multi timeframe indicator time of high and time of low  [SOLVED]

Questions about MultiCharts and user contributed studies.
FB2013
Posts: 20
Joined: 12 Mar 2013
Has thanked: 3 times
Been thanked: 5 times

multi timeframe indicator time of high and time of low

Postby FB2013 » 24 Dec 2013

Hello,

I am trying to implement an indicator determining the time of the high and low of the day.
The values should be displayed on the daily chart.
Therefore i wrote the following indicator logic.

Code: Select all


Vars:
tHigh(0),tlow(0),counter(0),lnow(0),hnow(0);

if Time data2 = sessionendtime(0,1) data2 then
begin
counter=0;
hnow =high data2;
lnow =low data2;
while counter < 150 begin
if hnow < high[counter] data2 then begin
hnow = high[counter] data2;
tHigh=Time[counter] data2;
end;
if lnow > low[counter] data2 then begin
lnow = low[counter] data2;
tlow= Time[counter] data2;
end;
counter=counter +1;
end;
end;

plot1(tlow);
This indicator should be used on a chart containing the visible daily data as data1 and as data2 hidden 1 minute data should be used. Right now it seems that I can only reference 150 minutes back within that indicator on data2.

Right now it seems I am lost completly.
Hope one of the forum members can help me out of that.

Best Regards

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: multi timeframe indicator time of high and time of low  [SOLVED]

Postby Henry MultiСharts » 26 Dec 2013

Hello FB2013,

Please try this code:

Code: Select all

Vars:
intrabarpersist cs(-1),
intrabarpersist tH(0),
intrabarpersist tL(0),
intrabarpersist _l(0),
intrabarpersist _h(0);

if cs <> CurrentSession(0)data2 then begin
_h = h data2;
_l = l data2;
tH = t data2;
tL = t data2;
end;
cs = CurrentSession(0) data2;

if _h < h data2 then begin
_h = h data2;
tH = t data2;
end;

if _l > l data2 then begin
_l = l data2;
tL = t data2;
end;

if currentbar > 1 then
begin
plot1(tH);
plot2(tL);
end;
In order to make this code work you need to ensure there are no session breaks in the instrument sessions (MultiCharts->File->New->QuoteManager window->double click on the symbol you need->Sessions tab).
Please note - the value cannot be calculated for the first daily bar of the chart.

FB2013
Posts: 20
Joined: 12 Mar 2013
Has thanked: 3 times
Been thanked: 5 times

Re: multi timeframe indicator time of high and time of low

Postby FB2013 » 26 Dec 2013

Hello Henry,

thank you very much for your fast answer, I have solved it in a similar way.
However, I think your approach is much cleaner than mine.
Just for sake of completness I post my actual working implementation, to give a different solution
for the same task.

Code: Select all

Inputs:
sessionStart(931),sessionEnd(1600);
Vars:
tlow(0,data1),thigh(0,data1),
tlow2(0,data2),thigh2(0,data2),
hnow(0,data2),lnow(0,data2);

if Time of data2 = sessionStart then
begin

hnow = high of data2;
lnow = low of data2;
tlow2 = Time of data2;
thigh2 = Time of data2;
end
else
begin
print(lnow);
if high of data2 > hnow[1] then
begin
hnow = high of data2;
thigh2 = Time of data2;
end
else
begin
hnow = hnow[1];
thigh2= thigh2[0];
end;
if low of data2 < lnow[1] then
begin
lnow = low of data2;
tlow2 = Time of data2;
end
else
begin
lnow = lnow[1];
tlow2 = tlow2[1];
end;
end;

if time of data2 = sessionendtime(0,1) then
begin
tlow = tlow2;
thigh = thigh2;
end;

plot1(thigh);
plot2(tlow);
Anyway I would like to thank the support of Multicharts for the great work they performed in this year. I hope you all had a nice chrsimas eve and wish you all a happy new year.


Return to “MultiCharts”