HLHB Trend Catcher - DAX mtf

Category: Strategies By: robertogozzi Created: July 23, 2019, 8:37 AM
July 23, 2019, 8:37 AM
Strategies
13 Comments

I coded this strategy after reading this website https://www.babypips.com/trading/forex-hlhb-system-explained, where the logic is best described.

Basically it enters LONG when a Fast Ema crosses over a Slow Ema AND Rsi crosses over its mid line. The reverse for SHORT trades.

I used the same settings for Ema’s (5 and 10), while I changed Rsi periods from 10 to 8 because the optimization granted better results. I also optimized TP’s and SL’s.

I coded it on DAX 1-minute default TF and 1-hour TF for signals.

Many inner workings are commented and easy to understand and change.

I will describe what I think deserves a deeper insight:

  • Line 10 sets the default TF (1-minute).
  • Line 12 allows to choose how the Trailing Stop code should behave (0 will use CLOSE to check prices, 1 will use HIGH/LOW).
  • Lines 21-157 allow to choose trading hours, days and months.
  • Lines 160 and 161 are the basic conditions for Long/Short trades.
  • At line 163 TF 1-hour is started, that’s where the signals are returned.
  • Lines 184-190 set data to be used as signals (two Ema’s + Rsi).
  • Lines 192-195 prepare the setup for LONG tradses, while lines 196-200 prepare the seup for SHORT trades.
  • The 1-hour TF has finished its tasks and it’s time to resort again to the default TF (1-minute) at line 202.
  • Lines 203-210 are used to avoid entering again after a signal, if a trade is exited before the next hour begins (the signal is still set, but entering at such a late time may cause SL to be hit).
  • lines 211-230 enter trades and set flag TradeON to 0, to finish what lines 203-210 have started.
  • The last snippet starts at line 233, it’s the TRAILING STOP. Lines 233-343 set the reference to either CLOSE or HIGH/LOW according to one of the first options encountered earlier:
    TRAILSTART         is the number of pips after which trailing starts.
    BASEPERCENT     is the base percentage of profits to be secured when Trailing begins.
    STEPSIZE                is the number of pips needed to increment SL.
    PERCENTINC        is the percentage that BASEPERCENT needs to be incremented each STEPSIZE pips. So that if BASEPERCENT     is 10% initially, after each STEPSIZE chunk will be incremented by this PERCENTINC, if it is 20%, then BASEPERCENT     will rise to 12% the first time, then another 20%, rising to 14.4% the second time and so on… as profits grow.
    PRICEDISTANCE is the minimum distance the broker requires for an instrument when a pending order is entered (I use 7 for DAX, despite it is actually slightly lower).
