Strategy Eur/Usd mini, how to reduce the maximum % drawdown?

Viewing 15 posts - 16 through 30 (of 55 total)
  • Author
    Posts
  • #87409 quote
    robertogozzi
    Moderator
    Master

    I made an MTF version out of latest Vonasi’s version, by:

    • replacing empty line 5 with timeframe(Daily,UpdateOnClose)
    • replacing empty line 48 with timeframe(default)
    • appending Nicolas’ Trailing Stoip code
    • launching it form a 2-minute TF
    //Eur/Usd mini - 1D Capital Eur 500,00
    
    DEFPARAM CUMULATEORDERS = false
    DEFPARAM PRELOADBARS = 10000
    timeframe(Daily,UpdateOnClose) //Daily
    a = 2 //2
    t = 2 //2
    m = 1.8 //1.8
    
    n=1
    Atr = AverageTrueRange[14](close) //14
    Atrs = 0.1 //0.1
    x = average[A,3]((High+Low+close)/3) //3
    
    b1e = ((t*x)-high)+(ATR*ATRs)
    s1e = ((t*x)-Low)-(ATR*ATRs)
    Hbop = (t*x)-(t*Low)+High
    Lbop = (t*x)-(t*High)+Low
    
    // Condizioni per entrare su posizioni long
    IF NOT LongOnMarket AND close <= lbop THEN
    BUY n CONTRACTS AT market//b1e limit
    //SELL AT s1e limit
    ENDIF
    
    // Condizioni per uscire da posizioni long
    If LongOnMarket and close > s1e THEN
    SELL AT market//s1e limit
    if close > positionprice then//positionprice then
    sell at market
    endif
    ENDIF
    
    // Condizioni per entrare su posizioni short
    IF NOT ShortOnMarket AND close >= hbop THEN
    SELLSHORT n CONTRACTS AT market//s1e limit
    //EXITSHORT AT b1e limit
    ENDIF
    
    // Condizioni per uscire da posizioni short
    IF ShortOnMarket and close < b1e THEN
    EXITSHORT AT market//b1e limit
    if close < positionprice then
    exitshort at market
    endif
    ENDIF
    set stop loss (m*ATR)
    //
    timeframe(default) //2 min
    //************************************************************************
    //trailing stop function
    trailingstart = 45 //45 trailing will start @trailinstart points profit
    trailingstep = 15 //15 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

    as from attached screenshot.

    pippo999 and GraHal thanked this post
    x-9.jpg x-9.jpg
    #87415 quote
    coscar
    Participant
    Senior

    **** Google translator*******
    Thank you all for your contribution.
    In theory, the strategy should appeal to all markets with appropriate optimization, in fact I would like to create a diversified portfolio on this strategy.
    Roberto hrazie for your MTF code but are looking for a strategy that can betray in real and I think the MTF is not yet supported in real mode, or something has changed? Currently I use PRT of IG which has some limitation.

    #87417 quote
    Vonasi
    Moderator
    Master

    You are correct that MTF is still only in beta testing but we should all be using this opportunity to live forward test MTF strategies so that we are ready and confident in them when it finally gets put live. Also it helps PRT/IG find any bugs which can only benefit us too.

    Regarding your topic title and trying to reduce draw down. I personally think the draw down is already pretty low on your strategy and it will be difficult to improve on it without adding new conditions which will then just lead to less trades and less profit and increased chance of curve fitting. I usually have in my mind that every time that I add a condition that has a variable then I am multiplying the curve fitting probability by two. My theory is that if we keep it simple and it works then it is more likely to work going forward than a complicated strategy is.

    pippo999 thanked this post
    #87418 quote
    coscar
    Participant
    Senior

    Thanks Vonasi
    in fact, my goal is to find a simple strategy that is stable.

    #87424 quote
    robertogozzi
    Moderator
    Master

    Drawdown can be further reduced by applying the same strategy above to Heikin-Ashi candlesticks (still Nicolas’ trailing stop code uses regular japanese candlesticks).

    I tested it on regular EurUsd, rather than the mini one because I found out it is not just a simple math issue (it’s, or it should be, just a division by ten), because on the mini contract I’ve been reported more than 300 trades, almost all losing money. While there’s no difference when applied to DAX €25 and DAX €5, it’s the same behaviour, only multiplied/divided by 5!

    //Eur/Usd mini - 1D Capital Eur 500,00
     
    DEFPARAM CUMULATEORDERS = false
    DEFPARAM PRELOADBARS    = 0
    timeframe(Daily,UpdateOnClose) //Daily
    // HA definition
    if BarIndex > 1 then
    xClose  = (open+close+low+high)/4
    xOpen   = (xOpen[1]+xClose[1])/2
    haHigh  = Max(xOpen, xClose)
    haLow   = Min(xOpen, xClose)
    xHigh   = Max(High,haHigh)
    xLow    = Min(Low,haLow)
    else
    xClose  = (open+close+low+high)/4
    xOpen   = (Open[1]+Close[1])/2
    haHigh  = Max(xOpen, xClose)
    haLow   = Min(xOpen, xClose)
    xHigh   = Max(High,haHigh)
    xLow    = Min(Low,haLow)
    endif
    
    a = 2 //2
    t = 2 //2
    m = 1.8 //1.8
     
    n=1
    Atr = AverageTrueRange[14](xClose) //14
    Atrs = 0.1 //0.1
    x = average[A,0]((xHigh+xLow+xclose)/3) //4
     
    b1e = ((t*x)-xhigh)+(ATR*ATRs)
    s1e = ((t*x)-xLow)-(ATR*ATRs)
    Hbop = (t*x)-(t*xLow)+xHigh
    Lbop = (t*x)-(t*xHigh)+xLow
     
    // Condizioni per entrare su posizioni long
    IF NOT LongOnMarket AND xclose <= lbop THEN
    BUY n CONTRACTS AT market//b1e limit
    //SELL AT s1e limit
    ENDIF
     
    // Condizioni per uscire da posizioni long
    If LongOnMarket and xclose > s1e THEN
    SELL AT market//s1e limit
    if xclose > positionprice then//positionprice then
    sell at market
    endif
    ENDIF
     
    // Condizioni per entrare su posizioni short
    IF NOT ShortOnMarket AND xclose >= hbop THEN
    SELLSHORT n CONTRACTS AT market//s1e limit
    //EXITSHORT AT b1e limit
    ENDIF
     
    // Condizioni per uscire da posizioni short
    IF ShortOnMarket and xclose < b1e THEN
    EXITSHORT AT market//b1e limit
    if xclose < positionprice then
    exitshort at market
    endif
    ENDIF
    set stop loss (m*ATR)
    //
    timeframe(default) //2 min
    //************************************************************************
    //trailing stop function
    trailingstart = 35   //35 trailing will start @trailinstart points profit
    trailingstep  = 15   //15 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
    GraHal thanked this post
    x-10.jpg x-10.jpg
    #87465 quote
    coscar
    Participant
    Senior

    Ok grazie Roberto, lo proverò ma ho notato dal tuo screenshots che per alcuni mesi non scambia.

    #87473 quote
    Vonasi
    Moderator
    Master

    coscar – English only please in the English speaking forum – even if you are both Italian!

    #87476 quote
    coscar
    Participant
    Senior

    Sorry Vonasi, it’s the fault of the automatic translator.
    “Ok, thanks Roberto, I’ll try it but I noticed from your screenshots that for a few months it does not exchange.”

    #87479 quote
    coscar
    Participant
    Senior

    Hello Vonasi and Roberto I still ask you a kindness, you could test the attached code since 1995. Thank you

    //@Coscar Break Out Point on Eur/Usd mini - 1D  Capital Ini Eur 500,00
     
    DEFPARAM CUMULATEORDERS= false
    DEFPARAM PRELOADBARS = 10000
    
    //***********************************************************************************************************
    CapitalIni = 10000      // Capitale iniziale cifra intera
    NrContratti = 1       // numero di contratti iniziali
    MargineBroker = 378  // Margine richiesto dal broker per 1 contratto Eur/Usd Mini
    Martingala = 1       // "1" per ON , "0" per OFF del sistema Martinagala
    Multi = 1           //Martingala Moltiplicatore in caso di vincita - "1" per OFF
    Reinvestimento = 1   // "1" per ON , "0" per OFF reinvestimento Capiatale e profitto
    Perc = 20           // Percentuale del capiatale destinato al reinvestimento (consiglio max 30%)
    Protec = 100           // "0" per OFF, Contratti massimi consentiti al sistema -Ricordarsi di inserire questo valore in fase di Trading Automatico in PRT
    Avg = 2              // Moving Average Period Two Day
    Atrs = 0.16          // Multiplier coefficient Atr
    m = 1.8              // Multiplier coefficient Stop Loss
    
    //***********************************************************************************************
    ONCE OrderSize = NrContratti
    ONCE ExitIndex = -2
    
    Capital= CapitalIni + strategyprofit
    IF Reinvestimento = 1 THEN
    NR = ((Capital * Perc/100)/MargineBroker)*1000
    n = (ROUND(NR)/1000)
    Else
    n = 1
    endif
    
    IF Protec>0 and n>Protec THEN
    n=Protec
    endif
    
    Atr = AverageTrueRange[14](close)
    x = average[Avg,3]((High+Low+close)/3)
     
    b1e = ((2*x)-high)+(ATR*ATRs)
    s1e = ((2*x)-Low)-(ATR*ATRs)
    Hbop = (2*x)-(2*Low)+High
    Lbop = (2*x)-(2*High)+Low
     
    // Condizioni per entrare su posizioni long
    IF NOT LongOnMarket AND close<lbop THEN
    BUY OrderSize CONTRACTS AT b1e limit
    SELL AT s1e limit
    ENDIF
     
    // Condizioni per uscire da posizioni long
    If LongOnMarket THEN
    SELL AT s1e limit
    if close > positionprice then
    sell at market
    endif
    ExitIndex = BarIndex
    ENDIF
     
    // Condizioni per entrare su posizioni short
    IF NOT ShortOnMarket AND close>hbop THEN
    SELLSHORT OrderSize CONTRACTS AT s1e limit
    EXITSHORT AT b1e limit
    ENDIF
     
    // Condizioni per uscire da posizioni short
    IF ShortOnMarket THEN
    EXITSHORT AT b1e limit
    if close < positionprice then
    exitshort at market
    endif
    ExitIndex = BarIndex
    ENDIF
    set stop loss (m*ATR)
    
    //Martingala************************
    IF Barindex = ExitIndex + 1 THEN
    ExitIndex = 0
    IF PositionPerf(1) < 0 THEN
    OrderSize =  OrderSize + (Martingala*0)
    ELSIF PositionPerf(1) > 0 THEN
    OrderSize = 1 * n * Multi
    ENDIF
    ENDIF
    IF Capital<-500 then
    Quit
    ENDIF
    GRAPH OrderSize
    
    Coscar-BOP1.png Coscar-BOP1.png Coscar-BOP2.png Coscar-BOP2.png
    #87483 quote
    Vonasi
    Moderator
    Master

    It is not possible to test it from 1995 as you need tick by tick data which is only available from mid 2010.

    #87485 quote
    coscar
    Participant
    Senior

    OK thanks, you could check the robustness of this code, I would like to start it in real time. Thanks for your availability

    #87487 quote
    Vonasi
    Moderator
    Master

    I have not had a chance to test your code yet but the only way to truly test robustness is to live forward test a strategy in demo. Personally I would not put any real money on any strategy until I have seen months of forward testing in a variety of market conditions and preferably lots and lots of trades. It is boring and you need a lot of patience but losing money is easy enough so why be in such a hurry to do it?

    I see that you have added some form of martingale and money management. Don’t do this until you have forward tested the strategy with level stakes – it just makes you imagine all the money you could be making when in reality you don’t even know if level stakes would make you any. Martingale is very dangerous unless you have a very high win rate strategy or one where the wins are much bigger than the losses and even then it can all suddenly get very expensive in just a few losing trades. If you have Warren Buffets bank balance behind you then use martingale – if not then don’t.

    All just my humble opinion but then people have all sorts of opinions on how to best lose money at this game!

    #102093 quote
    TempusFugit
    Participant
    Veteran

    I did a multitimeframe version of this fine system that seems to perform quite well in backtest, I haven´t tried it yet in real or demo

    COSCAR-EURSD1h-PRTCode.itf
    #102096 quote
    robertogozzi
    Moderator
    Master

    Next autumn v11 is likely to be made available to IG customers, thus making 1M bars available for backtesting.

    #102107 quote
    Vonasi
    Moderator
    Master

    Here is the code from the version posted by TempusFugit. My main concern if I had coded it myself would be the exit conditions based on days of week and time and bars since trades opened which seem to smell horribly of data mining.

    The true test is to remove most of them and see how it fairs. With just the exit if it is 2100 hours and the rest of them are removed then the equity curve is a little less inspiring. Image attached.

    If we let them back in one by one then the equity curve starts to look nice again which is really telling us that they are just data mining conditions. IMHO.

    // COSCAR Eur/Usd mini - 1H En PRTCode
    //Version Tempus Fugit
    
    DEFPARAM CUMULATEORDERS= false
    DEFPARAM PRELOADBARS = 10000
    
    //VARIABLES
    PositionSize = 1
    ENTRYHOURS   = HOUR=1
    nwma         = 2 //Periodos de la Media de Willians sobre "la mediana"
    t            = 2//Multiplicador de la media y otros valores
    NATR         = 14//Periodos del ATR
    m            = 1.8//2.7 //Multiplicador del ATR para el stop
    Atrs         = 0.16//Multiplicador del ATR para el precio límite de salida
    
    Timeframe(Daily,Updateonclose)
    Atr = AverageTrueRange[NATR](close)
    x = average[nwma,3]((High+Low+close)/3)
    
    b1e = ((t*x)-high)+(ATR*ATRs)
    s1e = ((t*x)-Low)-(ATR*ATRs)
    Hbop = (t*x)-(t*Low)+High
    Lbop = (t*x)-(t*High)+Low
    
    LONGSIGNAL = CLOSE<LBOP
    SHORTSIGNAL = CLOSE>HBOP
    
    Timeframe(Default)
    LONGENTRY = LONGSIGNAL
    LONGENTRY = LONGENTRY AND ENTRYHOURS
    LONGENTRY = LONGENTRY AND DAYOFWEEK<4//SIN JUEVES Y VIERNES
    
    SHORTENTRY = SHORTSIGNAL
    SHORTENTRY = SHORTENTRY AND ENTRYHOURS
    SHORTENTRY = SHORTENTRY AND DAYOFWEEK<4//SIN JUEVES Y VIERNES
    
    IF LONGENTRY THEN
    BUY PositionSize CONTRACTS AT B1E LIMIT
    SELL AT s1e limit
    ELSIF SHORTENTRY THEN
    SELLSHORT PositionSize CONTRACTS AT S1E LIMIT
    EXITSHORT AT b1e limit
    ENDIF
    
    If LongOnMarket  THEN
    SELL AT s1e limit
    ELSIF ShortOnMarket  THEN
    EXITSHORT AT b1e limit
    endif
    
    WINEXIT = ONMARKET
    WINEXIT = WINEXIT AND POSITIONPERF>0
    WINEXIT = WINEXIT AND (HOUR=21 OR (BARINDEX-TRADEINDEX>70))
    
    LOSSEXIT = ONMARKET
    LOSSEXIT = LOSSEXIT AND POSITIONPERF<0
    LOSSEXIT = LOSSEXIT AND BARINDEX-TRADEINDEX>80
    LOSSEXIT = LOSSEXIT AND HOUR>=21
    LOSSEXIT = LOSSEXIT AND (DAYOFWEEK=3 OR DAYOFWEEK=5)
    
    IF WINEXIT OR LOSSEXIT THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    
    set stop loss (m*ATR)
    
    Screenshot_5.png Screenshot_5.png
Viewing 15 posts - 16 through 30 (of 55 total)
  • You must be logged in to reply to this topic.

Strategy Eur/Usd mini, how to reduce the maximum % drawdown?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
coscar @coscar Participant
Summary

This topic contains 54 replies,
has 7 voices, and was last updated by Gregg
6 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/18/2018
Status: Active
Attachments: 22 files
Logo Logo
Loading...