Kama & Sma Trading System DAX mtf

Category: Strategies By: robertogozzi Created: August 21, 2019, 10:10 AM
August 21, 2019, 10:10 AM
Strategies
50 Comments

Coded for micro DAX €1 (simply multiply by 25 to run on standard DAX €25 or by 5 to run on mini DAX €5), 1-hour TF.

I used the Multiple Time Frame support to allow Breakeven/Trailing Stop to run on 1-minute bars (default TF).

Strategy from https://www.forexstrategiesresources.com/trend-following-forex-strategies/111-kama-strategy/.

Compared to the original version at the above link, I only optimized the SMA (called MVA in the above site) and set it to 22, instead of 7.

I also added SL & TP plus my own Breakeven/Trailing Stop code snippet.

Lines 10-11 allow to enable/disable Long/Short trading (both enabled by default).

Lines 21-25, along with lines 54-61 and lines 67 and 74, ban further trading before a whole 1-hour bar has elapsed, in case a trade exits within a few 1-minute bars. In such case the 1-hour signal is still set and valid, but it would most likely lead to a losing trade since the momentum is likely to have faded.

//************************************************************************
//                 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            = 200                              //200  pips
ONCE SL            = 50                               //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     = 2                                              //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

Download
Filename: Kama.jpg
Downloads: 790
Download
Filename: Kama-Sma-DAX-mtf.itf
Downloads: 1560
Download
Filename: Kama-Sma-Trading-System-DAX-mtf.txt
Downloads: 642
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Logo Logo
Loading...