//************************************************************************
//                      HLHB Trend Catcher - DAX mtf
//
//         https://www.babypips.com/trading/forex-hlhb-system-explained
//************************************************************************
//
DEFPARAM CumulateOrders = False
DEFPARAM PreLoadBars    = 2000
////////////////////////////////////////////////////////////////////////
TIMEFRAME (default)
ONCE nLots         = 1
ONCE TrailHILO     = 0                                //0=use CLOSE 1=use HiLo to trailSL
ONCE LongTrading   = 1//w1//1                         //1=allowed   0=banned
ONCE ShortTrading  = 1//w2//1                         //1=allowed   0=banned
// Target Profit & Stop Loss settings
ONCE TPlong        = 262                              //262
ONCE SLlong        = 39                               //39
ONCE TPshort       = 26                               //26
ONCE SLshort       = 50                               //50
//
OpenJan            = 0//w3//0                          //0=not forbidden 1=forbidden
OpenFeb            = 0//w4//0                          //0=not forbidden 1=forbidden
OpenMar            = 0//w5//0                          //0=not forbidden 1=forbidden
OpenApr            = 0//w6//0                          //0=not forbidden 1=forbidden
OpenMay            = 0//w7//0                          //0=not forbidden 1=forbidden
OpenJun            = 0//w8//0                          //0=not forbidden 1=forbidden
OpenJul            = 0//w9//0                          //0=not forbidden 1=forbidden
OpenAug            = 0//w10//0                         //0=not forbidden 1=forbidden
OpenSep            = 0//w11//0                         //0=not forbidden 1=forbidden
OpenOct            = 0//w12//0                         //0=not forbidden 1=forbidden
OpenNov            = 0//w13//0                         //0=not forbidden 1=forbidden
OpenDec            = 0//w14//0                         //0=not forbidden 1=forbidden
MonthsForbidden    = 0
IF OpenJan = 1 AND OpenMonth = 1 THEN
MonthsForbidden = 1
ELSIF OpenFeb = 1 AND OpenMonth = 2 THEN
MonthsForbidden = 1
ELSIF OpenMar = 1 AND OpenMonth = 3 THEN
MonthsForbidden = 1
ELSIF OpenApr = 1 AND OpenMonth = 4 THEN
MonthsForbidden = 1
ELSIF OpenMay = 1 AND OpenMonth = 5 THEN
MonthsForbidden = 1
ELSIF OpenJun = 1 AND OpenMonth = 6 THEN
MonthsForbidden = 1
ELSIF OpenJul = 1 AND OpenMonth = 7 THEN
MonthsForbidden = 1
ELSIF OpenAug = 1 AND OpenMonth = 8 THEN
MonthsForbidden = 1
ELSIF OpenSep = 1 AND OpenMonth = 9 THEN
MonthsForbidden = 1
ELSIF OpenOct = 1 AND OpenMonth = 10 THEN
MonthsForbidden = 1
ELSIF OpenNov = 1 AND OpenMonth = 11 THEN
MonthsForbidden = 1
ELSIF OpenDec = 1 AND OpenMonth = 12 THEN
MonthsForbidden = 1
ENDIF
//
OpenMon            = 0//w1//0                          //0=not forbidden 1=forbidden
OpenTue            = 0//w2//0                          //0=not forbidden 1=forbidden
OpenWed            = 0//w3//0                          //0=not forbidden 1=forbidden
OpenThu            = 0//w4//0                          //0=not forbidden 1=forbidden
OpenFri            = 0//w5//0                          //0=not forbidden 1=forbidden
OpenSat            = 0//w6//1                          //0=not forbidden 1=forbidden
OpenSun            = 0//w7//1                          //0=not forbidden 1=forbidden
DaysForbidden      = 0
IF OpenMon = 1 AND OpenDayOfWeek = 1 THEN
DaysForbidden = 1
ELSIF OpenTue = 1 AND OpenDayOfWeek = 2 THEN
DaysForbidden = 1
ELSIF OpenWed = 1 AND OpenDayOfWeek = 3 THEN
DaysForbidden = 1
ELSIF OpenThu = 1 AND OpenDayOfWeek = 4 THEN
DaysForbidden = 1
ELSIF OpenFri = 1 AND OpenDayOfWeek = 5 THEN
DaysForbidden = 1
ELSIF OpenSat = 1 AND OpenDayOfWeek = 6 THEN
DaysForbidden = 1
ELSIF OpenSun = 1 AND OpenDayOfWeek = 0 THEN
DaysForbidden = 1
ENDIF
//
OpenH0             = 1                                //0=not forbidden 1=forbidden
OpenH1             = 1                                //0=not forbidden 1=forbidden
OpenH2             = 1                                //0=not forbidden 1=forbidden
OpenH3             = 1                                //0=not forbidden 1=forbidden
OpenH4             = 1                                //0=not forbidden 1=forbidden
OpenH5             = 1                                //0=not forbidden 1=forbidden
OpenH6             = 1                                //0=not forbidden 1=forbidden
OpenH7             = 1                                //0=not forbidden 1=forbidden
OpenH8             = 1                                //0=not forbidden 1=forbidden
OpenH9             = 0//w1//0                         //0=not forbidden 1=forbidden
OpenH10            = 0//w2//0                         //0=not forbidden 1=forbidden
OpenH11            = 0//w3//0                         //0=not forbidden 1=forbidden
OpenH12            = 0//w4//0                         //0=not forbidden 1=forbidden
OpenH13            = 0//w5//0                         //0=not forbidden 1=forbidden
OpenH14            = 0//w6//0                         //0=not forbidden 1=forbidden
OpenH15            = 0//w7//0                         //0=not forbidden 1=forbidden
OpenH16            = 0//w8//0                         //0=not forbidden 1=forbidden
OpenH17            = 0//w9//0                         //0=not forbidden 1=forbidden
OpenH18            = 0//w10//0                        //0=not forbidden 1=forbidden
OpenH19            = 0//w11//0                        //0=not forbidden 1=forbidden
OpenH20            = 1                                //0=not forbidden 1=forbidden
OpenH21            = 1                                //0=not forbidden 1=forbidden
OpenH22            = 1                                //0=not forbidden 1=forbidden
OpenH23            = 1                                //0=not forbidden 1=forbidden
TimeForbidden      = 0
IF OpenH0 = 1 AND OpenHour = 0 THEN
TimeForbidden = 1
ELSIF OpenH1 = 1 AND OpenHour = 1 THEN
TimeForbidden = 1
ELSIF OpenH2 = 1 AND OpenHour = 2 THEN
TimeForbidden = 1
ELSIF OpenH3 = 1 AND OpenHour = 3 THEN
TimeForbidden = 1
ELSIF OpenH4 = 1 AND OpenHour = 4 THEN
TimeForbidden = 1
ELSIF OpenH5 = 1 AND OpenHour = 5 THEN
TimeForbidden = 1
ELSIF OpenH6 = 1 AND OpenHour = 6 THEN
TimeForbidden = 1
ELSIF OpenH7 = 1 AND OpenHour = 7 THEN
TimeForbidden = 1
ELSIF OpenH8 = 1 AND OpenHour = 8 THEN
TimeForbidden = 1
ELSIF OpenH9 = 1 AND OpenHour = 9 THEN
TimeForbidden = 1
ELSIF OpenH10 = 1 AND OpenHour = 10 THEN
TimeForbidden = 1
ELSIF OpenH11 = 1 AND OpenHour = 11 THEN
TimeForbidden = 1
ELSIF OpenH12 = 1 AND OpenHour = 12 THEN
TimeForbidden = 1
ELSIF OpenH13 = 1 AND OpenHour = 13 THEN
TimeForbidden = 1
ELSIF OpenH14 = 1 AND OpenHour = 14 THEN
TimeForbidden = 1
ELSIF OpenH15 = 1 AND OpenHour = 15 THEN
TimeForbidden = 1
ELSIF OpenH16 = 1 AND OpenHour = 16 THEN
TimeForbidden = 1
ELSIF OpenH17 = 1 AND OpenHour = 17 THEN
TimeForbidden = 1
ELSIF OpenH18 = 1 AND OpenHour = 18 THEN
TimeForbidden = 1
ELSIF OpenH19 = 1 AND OpenHour = 19 THEN
TimeForbidden = 1
ELSIF OpenH20 = 1 AND OpenHour = 20 THEN
TimeForbidden = 1
ELSIF OpenH21 = 1 AND OpenHour = 21 THEN
TimeForbidden = 1
ELSIF OpenH22 = 1 AND OpenHour = 22 THEN
TimeForbidden = 1
ELSIF OpenH23 = 1 AND OpenHour = 23 THEN
TimeForbidden = 1
ENDIF
//
TradeCond          = (Not DaysForbidden) AND (Not TimeForbidden) AND (Not MonthsForbidden)
LongCond           = TradeCond AND LongTrading
ShortCond          = TradeCond AND ShortTrading
////////////////////////////////////////////////////////////////////////
TIMEFRAME (1 hour, updateonclose)                                             //h1
IF Not OnMarket THEN
BarCount = 0
ELSE
BarCount = BarCount + 1
ENDIF
// Define some candle features to be used
Bullish     = open < close
Bearish     = open > close
Body        = abs(close - open)
HiWick      = high - max(close,open)
LoWick      = min(close,open) - low
TotalWicks  = HiWick + LoWick
LongCandle  = Body > TotalWicks
LongBullish = LongCandle AND Bullish
LongBearish = LongCandle AND Bearish
BigBullish  = (Body > (range * 0.67)) AND LongBullish
BigBearish  = (Body > (range * 0.67)) AND LongBearish
HugeBullish = (Body > (range * 0.85)) AND BigBullish
HugeBearish = (Body > (range * 0.85)) AND BigBearish
//
ONCE AvgType= 1                                                   //1 = ema
ONCE FastMA = 5                                                   //5
ONCE SlowMA = 10                                                  //10
FastEma     = average[FastMA,AvgType](close)
SlowEma     = average[SlowMA,AvgType](close)
ONCE RsiMid = 50
MyRsi       = Rsi[8](MedianPrice)                                 //8
//------------------------------------------------------------------------------------
// --- LONG
a1 = HugeBullish OR BigBullish OR LongBullish// OR Bullish// OR 1
a2 = FastEma CROSSES OVER  SlowEma
a3 = MyRsi   CROSSES OVER  RsiMid
// --- SHORT

