stop order unreliable in backtest

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #137551 quote
    Paul
    Participant
    Master

    Hello, 

    An issue with a backtest running on the dow with a stop order.

    i’ve coded to close a long position on stop at the supportprice.

    the position is then is the red and closing it should cut potential losses.

    Now, in the backtest, the index never traded at the supportprice, yet still the position in closed exactly at the line. In de demo, the position is not closed, which is correct and ended up winning.

    The difference between the low & supportline is 2 points.

    (positionsize=0.5)

    if spread=3.8 or lower, the position stays open and wins in the backtest +22,60

    if spread=3.9 or higher, the position is closed with losses in the backtest  -17,50

    (demo +22,64)

    It bugs me that it’s depended on spread if it’s closed or not which shouldn’t be an issue at all because the line was never touched. 

    So the question, why was it closed?  Because it means a stoporder doesn’t work exactly as intended in a backtest!

     

    code used;

    // support & resistence
    if supportresistance then
    pivotbar     =  60
    lookback     =  120
    barlookback  = pivotbar + 1
    if low[pivotbar] < lowest[lookback](low)[barlookback] then
    if low[pivotbar] = lowest[barlookback](low) then
    supportprice  = low[pivotbar]
    endif
    endif
    if high[pivotbar] > highest[lookback](high)[barlookback] then
    if high[pivotbar]  = highest[barlookback](high) then
    resistanceprice = high[pivotbar]
    endif
    endif
    if longonmarket then
    sell at supportprice  stop
    endif
    if shortonmarket then
    exitshort at resistanceprice stop
    endif
    endif
    Screenshot-2020-06-29-at-17.22.49.jpg Screenshot-2020-06-29-at-17.22.49.jpg Screenshot-2020-06-29-at-17.23.11.jpg Screenshot-2020-06-29-at-17.23.11.jpg Screenshot-2020-06-29-at-20.11.35.jpg Screenshot-2020-06-29-at-20.11.35.jpg
    #137560 quote
    GraHal
    Participant
    Master

    Have you taken account that for example the Low shown on the candlestick is mid price?

    So with spread = 4 the SellShort / Stop Loss (for a Long) would be 2 points below the Low seen on a candlestick?

    Paul thanked this post
    #137568 quote
    Paul
    Participant
    Master

    I didn’t realise. If spread is high, the difference could be even bigger. On a fast timeframe it’s a problem with many trades, stability and testing. Guess the best solution is to use crossover/crossunder & exit at market, which come at a cost too.

    Maybe then use MTF, like something I did with barhunter. In this case backtesting on 5s, putting it live on 1s.

    Thanks GraHal, there are a few options! and it’s never easy 🙂

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

stop order unreliable in backtest


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Paul @micky75d Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/29/2020
Status: Active
Attachments: 3 files
Logo Logo
Loading...