how to delay an order in milliseconds

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #146494 quote
    Paul
    Participant
    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
    #146499 quote
    robertogozzi
    Moderator
    Master

    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.

    Paul and eckaw thanked this post
    #146500 quote
    robertogozzi
    Moderator
    Master

    Sorry, use CurrentSecond (OpenSecond does not exist), but there’s no guarantee there’s a bar each second.

    #146503 quote
    robertogozzi
    Moderator
    Master

    You can also tell the correct second unit with:

    MySecond = OpenTime - (round((OpenTime / 100) - 0.5) * 100)
    Paul and eckaw thanked this post
    #146505 quote
    Paul
    Participant
    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.

    #146608 quote
    Paul
    Participant
    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.

    GraHal and eckaw thanked this post
    Screenshot-2020-10-07-at-05.00.43.png Screenshot-2020-10-07-at-05.00.43.png test-delay-entry-dow-1s.itf
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

how to delay an order in milliseconds


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Paul @micky75d Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Paul
5 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/05/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...