Hello,
My system trades on a 4 hour chart so new candles (and new trades) are triggered at 00:00, 04:00, 08:00, 12:00, 16:00, 20:00
I am trying to add some code so that trading can only occur at 04:00, 08:00, 12:00 and 16:00 and not 00:00 and 20:00
Can anyone advise if this is possible and if so which programming function(s) should I use
Many thanks
As a follow up to this request I have ruled out using FLATBEFORE or FLATAFTER as I don’t want existing trades to be closed by these commands
I was going to suggest this code to test against before making a trade:
ValidTime = not ((time = 000000) or (time = 200000))
But to my surprise I can’t get it to work as still takes some positions at 20:00. Either a bug in the system or a bug in my thinking.
@Nicholas can you take a look please
Using a 4 hour chart on a forex pair using the code below it still takes some positions at 200000 (see attached screenshot) even though the TimeCount graph output is 0? Only does this for 200000 not any of the other times.
defparam CUMULATEORDERS = true
once TimeCount = 0
if not (time = 200000) then
Buy 1 contract at market
if time = 200000 then
TimeCount = TimeCount + 1
endif
endif
graph TimeCount
EricParticipant
Master
@TradeRanger
You can probaly do it different ways
you can try this
..and Time > 035900 and Time < 195900 Then buy..
Many thanks @ AutoStrategist and @Eric for your input. Like @AutoStrategist I got the same results with TIME 200000
I’ve now incorporated the code from @Eric into my system and backtested it on 12 currency pairs and it all appears to be working correctly
//Determine times when trading is allowed
ValidTime = (TIME > 035900) AND (TIME <195900)
once TradeTime = 1
IF ValidTime THEN
TradeTime = 1
ELSE
TradeTime = 0
ENDIF
Again thanks for your help