Wanted help to backtesting indicator type Larry Williams

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #130733 quote
    Zigo
    Participant
    Master

    I manually tested a version of the Larry Williams approach, the results where not outstanding but nevertheless I can see possibilities. The principle : entering the market, depending on the previous candle. Normally it is usted on a dayly timeframe and on forex pairs, but I have transformed it to every timeframe and every instrument. Manually it works.

    In reality I tested the indicator yesterday on a 45 min graph. The parameters didn’t seemed optimal and trerefore I tried to programme a backtest scenario but, it failed.

    Here is the indicator:

    Defparam drawonlastbaronly = true
    f=0.2
    KH= high[1]
    KL=low[1]
    
    up=KH* f/100
    Dn=KL*f/100
    
    P=open
    
    U= P + up
    L= P - dn
    //Tekenen
    DRAWSEGMENT(barindex, u, barindex[3], u)coloured(5,155,5,255)
    DRAWSEGMENT(barindex, L, barindex[3], L)coloured(175,75,75,255)
    DRAWTEXT("                                                         Go Long above =#U#", barindex, U, dialog, bold, 20)coloured(5,155,5,255)
    DRAWTEXT("                                                           Go Short under  =#L#", barindex, L, dialog, bold, 20)coloured(175,75,75,255)
    TP=u+(0.89*(u-l))
    St=l-(0.89*(u-l))
    DRAWSEGMENT(barindex, TP, barindex[3], TP)
    DRAWSEGMENT(barindex, St, barindex[3], St)
    DRAWTEXT("                                                          TP Long / Stop Short=#TP#",barindex,TP, dialog,standard, 20)coloured(255,255,255,255)
    DRAWTEXT("                                                          TP Short / Stop Long=#St#", barindex, St, dialog,standard, 20)coloured(255,255,255,255)
    
    return u,l
    #130734 quote
    Zigo
    Participant
    Master

    Thats what you get from, the indicator above

    DAX-45-minuten.png DAX-45-minuten.png
    #130737 quote
    Zigo
    Participant
    Master

    I show the backtest who works but give Always 0 trades.

     

    Defparam cumulateorders=false
    
    f=0.2
    
    KH=high[1]
    KL=low[1]
    
    up=KH*f/100
    Dn=KL*f/100
    p=open
    U=P+up
    L=P-dn
    
    //Go Long
    
    if high > U then
    buy 1 contract at market
    endif
    
    targetpriceLong= u+1.618*(u-l)
    stoppriceLong = L-(u-l)
    
    if longonmarket then
    if targetpriceLong then
    sell at market
    endif
    else
    if stoppriceLong then
    sell at market
    endif
    endif
    if close then
    sell at market
    endif
    
    //Go Short
    
    if low < L then
    sellshort at market
    endif
    targetpriceshort= L-1.618*(u-l)
    stoppriceshort = u+(u-l)
    if shortonmarket then
    if targetpriceshort then
    exitshort at market
    endif
    else
    if stoppriceshort then
    exitshort at market
    endif
    endif
    if close then
    exitshort at market
    endif
    #130748 quote
    Zigo
    Participant
    Master

    Spreadsheet manually on a 45min graph.

    DAX-45-minuten-1.png DAX-45-minuten-1.png L.W.-Manually.png L.W.-Manually.png
    #130751 quote
    Zigo
    Participant
    Master

    As you can see, the results are not so good. But what I trying for, is if I have a trade (long or short) then the target as well as the stoploss is clear but I’m not shure about the timestop. The meaning is to consider every candle whether there is a trade or not.  And start each candle again to obtain maybe an automatic system.

    #130752 quote
    GraHal
    Participant
    Master

    but give Always 0 trades

    You sure it’s 0 trades and not 0 bar trades??

    Surely with conditions below the trade is going to close as soon as it opens??

    I’ll run it on my Platform early evening, but I must get out in the garden! 🙂

    if close then
    sell at market
    endif
    
    if close then
    exitshort at market
    endif
    #130754 quote
    Zigo
    Participant
    Master
    #130761 quote
    Vonasi
    Moderator
    Master

    Topic moved to ProOrder forum as this is a discussion about a strategy.

    #130765 quote
    Vonasi
    Moderator
    Master

    Apart from the mistakes that GraHal pointed out you also can’t use your calculated levels as conditions on their own. You have to compare them to something such as close > targetpricelong bt this would sell at the close of a candle. I’m guessing that you want to close when the level is hit so you need to use pending orders.

    I have modified your code to use pending orders but really the code needs a few more fixes such as only buying if you are between your exit levels and making sure you have exit orders on the market when you place the entry orders etc.

    Defparam cumulateorders=false
    
    f=0.2
    
    KH=high[1]
    KL=low[1]
    
    up=KH*f/100
    Dn=KL*f/100
    p=open
    U=P+up
    L=P-dn
    
    //Go Long
    
    if high > U then
    buy 1 contract at market
    endif
    
    targetpriceLong= u+1.618*(u-l)
    stoppriceLong = L-(u-l)
    
    if longonmarket then
    //if targetpriceLong then
    sell at targetpricelong limit
    //endif
    //else
    //if stoppriceLong then
    sell at stoppriceLong stop
    //endif
    endif
    //if close then
    //sell at market
    //endif
    
    //Go Short
    
    if low < L then
    sellshort at market
    endif
    targetpriceshort= L-1.618*(u-l)
    stoppriceshort = u+(u-l)
    if shortonmarket then
    //if targetpriceshort then
    exitshort at targetpriceshort limit
    //endif
    //else
    //if stoppriceshort then
    exitshort at stoppriceshort stop
    endif
    //endif
    //if close then
    //exitshort at market
    //endif
    
    graphonprice targetpriceshort
    graphonprice stoppriceshort
    graphonprice targetpricelong
    graphonprice stoppricelong
    graphonprice u
    graphonprice l
    
    #130770 quote
    Zigo
    Participant
    Master

    Thanks,

    At stoppriceshort is not what I want.

    Because if the price  is higher then stoppriceshort I lose the difference between price and stoppriceshort, thats not what I want. (It can still be a winning trade if price is between enterprice and TP)

    If neither TP and Stopprice (long or short) is not reached before the end of the intradaybarindex.  The trade has to stop  (at close?)  of that intradaybarindex.

    #130792 quote
    Vonasi
    Moderator
    Master

    We can only guess what you want. You need to set out exactly what strategy you have in mind down to every detail if you want someone else to code it or help you fix it. For example we have no idea if you want to sell at the calculated levels or any time price closes outside of them. We also don’t know if you want the levels fixed at the time of entry or changing with every new bar after entry.

    Much more clear definitive info is needed!

    #130807 quote
    Zigo
    Participant
    Master

    The indicator show the conditions  to go long or short at the open of each candle. I will illustrate this with two graphics a 15 min and a 90 min. The second last candle is only used to calculate conditions for the last candle and the result is immediately printed at the opening of the last candle. The high and the low of the second last candle (High[1] and low[1]) are used to calculate those values. Fact: there is Always a last and  a second last candle which timeframe you ever take.

    The factor (f) is in both cases (both graphics) 0.2 or 20% of the range (U-L) of the second last candle.

    At the moment price touches the Green or Red line we are in the market long or short depending. If one change line 20 and 40 in the backtest we change the targetPrice, the same for the stoplossprice line 40 and 41. Beside variable f as % of the range, we can take for example f2 (instead of 1.618) as factor for TP and f3( instead of 1) for Stoploss as variables as well.

    TP and Stoploss are well defined. If  TP or stoploss are not reached, there will be a third exit and that will be the close of the last candle. In fact I am searching for a timestop at the candle in action (maybe the last second of that candle). Because the first second of the next candle there are new conditions. As conclusion in the 15 min graph we have no entry no trade, in the 90 min graph there is a gain of 38.8€.
    DAX-15-minuten.png DAX-15-minuten.png DAX-90-minuten.png DAX-90-minuten.png
    #130810 quote
    Vonasi
    Moderator
    Master
    Much more clear definitive info is needed!
    …and yet somehow I am more confused than I was before! 🙂
    #130894 quote
    Zigo
    Participant
    Master
    ?
    #131016 quote
    Zigo
    Participant
    Master
    Thank you all for motivating me.
    Backtest-dow.png Backtest-dow.png
Viewing 15 posts - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.

Wanted help to backtesting indicator type Larry Williams


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Zigo @zigo Participant
Summary

This topic contains 17 replies,
has 3 voices, and was last updated by Zigo
5 years, 9 months ago.

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