Breakout system error backtest

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #90787 quote
    maximus78
    Participant
    Senior

    Hello guys, I was trying a strategy and I realized that probacktest does not make the entries correctly.

    I have simplified the strategy in order to understand where the setup errors are:

    Forex, 1 hour chart

    If the price of the 2nd candle (01:00) exceeds the highest of the first candle (00:00) of 1 pip, enter long.

    If the price of the 2nd candle exceeds the minimum of first candle  of 1 pip, enter short.

    It automatically exits at open of the next candle.

    The problem is that, when the 2nd candle exceeds both the previous high and low, probacktest enters both long and short, while I want it to enter only once, at the first break that occurs.

    The code perfectly executes entries in separate long and short systems and even intradaybarindex = 0 is correct.

    I attach the code, I cannot understand where I’m wrong … ..

    Thanks in advance to everyone for the help!

    defparam cumulateorders=false
     
    entrylong=highest[1](high)
    entryshort=lowest[1](low)
     
    if not onmarket and intradaybarindex=0 and entrylong then
    buy 1 shares at entrylong +(1*pointsize) stop
    endif
     
    if longonmarket then
    sell at market
    endif
     
    if not onmarket and intradaybarindex=0 and entryshort then
    sellshort 1 shares at entryshort-(1*pointsize) stop
    endif
     
    if shortonmarket then
    exitshort at market
    endif
    #90794 quote
    Vonasi
    Moderator
    Master

    You place two pending orders on the market and when one is hit the other is not cancelled until the candle closes –  so if price moves against you and hits the other order within the same candle then you have two trades and the second one closes the first one. It is not possible to cancel an order before a candle has closed. You will need to use MTF and work in a faster time frame. Keep putting the orders to market at each candle close until one is hit and then stop putting the opposite order to market as soon as you are on market at a candle close. This will though obviously massively reduce the available data that you can back test on.

    #90796 quote
    robertogozzi
    Moderator
    Master

    a)  you can simply write lines 3-4 as, since you want to just scan ONE bar (that is the current bar):

    entrylong=high
    entryshort=low

    if you also want to scan the previous bar you’ll have to use [2] within brackets:

    entrylong=highest[2](high)
    entryshort=lowest[2](low)

    while if you want to scan ONLY the previous bar you’ll have to write:

    entrylong=high[1]
    entryshort=low[1]

    b) you can remove and entrylong and and entryshort from lines 6 and 14, since they are always true (they cannot be 0).

    c) since in line 7 you want to BUY 1 pip higher than current HIGH, be warned that if CLOSE is too near and does not meet the broker’s distance requirements, the order could be rejected or entered at market. This is also the case for line 15.

    d) your orders will be placed when the first bar of the day (usually opening at 01:00 utc+1) closes and will be triggered if THAT high/low is broken, not that of the previous bar as I said above at point a)

    e) there is no way to avoid pending orders from being triggered once they are placed. So if it happens that the range of the setup bar is narrow and they are both triggered… well you’l have to either:

    • use at market orders, or
    • use the MTF (Multiple Time Frame) support and launch your strategy from a lower TF (say 1 minute, but still they could be both triggered in this unlikely case).

    EDIT:  I was writing while Vonasi was posting

    #90802 quote
    Vonasi
    Moderator
    Master

    I typed faster Roberto!

    I thought that I would ignore all the other little issues in the code as none of them stopped it working and even if they were not the most efficient way to code it they were not relevant to the main question. I thought that it might confuse things a little if I mentioned them so I didn’t – but you listed them all so I think we got it all totally covered between us!

    robertogozzi thanked this post
    #90859 quote
    maximus78
    Participant
    Senior

    Ah ok, I didn’t considered the fact of the orders cancelled only at closed candle, I thought that using “if not onmarket” and “if longonmarket” would erase the other order at once.

    Yes the only way in this cases may be using the MTF.

    Thanks so much Roberto and Vonasi!!

    Maxx

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Breakout system error backtest


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
maximus78 @maximus78 Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by maximus78
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/07/2019
Status: Active
Attachments: No files
Logo Logo
Loading...