Hi,
I’m have some trouble trying to code no entry between say Saturday 12PM and Monday 11AM.
At the start of my strategy code.
Can any assist?
Thanks
Here you can find the coding example to use (lines 7 and 10, then 25 and 30) https://www.prorealcode.com/topic/d-i-rsioma-trend-following-on-dax/.
Above added as row 51 to Snippet Library Snippet Link Library
Hi, its not quite what I’m after. I’m running a 24 hour FX strategy, but what I’m finding is it takes trades as soon as the market opens on Monday morning when the spreads are very large and there is a gap. So I Just want it to only take trades from 11AM monday all the way to Friday when the FX markets close.
So what I need is a time range which overlaps into days rather than a time interval per day. Like for example, if the time is between Monday after 11AM to Saturday 11AM then enter the trade.
You could just set a flag on or off.
if opentime = 110000 and opendayofweek = 1 then
tradeflag = 1
endif
if opentime = 110000 and opendayofweek = 6 then
tradeflag = 0
endif
if tradeflag and (your entry conditions) then
buy 1 contract at market
endif
Just so I understand exactly what that does –
Does the first part require the system to be on and when it clicks to 11AM on Monday the timeflag = 1
What happens if the system gets shut off mid week and I turn it back on, and hence the time has already passed Monday 11AM will the timeflag still be 1?
And the same goes for Saturday, what if my expiry is on Friday and I only start the system on Sunday, because the time never passed 11am Saturday when the system is onn, is it possible for the timeflag to be 1 on Monday before 11AM given the condition of opentime on the Saturday was never meet?
Thank you
Above also saved to Snippet Library as row 52
Your strategy will do nothing until the trigger time is hit. I think this will allow you to start your strategy at any time and start trading immediately. Not tested – I suggest graphing tradeflag to check it does what you want it to do.
if (opendayofweek = 6 and opentime < 110000) or (opendayofweek = 1 and opentime >= 110000) or (opendayofweek >= 2 and opendayofweek <= 5) then
tradeflag = 1
else
tradeflag = 0
endif
if tradeflag and (your entry conditions) then
buy 1 contract at market
endif
I think that code marks sense now.
Thankyou!
You don’t really need the if then else so a shorter version would be:
timeok = (opendayofweek = 6 and opentime < 110000) or (opendayofweek = 1 and opentime >= 110000) or (opendayofweek >= 2 and opendayofweek <= 5) then
if timeok and (your entry conditions) then
buy 1 contract at market
endif