I am trying to solve a coding problem it seems easy but I get it wrong in the backtest.
I want to take as reference everyday’s price at 090000h. Let’s call it levelZERO. I would write:
1
2
3
IFtime=090000THEN
levelZERO=close
ENDIF
So, that day, if I want to refer to the price at 09:00h I would mention levelZERO in the code. It seems that it has to be reset everyday, seems the lecture I got in the backtest does not make any sense. Everyday levelZERO should be different, but it seems that it refers to a price from a different day.
I have tried:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
IFdayofweek=1ANDtime=090000THEN
levelZERO=close
ENDIF
IFdayofweek=2ANDtime=090000THEN
levelZERO=close
ENDIF
IFdayofweek=3ANDtime=090000THEN
levelZERO=close
ENDIF
IFdayofweek=4ANDtime=090000THEN
levelZERO=close
ENDIF
IFdayofweek=5ANDtime=090000THEN
levelZERO=close
ENDIF
It does not show a lot of imagination but it is simple.
I believe it still doesn’t work, since I don’t get the lecture I want in the backtest.
I would appreciate if anyone can confirm with me if the above is right, or any other (and more simple way) to “lock” the price at 09:00 everyday.
Your first code example should work. Anytime you think your code is wrong or something dis-functioning, try to debug it with GRAPH or build a simple indicator from it and apply it on your chart.
090000 is a time that must be read by the code, if you launch the code on daily basis, then it is possible that it will not be updated, since the code is read one time at Close and at that moment, time could not be 09h00m00s.
Thanks. That is what I did. I built a simple indicator representing levelZRO and it works. I am discovering GRAPH applications to debug/confirm and to graphically see the results of same lines of codes.