PaulParticipant
Master
Hi,
Is it really possible to delay an order in milliseconds? Because this could be useful when testing similar strategies which open a trade in the same direction simultaneously. Possible that one gets rejected. By adding a time delay, like 100-500 ms in one strategy, the order is still opened in the same bar.
Could someone please advise how to code that correctly if even possible? Thanks.
// test dow 2s 10k bars spread 2,3
defparam cumulateorders=false
defparam flatbefore=000000
defparam flatafter=220000
ind1=Average[70](close)
ind2=Average[40](totalprice)
condbuy=ind2 crosses under ind1 and high<high[1]
condsell=ind2 crosses over ind1 and low>low[1]
if condbuy then
buy 1 contract at market
endif
if condsell then
sellshort 1 contract at market
endif
set stop %loss .1
set target %profit .1
No, you can’t. There’s no provisions for planned delays.
You could only delay minimun 1 second, using MTF support and 1-second TF. You could delay each strategy with a defined different second unit (not tested):
TIMEFRAME(1 hour,UodateOnClose)
MyCondition = close CROSSES OVER Average[200,0](close)
TIMEFRAME(Default)
IF OpenSecond = 0 AND MyCondition THEN //Enter when second is 0
BUY AT MARKET
ENDIF
TIMEFRAME(1 hour,UodateOnClose)
MyCondition = close CROSSES OVER Average[200,0](close)
TIMEFRAME(Default)
IF OpenSecond = 1 AND MyCondition THEN //Enter when second is 1
BUY AT MARKET
ENDIF
your next similar strategy on the same instrument could use second 2.
If 1 second difference is too high, then you have to give up. If it’s too little you can set the delay to a multiple of 1.
Sorry, use CurrentSecond (OpenSecond does not exist), but there’s no guarantee there’s a bar each second.
You can also tell the correct second unit with:
MySecond = OpenTime - (round((OpenTime / 100) - 0.5) * 100)
PaulParticipant
Master
Thanks robertogozzi. Yeah when there’s no bar the next second is another problem of it’s own. I will give your code a try.
PaulParticipant
Master
So the goal was to have identical strategies running the same index in the same direction more correctly for the entry.
“ve tested it for a day and it seemed in general to work fine.
Strategy running on 1 sec, with mtf using 2s. When a signal comes, entry is on the first sec and in another strategy entry is on the second sec.
Also tested the difference with and without updateonclose.
If there’s no bar on the one second timeframe hopefully the order will be repeated at first or later rejected. Not completely sure about that.
Another way to avoid conflict is using 1€, 2$ and 10$ charts I guess, still this was an interesting experiment.
Here’s the test file for anyone interested.