Mother of Dragons trading strategy…

Viewing 15 posts - 1 through 15 (of 523 total)
  • Author
    Posts
  • #117373 quote
    nonetheless
    Participant
    Master

    Well, I had to call it something, right?

    Attached is the first code I’ve put together that ‘seems to work’. Survives all manner of WF tests: 70-30, 50-50, 30-70 – however you want to chop it.

    Also does well in Vonasi’s robustness tester, Random 10-10. I tried hitting it with a very big hammer but still performs well.

    Uses a combination of HullMA and Supertrend on the 2h TF to define the primary trend, then another HullMA + trailing stop on a 5m TF to control entry and exit.

    The 5m TF doesn’t give us much in the backtest but it does well in clear uptrends and downtrends. Just that choppy bit in March 2019 where it couldn’t cope. I hate to see whole month where a strategy doesn’t come good, but one out of 16 is not too shabby.

    It runs around the clock so I’ve allowed for a spread of 3.3, calculated for IG as: (6.5 x 2.4 + 6.5 x 1.6 + 2 x 9.8 + 9 x 3.8)/24

    All backtesting was done with MM disabled but I ran the final optimization with it turned on just to demonstrate the boost it gives. Starts with position size = 1 and by the end of the run when equity has trebled, it’s placing position size of ~3.4, so more or less in keeping with standard practise. Also reduces position size in bad patches.

    Credit where credit is due: Vonasi wrote the Money Management part and coded the HullMA for me. The trailing stop I believe is Nicolas’ work – big thanks to both!

    But the really cool thing about this strategy is that the equity graph draws a perfect profile of Daenerys Targaryen! You might have to squint a bit, but if you can’t see Daenerys then you haven’t optimized correctly.

    All comments, suggestions, mods etc welcome!

    // DJI 5m
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM preloadbars = 5000
    Capital = 10000
    MinSize = 1                 //The minimum position size allowed for the instrument.
    MM1stType = 0               //Starting type of moneymanagement. Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.
    MM2ndType = 1               //Type of money management to switch to after TradesQtyForSwitch number of trades and ProfitNeededForSwitch profit has occurred
    TradesQtyForSwitch = 15    //Quantity of trades required before switching to second money management choice.
    ProfitNeededForSwitch = 2  //% profit needed before allowing a money management type change to MM2ndType.
    DrawdownNeededToSwitch = 8 //% draw down from max equity needed before money management type is changed back to MM1stType.
    DrawdownNeededToQuit = 25   //% draw down from max equity needed to stop strategy
     
    Once MoneyManagement = MM1stType
     
    Equity = Capital + StrategyProfit
    maxequity = max(equity,maxequity)
     
    if equity < maxequity * (1 - (DrawdownNeededToSwitch/100)) then
    enoughtrades = 0
    tradecount = 0
    moneymanagement = MM1stType
    endif
     
    if equity < maxequity * (1 - (DrawdownNeededToQuit/100)) then
    quit
    endif
     
    if not EnoughTrades then
    if abs(countofposition) > abs(countofposition[1]) then
    tradecount = tradecount + 1
    endif
    if tradecount > TradesQtyForSwitch and maxequity >= Capital * (1 + (ProfitNeededForSwitch/100)) then
    EnoughTrades = 1
    MoneyManagement = MM2ndType
    endif
    endif
     
    IF MoneyManagement = 1 THEN
    PositionSize = Max(MinSize, Equity * (MinSize/Capital))
    ENDIF
     
    IF MoneyManagement = 2 THEN
    PositionSize = Max(LastSize, Equity * (MinSize/Capital))
    LastSize = PositionSize
    ENDIF
     
    IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
    PositionSize = MinSize
    ENDIF
     
    PositionSize = Round(PositionSize*100)
    PositionSize = PositionSize/100
     
     
    // Size of POSITIONS
    PositionSizeLong = 1 * positionsize
    PositionSizeShort = 1 * positionsize
    
    TIMEFRAME(120 minutes)
    Period= 520
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
    HULLa = weightedaverage[round(sqrt(Period))](inner)
     
    c1 = HULLa > HULLa[1]
    c2 = HULLa < HULLa[1]
    
    indicator1 = SuperTrend[5,21]
    c3 = (close > indicator1)
    c4 = (close < indicator1)
    
    TIMEFRAME(5 minutes)
    Periodb= 60
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
     
    c5 = HULLb > HULLb[1]
    c6 = HULLb < HULLb[1]
    
    // Conditions to enter long positions
    IF c1 AND C3 AND C5 THEN
    BUY PositionSizeLong CONTRACT AT MARKET
    SET STOP %LOSS 2.1
    SET TARGET %PROFIT 1
    ENDIF
     
     
    // Conditions to enter short positions
     
    IF c2 AND C4 AND C6 THEN
    SELLSHORT PositionSizeShort CONTRACT AT MARKET
    SET STOP %LOSS 1.2
    SET TARGET %PROFIT 1
    ENDIF
     
    
    
    //trailing stop function
    trailingstart = 84 //trailing will start @trailinstart points profit
    trailingstep = 3 //trailing step to move the "stoploss"
     
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
     
    
    Nicolas, Francesco, Gubben and 10 others thanked this post
    DJ-5m-Mother.of_.Dragons-30-70-WF.jpg DJ-5m-Mother.of_.Dragons-30-70-WF.jpg DJ-5m-Mother.of_.Dragons-50-50-WF.jpg DJ-5m-Mother.of_.Dragons-50-50-WF.jpg DJ-5m-Mother.of_.Dragons-70-30-WF.jpg DJ-5m-Mother.of_.Dragons-70-30-WF.jpg DJ-5m-Mother.of_.Dragons.itf DJ-5m-Mother.of_.Dragons-VRT-10-10.jpg DJ-5m-Mother.of_.Dragons-VRT-10-10.jpg
    #117379 quote
    nonetheless
    Participant
    Master

    One more attachment, opt with MM

    MAKSIDE thanked this post
    DJ-5m-Mother.of_.Dragons-opt-with-MM.jpg DJ-5m-Mother.of_.Dragons-opt-with-MM.jpg
    #117382 quote
    Francesco
    Participant
    Veteran

    Looks amazing! I will try on 200k later today and post the results

    #117408 quote
    GraHal
    Participant
    Master

    You are coming out with good work @nonetheless!

    Even ‘compiling’ others snippets needs a flair (and you deffo have it! ) but also effort and enthusiasm and time in front of the screen.  Even more so with the WF and robustness testing you are doing.

    Many Thanks for Sharing!

    robertogozzi thanked this post
    #117412 quote
    nonetheless
    Participant
    Master

    I’ve had so much help on this forum, it’s good to be able to give something back!

    #117415 quote
    Vonasi
    Moderator
    Master

    The robustness test results look good. Just need to check if you added the TRADEON condition correctly as it is a strategy that can reverse position direction.

    It should be added like this:

    // Conditions to enter long positions
    IF (shortonmarket or (not onmarket and tradeon)) and c1 AND C3 AND C5 THEN
    BUY PositionSizeLong CONTRACT AT MARKET
    SET STOP %LOSS 2.1
    SET TARGET %PROFIT 1
    ENDIF
     
     
    // Conditions to enter short positions
    IF (longonmarket or (not onmarket and tradeon)) and c2 AND C4 AND C6 THEN
    SELLSHORT PositionSizeShort CONTRACT AT MARKET
    SET STOP %LOSS 1.2
    SET TARGET %PROFIT 1
    ENDIF
    nonetheless thanked this post
    #117417 quote
    nonetheless
    Participant
    Master

    I redid it with those TRADEON conditions and it’s not much changed, but possibly better!

    GraHal thanked this post
    DJ-5m-Mother.of_.Dragons-VRT-10-10-1.jpg DJ-5m-Mother.of_.Dragons-VRT-10-10-1.jpg
    #117467 quote
    Vonasi
    Moderator
    Master

    We have to be careful when analysing the results of robustness tests of strategies that reverse position as the robustness test is some what diluted. In an extreme example of dilution a strategy could open a trade on the first bar and then reverse position repeatedly until the last bar in a data sample. This robustness test would only tell us how good an idea it was to open a trade on the first bar! All of our robustness tests will in reality be something between that very diluted test and the ideal robustness test that completely randomly opens and closes trades and never reverses positions.

    What I’m basically trying to say is that a robustness test on a strategy that reverses positions will never be as robust a test as a robustness test on a strategy that does not reverse positions and so we can’t say the results are better because we are not comparing eggs with eggs!

    nonetheless thanked this post
    #117476 quote
    nonetheless
    Participant
    Master

    Yeah, that makes sense. I’ll put it on forward testing for a couple of months and see how it goes.

    So far though, looks like it could be worth a punt…

    #117578 quote
    Francesco
    Participant
    Veteran

    No positions opened after 2018 in 200k. Why?

    provaaa.png provaaa.png
    #117581 quote
    nonetheless
    Participant
    Master

    Because the MM is set to quit the whole thing after 25% drawdown … which is bad bad bad!

    Try it with

    MM1stType = 0               
    MM2ndType = 0
    (disables the MM)
    And/or raise DrawdownNeededToQuit = 25  to 50 just so it will complete the run.
    Francesco thanked this post
    #117583 quote
    Francesco
    Participant
    Veteran
    #117593 quote
    Vonasi
    Moderator
    Master

    Thanks for the OOS 200k test Francesco. The strategy doesn’t completely fail but it is not a total success by a long way. That OOS equity curve would be one that most people would soon give up trading.

    There are quite a few variables in the strategy that are most likely curve fitted especially when they are given values like 84 and 2.1. I see eight variables and that is quite a lot in my mind:

    • period
    • periodb
    • A long take profit %
    • A short take profit %
    • A long stop loss %
    • A short stop loss %
    • Trailingstart
    • TrailingStep

     

    I would start by removing the trailing stop as personally I think these are very easy to curve fit and rarely bring any performance benefit. Then I would plot charts of each other variable for a range of values to see how important their actual value is and whether it is majorly fitted or standing on a cliff edge. Sometimes it is a combination of optimised variables which is where 3D charts come in useful. Roll on being able to use v11 more easily!

    I would also consider removing the short part of the strategy as the DJI is a long only index in my mind and this removes two variables straight away from the curve fit.

    nonetheless thanked this post
    #117596 quote
    nonetheless
    Participant
    Master

    @Francesco, thanks for the backtest, even if it’s not what I had hoped for!


    @Vonasi
    , I must reluctantly agree with your analysis, it does look curve fit to the 100k period i was testing on. I’ll play around with some of your suggestions and see if it can’t be salvaged…

    #117615 quote
    Francesco
    Participant
    Veteran

    No problem! I’m ready to test on 200k when u will do some optimizations 🙂

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

Mother of Dragons trading strategy…


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 522 replies,
has 50 voices, and was last updated by LaurentBZH35
4 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/21/2020
Status: Active
Attachments: 195 files
Logo Logo
Loading...