b1 = HugeBearish OR BigBearish OR LongBearish// OR Bearish// OR 1
b2 = FastEma CROSSES UNDER SlowEma
b3 = MyRsi   CROSSES UNDER RsiMid
////////////////////////////////////////////////////////////////////////
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
//************************************************************************
ax = a1 AND a2 AND a3
IF ax AND Not OnMarket AND TradeON AND LongCond THEN
SET TARGET pPROFIT TPlong
SET STOP   pLOSS   SLlong
BUY nLots CONTRACT AT MARKET
TradeON = 0
ENDIF
//************************************************************************
//                           SHORT trades
//************************************************************************
bx = b1 AND b2 AND b3
IF bx AND Not OnMarket AND TradeON AND ShortCond THEN
SET TARGET pPROFIT TPshort
SET STOP   pLOSS   SLshort
SELLSHORT nLots CONTRACT AT MARKET
TradeON = 0
ENDIF
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                Trailing Stop
TrailSlPrice   = close
TrailExitPrice = close
IF TrailHILO THEN
IF LongOnMarket THEN
TrailSlPrice    = high
TrailExitPrice = low
ELSIF ShortOnMarket THEN
TrailSlPrice    = low
TrailExitPrice = high
ENDIF
ENDIF
//------------------------------------------------------------------------------------
IF Not OnMarket THEN
TrailStart    = 12          //12     Start trailing profits from this point
BasePerCent   = 0.094       //09.4%  Profit to keep
StepSize      = 6           //6      Pips chunks to increase Percentage
PerCentInc    = 0.102       //10.2%  PerCent increment after each StepSize chunk
RoundTO       = -0.5        //-0.5   rounds to Lower integer,  +0.4 rounds to Higher integer
PriceDistance = 7 * pipsize //7      minimun distance from current price
y1            = 0
y2            = 0
ProfitPerCent = BasePerCent
ELSIF LongOnMarket AND TrailExitPrice > (TradePrice + (y1 * pipsize)) THEN                         //LONG
x1 = (TrailExitPrice - 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 TrailExitPrice < (TradePrice - (y2 * pipsize)) THEN                        //SHORT
x2 = (tradeprice - TrailExitPrice) / 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(TrailSlPrice - SellPrice) > PriceDistance THEN
IF TrailSlPrice >= 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(TrailSlPrice - ExitPrice) > PriceDistance THEN
IF TrailSlPrice <= ExitPrice THEN
EXITSHORT AT ExitPrice STOP
ELSE
EXITSHORT AT ExitPrice LIMIT
ENDIF
ELSE
EXITSHORT AT Market
ENDIF
ENDIF

Download
Filename: HLHB-Trend-Catcher-DAX-mtf.txt
Downloads: 326
Download
Filename: HLHB-Trend-Catcher-DAX-mtf.itf
Downloads: 812
Download
Filename: Hlhb-2.jpg
Downloads: 341
Download
Filename: Hlhb-1.jpg
Downloads: 558
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Logo Logo
Loading...