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:
1
2
3
4
5
6
7
8
9
10
11
Ifintradaybarindex=0then
tradeon=0
endif
Iftime>91000then
tradeon=1
elsiftime>170500then
tradeon=0
endif
Returntradeon
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
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue