Page 1 of 1

DateToNumeric and NumericToDate

Posted: 13 Feb 2016 10:39
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

Re: DateToNumeric and NumericToDate

Posted: 17 Feb 2016 20:25
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

Re: DateToNumeric and NumericToDate

Posted: 17 Feb 2016 21:03
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

Re: DateToNumeric and NumericToDate

Posted: 18 Feb 2016 14:18
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

Re: DateToNumeric and NumericToDate

Posted: 18 Feb 2016 16:50
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

Re: DateToNumeric and NumericToDate

Posted: 18 Feb 2016 17:22
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

Re: DateToNumeric and NumericToDate

Posted: 18 Feb 2016 19:43
by Ceres
Hi Timo,
Thank you very much it helps me to advance
Kind Regards
Ceres