Hi
I am having trouble coding with time. I have created a simple indicator to learn how to incorporate the ‘Time’ constant into my coding in order to trade between certain times only. I would like the indicator to return a 1 only between 9:00 and 17:00 everyday. I have gotten as far as to generate a “1” from 9:00 and reset it each day but I cant get it to return to ZERO after 17:00. The code is as follows:
If intradaybarindex = 0 then
tradeon = 0
endif
If time > 91000 then
tradeon = 1
elsif time > 170500 then
tradeon = 0
endif
Return tradeon
I have gone through the manuals and some of the code on this site but I am missing something as I cant get the indicator to return to Zero after 17:00. I’ve tried variation of this but cant get it right. I don’t think it was really necessary but I’ve included an image of my results. The chart is set to 5min candles.
Some help and insight as to why this is happening will be much appreciated
Thanks
Jens
Hi Jens!
IF TIME >= 090000 AND TIME < 170000 THEN
tradeon = 1
ELSE
tradeon = 0
ENDIF
Hope it helps you.
Regards.
It Works. Seems so obvious when you see it but I couldn’t think it.
Thank you!