DateToNumeric and NumericToDate

Post Reply
Ceres
Posts: 73
Joined: 31 Mar 2014 09:53

DateToNumeric and NumericToDate

Post by Ceres »

Hello WHS team

How turn the value "OneYearAgo" to a "Float Value" please ? thank you in advance


Vars

series OneYearAgo ;

calculation

OneYearAgo = dateToNumeric(dateopen) - 10000;
if date = NumericTodate(OneYearAgo) then begin Highlightrgb("slot",0,0,128); end

interpretation

begin
end

Plot (OneYearAgo, black, 2);


Best regards

Ceres
Last edited by Ceres on 16 Feb 2016 21:55, edited 1 time in total.
User avatar
WHS Support
Posts: 2443
Joined: 14 Feb 2013 10:27

Re: DateToNumeric and NumericToDate

Post by WHS Support »

Hi Ceres,

can you please specify what you are trying to achieve? For me the term "float value" defines only a variable that can have decimals (other than integer).

Kind regards,
Timo
WH SELFINVEST
Ceres
Posts: 73
Joined: 31 Mar 2014 09:53

Re: DateToNumeric and NumericToDate

Post by Ceres »

Hi Timo ,

I try to establish the date of a year ago, to establish a candle counter until that date, the number of candles is different from one market to another

departing I was using this code

Vars
series YY,zero;
input $period(1,270,264);
Calculation

YY=(((close-close[$period])/close[$period])*100);

interpretation
begin
end

plotcandles(zero,YY,YY,zero);



I try to count the candles on year and to incorporate a day counter, to establish performance over one year


Express YeartoYear


Vars


series YY , OneYearAGo , counter , zero ;
numeric candle ;


calculation

CalculateAtEveryTick(false);

OneYearAgo = dateToNumeric(dateopen) - 10000;

if (date >= NumericTodate(OneYearAgo)) and (date [1] < NumericTodate(OneYearAgo)) then
begin
Counter = 1 ;
end
else
counter = counter + 1 ;
candle = counter ;
YY=(((close-close[candle])/close[candle])*100);

interpretation
begin
end

plotcandles(zero,YY,YY,zero);



regards

Ceres
User avatar
WHS Support
Posts: 2443
Joined: 14 Feb 2013 10:27

Re: DateToNumeric and NumericToDate

Post by WHS Support »

Hi Ceres,

so in essence you want to determine the number of bars starting from today (current day) down to "one year ago" February 18th, 2015?

Kind regards,
Timo
WH SELFINVEST
Ceres
Posts: 73
Joined: 31 Mar 2014 09:53

Re: DateToNumeric and NumericToDate

Post by Ceres »

Hi Timo,
yes affirmatively
i would like to count the number of candles since 2/18/2016 (Today) untill 2/18/2015 .
But I can not get the expected result, I know how use the counter with sub units of time ( with "time") but not with a date
Kind Regards

Ceres
User avatar
WHS Support
Posts: 2443
Joined: 14 Feb 2013 10:27

Re: DateToNumeric and NumericToDate

Post by WHS Support »

Hi Ceres,

okay, understand.

Try this code:

Code: Select all

Express YeartoYear

Vars

numeric oneyearago, CBI, numberofcandles, i;
series xdate;

calculation
CalculateAtEveryTick(false);
OneYearAgo = (DateToNumeric(dateopen) - 10000);
xdate = DateToNumeric(dateOpen);
cbi = CurrentBarIndex();

if IsFinalBar() then
begin
  for i = 0 to FinalBarIndex() 
  begin
    if(xdate[i] >= oneyearago) and (xdate[i+1] < oneyearago) then 
    begin
      Highlightat(i,"slot","green");
      numberofcandles = (FinalBarIndex() - (CBI - i));
      Highlight("textAbove: Number of bars:" +NumericToString(numberofcandles, "%6.0f"), "black");
    end
  end
end

interpretation
begin
end
Hope this helps.

Kind regards,
Timo
WH SELFINVEST
Ceres
Posts: 73
Joined: 31 Mar 2014 09:53

Re: DateToNumeric and NumericToDate

Post by Ceres »

Hi Timo,
Thank you very much it helps me to advance
Kind Regards
Ceres
Post Reply

Return to “WHS NANOTRADER - EXPRESS PROGRAMMING”