Kama & Sma – Sistema su valute con settaggio standard

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #170464 quote
    Stanko
    Participant
    Senior

    Buongiorno Roberto e buongiorno a tutti.

    Vorrei riportare all’attenzione il sistema “Kama & Sma” che in precedenza aveva subito dei problemi di funzionamento, forse non ancora risolti.

    Negli ultimi mesi ho testato, in Demo ed in Reale, il sistema Kama con settaggio 2,2,30 e una SMA a 22 periodi (con Target a 150 e Stop a 40), in particolare con le coppie Eur/Usd, Aud/Usd e Nzd/Usd con risultati molto interessanti.

    Purtroppo, come già accaduto, ad un certo punto il sistema non ha più funzionato (da ieri, 25 maggio, su Eur/Usd).

    Ho quindi ritestato il sistema riportando i settaggi ai valori standard per Kama 10,2,30: i risultati rimangono interessanti ma i profitti sembrano ridursi nettamente.

    Se qualcuno è interessato a svolgere dei backest più ampi e dettagliati, riproporrei il sistema qui di seguito.

    Grazie

    //************************************************************************
    //                 Kama & Sma Trading System DAX mtf
    //************************************************************************
    //
    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars    = 30
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)
    ONCE nLots         = 1
    ONCE LongTrading   = 1                                //1=allowed   0=banned
    ONCE ShortTrading  = 1                                //1=allowed   0=banned
    //
    ONCE TP            = 150                              //200  pips
    ONCE SL            = 40                               //50   pips
    //
    TimeForbidden      = OpenTime < 090000 AND OpenTime > 190000
    LongCond           = (Not TimeForbidden) AND LongTrading
    ShortCond          = (Not TimeForbidden) AND ShortTrading
    //
    TIMEFRAME (1 hour, updateonclose)                                             //h1
    IF Not OnMarket THEN
    BarCount = 0
    ELSE
    BarCount = BarCount + 1
    ENDIF
    //------------------------------------------------------------------------------------
    //                         Kama & Sma Strategy
    //
    //https://www.forexstrategiesresources.com/trend-following-forex-strategies/111-kama-strategy/
    //
    Period     = 10                                            //2        (standard 10)
    FastPeriod = 2                                              //standard
    SlowPeriod = 30                                             //standard
    //
    Fastest  = 2 / (FastPeriod + 1)
    Slowest  = 2 / (SlowPeriod + 1)
    if barindex >= (Period + 1) then
    Num   = abs(close-close[Period])
    Den   = summation[Period](abs(close-close[1]))
    ER    = Num / Den
    Alpha = SQUARE(ER *(Fastest - Slowest )+ Slowest)
    Kama  = (Alpha * Close) + ((1 -Alpha)* Kama[1])
    else
    Kama  = close
    endif
    //------------------------------------------------------------------------------------
    Sma        = average[22,0](close)                           //22
    //------------------------------------------------------------------------------------
    a1 = Kama CROSSES OVER  Sma
    // --- SHORT
    b1 = Kama CROSSES UNDER Sma
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)                                                           //1 min
    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
    TradeON = 1
    ENDIF
    //************************************************************************
    //                           LONG  trades
    //************************************************************************
    IF a1 AND TradeON AND LongCond THEN
    BUY nLots CONTRACT AT MARKET
    TradeON = 0
    ENDIF
    //************************************************************************
    //                           SHORT trades
    //************************************************************************
    IF b1 AND TradeON AND ShortCond THEN
    SELLSHORT nLots CONTRACT AT MARKET
    TradeON = 0
    ENDIF
    //
    SET TARGET pPROFIT TP
    SET STOP   pLOSS   SL
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                Trailing Stop
    //------------------------------------------------------------------------------------
    IF Not OnMarket THEN
    TrailStart    = 10          //10     Start trailing profits from this point
    BasePerCent   = 0.100       //10.0%  Profit to keep
    StepSize      = 6           //6      Pips chunks to increase Percentage
    PerCentInc    = 0.100       //10.0%  PerCent increment after each StepSize chunk
    RoundTO       = -0.5        //-0.5   rounds to Lower integer,  +0.4 rounds to Higher integer
    PriceDistance = 7 * pipsize//8.9    minimun distance from current price
    y1            = 0
    y2            = 0
    ProfitPerCent = BasePerCent
    ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG
    x1 = (close - tradeprice) / pipsize                            //convert price to pips
    IF x1 >= TrailStart THEN                                       //go ahead only if N+ pips
    Diff1         = abs(TrailStart - x1)
    Chunks1       = max(0,round((Diff1 / StepSize) + RoundTO))
    ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))
    ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
    y1 = max(x1 * ProfitPerCent, y1)                            //y = % of max profit
    ENDIF
    ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORT
    x2 = (tradeprice - close) / pipsize                            //convert price to pips
    IF x2 >= TrailStart THEN                                       //go ahead only if N+ pips
    Diff2         = abs(TrailStart - x2)
    Chunks2       = max(0,round((Diff2 / StepSize) + RoundTO))
    ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
    ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
    y2 = max(x2 * ProfitPerCent, y2)                           //y = % of max profit
    ENDIF
    ENDIF
    IF y1 THEN                                        //Place pending STOP order when y>0
    SellPrice = Tradeprice + (y1 * pipsize)        //convert pips to price
    IF abs(close - SellPrice) > PriceDistance THEN
    IF close >= SellPrice THEN
    SELL AT SellPrice STOP
    ELSE
    SELL AT SellPrice LIMIT
    ENDIF
    ELSE
    SELL AT Market
    ENDIF
    ENDIF
    IF y2 THEN                                        //Place pending STOP order when y>0
    ExitPrice = Tradeprice - (y2 * pipsize)        //convert pips to price
    IF abs(close - ExitPrice) > PriceDistance THEN
    IF close <= ExitPrice THEN
    EXITSHORT AT ExitPrice STOP
    ELSE
    EXITSHORT AT ExitPrice LIMIT
    ENDIF
    ELSE
    EXITSHORT AT Market
    ENDIF
    ENDIF
    

    Ho provato , in seguito, ad “adeguare” il vecchio sistema utilizzando la media mobile adattiva ora presente tra gli indicatori di ProRealTime ed il sistema sembra funzionare correttamente anche con settaggio della Media adattiva 2,2,30.

    Qualcuno ha già provato il sistema e può fornire informazioni a riguardo?

    Grazie.

    Di seguito fornisco il sistema con la Media Mobile Adattiva.

    //************************************************************************
    //                 Kama & Sma Trading System DAX mtf
    //************************************************************************
    //
    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars    = 2000
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)
    ONCE nLots         = 1
    ONCE LongTrading   = 1                                //1=allowed   0=banned
    ONCE ShortTrading  = 1                                //1=allowed   0=banned
    //
    ONCE TP            = 150                             //200  pips
    ONCE SL            = 40                               //50   pips
    //
    TimeForbidden      = OpenTime < 090000 AND OpenTime > 190000
    LongCond           = (Not TimeForbidden) AND LongTrading
    ShortCond          = (Not TimeForbidden) AND ShortTrading
    //
    TIMEFRAME (1 hour, updateonclose)                                             //h1
    IF Not OnMarket THEN
    BarCount = 0
    ELSE
    BarCount = BarCount + 1
    ENDIF
    //------------------------------------------------------------------------------------
    //                         Kama & Sma Strategy
    //
    //https://www.forexstrategiesresources.com/trend-following-forex-strategies/111-kama-strategy/
    //
    Kama = AdaptiveAverage[2,2,30](close)
    //------------------------------------------------------------------------------------
    Sma        = average[22,0](close)                           //22
    //------------------------------------------------------------------------------------
    a1 = Kama CROSSES OVER  Sma
    // --- SHORT
    b1 = Kama CROSSES UNDER Sma
    ////////////////////////////////////////////////////////////////////////
    TIMEFRAME (default)                                                           //1 min
    ONCE TradeON = 1
    IF IntraDayBarIndex = 0 THEN
    TradeON = 1
    ENDIF
    TradeBar = BarCount
    IF Not OnMarket AND TradeBar <> TradeBar[1] THEN
    TradeON = 1
    ENDIF
    //************************************************************************
    //                           LONG  trades
    //************************************************************************
    IF a1 AND TradeON AND LongCond AND close[1] < Kama THEN
    BUY nLots CONTRACT AT MARKET
    TradeON = 0
    ENDIF
    //************************************************************************
    //                           SHORT trades
    //************************************************************************
    IF b1 AND TradeON AND ShortCond AND close[1] > Kama THEN
    SELLSHORT nLots CONTRACT AT MARKET
    TradeON = 0
    ENDIF
    //
    SET TARGET pPROFIT TP
    SET STOP   pLOSS   SL
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                Trailing Stop
    //------------------------------------------------------------------------------------
    IF Not OnMarket THEN
    TrailStart    = 10          //10     Start trailing profits from this point
    BasePerCent   = 0.100       //10.0%  Profit to keep
    StepSize      = 6           //6      Pips chunks to increase Percentage
    PerCentInc    = 0.100       //10.0%  PerCent increment after each StepSize chunk
    RoundTO       = -0.5        //-0.5   rounds to Lower integer,  +0.4 rounds to Higher integer
    PriceDistance = 7 * pipsize//8.9    minimun distance from current price
    y1            = 0
    y2            = 0
    ProfitPerCent = BasePerCent
    ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONG
    x1 = (close - tradeprice) / pipsize                            //convert price to pips
    IF x1 >= TrailStart THEN                                       //go ahead only if N+ pips
    Diff1         = abs(TrailStart - x1)
    Chunks1       = max(0,round((Diff1 / StepSize) + RoundTO))
    ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))
    ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
    y1 = max(x1 * ProfitPerCent, y1)                            //y = % of max profit
    ENDIF
    ELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORT
    x2 = (tradeprice - close) / pipsize                            //convert price to pips
    IF x2 >= TrailStart THEN                                       //go ahead only if N+ pips
    Diff2         = abs(TrailStart - x2)
    Chunks2       = max(0,round((Diff2 / StepSize) + RoundTO))
    ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))
    ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))
    y2 = max(x2 * ProfitPerCent, y2)                           //y = % of max profit
    ENDIF
    ENDIF
    IF y1 THEN                                        //Place pending STOP order when y>0
    SellPrice = Tradeprice + (y1 * pipsize)        //convert pips to price
    IF abs(close - SellPrice) > PriceDistance THEN
    IF close >= SellPrice THEN
    SELL AT SellPrice STOP
    ELSE
    SELL AT SellPrice LIMIT
    ENDIF
    ELSE
    SELL AT Market
    ENDIF
    ENDIF
    IF y2 THEN                                        //Place pending STOP order when y>0
    ExitPrice = Tradeprice - (y2 * pipsize)        //convert pips to price
    IF abs(close - ExitPrice) > PriceDistance THEN
    IF close <= ExitPrice THEN
    EXITSHORT AT ExitPrice STOP
    ELSE
    EXITSHORT AT ExitPrice LIMIT
    ENDIF
    ELSE
    EXITSHORT AT Market
    ENDIF
    ENDIF
    
    #170481 quote
    robertogozzi
    Moderator
    Master

    C’erano dei problemicon i backtest per i periodi successivi al 14 Aprile sul DAX a 1 o 10 minuti.

    Ho aperto un ticket d’assistenza un paio di settimane fa, ma ancora non ho avuto risposte.

    #170513 quote
    Stanko
    Participant
    Senior

    Grazie per la risposta.

    Ho visto che il sistema è stato creato per il Dax, però in questo momento ho notato che i risultati migliori sono nel forex.

    Ad ogni modo , eseguendo i backtest di confronto fra Kama e Media Mobile Adattiva i risultati delle performance sono diversi.

    Scusa Roberto, ne approfitto per chiederti se il codice di trailing stop all’interno del sistema Kama è stato creato da chi ha scritto il programma o è stato creato da altri: è comunque un’alternativa interessante ai classici trailing già noti.

    #170529 quote
    robertogozzi
    Moderator
    Master

    E’ un codice che ho scritto io, qui c’è una versione aggiornata con varie aggiunte https://www.prorealcode.com/topic/breakeeven-trailing-profit/page/5/#post-166092.

    #170530 quote
    Stanko
    Participant
    Senior

    Grazie ancora Roberto e complimenti per il tuo eccezionale supporto a questo forum.

    robertogozzi thanked this post
    #170626 quote
    Stanko
    Participant
    Senior

    Buongiorno Roberto.

    Visto che ieri avevo ri-evidenziato il problema di funzionamento del sistema Kama, volevo comunicare che oggi si è aperta una posizione su Eur/Usd (Buy a 1,21935), utilizzando lo stesso sistema Kama con una variante su “DEFPARAM  PreLoadBars.

    Invece di 20K ho inserito solo 30 unità: già ieri non saltava più il sistema ed oggi è ripartito regolarmente.

    E’ possibile che solo questa variante possa evitare problemi?

    Grazie.

    #170631 quote
    robertogozzi
    Moderator
    Master

    Può essere, per qualche motivo i problemi sono da circa metà Aprile fino ai primi di Maggio.

    #207247 quote
    jim
    Participant
    New

    Buonasera, commentate questo trading system.

    #207252 quote
    robertogozzi
    Moderator
    Master

    Si riferisce al Kama?

    #207263 quote
    Stanko
    Participant
    Senior

    Ciao jim,

    dalla tua immagine di backtest non si capisce quale sia il sistema che stai proponendo…

    #207265 quote
    jim
    Participant
    New

    si

    #207266 quote
    jim
    Participant
    New

    Salve

    #207267 quote
    jim
    Participant
    New

    Gentile, come mai risulta un droudown quasi uguale a ai guadagni ?

    #207286 quote
    robertogozzi
    Moderator
    Master

    Occorrerebbe il codice che hai utilizzato ed il timeframe e lo strumento su cui l’hai testato.

    Il drawdown è la perdita massima raggiunta. Potrebbe essere uno stop loss troppo alto (usato per migliorare la precentuale delle operazioni vincenti), ma possono esserci altri motivi.

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

Kama & Sma – Sistema su valute con settaggio standard


ProOrder: Trading Automatico & Backtesting

New Reply
Author
author-avatar
Stanko @stanko Participant
Summary

This topic contains 13 replies,
has 3 voices, and was last updated by robertogozzi
3 years ago.

Topic Details
Forum: ProOrder: Trading Automatico & Backtesting
Language: Italian
Started: 05/26/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...