Firstly apologies for the delay, I had a couple of other matters requiring my attention.
So I finished coding the strategy and then proceeded to test it on different markets and timeframes (Sticking to the 4Hr TimeFrame).
The first issue I encountered was that of price being quoted differently between different forex pairs and indexes.
I overcame this by creating a variable that can be optimized per market called ‘DigitFactor’ in Line 5
Secondly, I have found that the FastEMA must also be optimized for different markets for a value of either 6, 7 or 8
Other than the above optimization is technically not required, but I will experiment with optimizing the Default parameters of the three Ehlers indicators.
//Strategy: Advanced Trend trader
//Author: Juan Jacobs (www.FXautomate.com)
Defparam cumulateorders = False
possize = 1
DigitFactor = 6 //should be optimed between 1 and 10 to cater for different market types i.e. forex or indexes
PointFactor = EXP(DigitFactor*LOG(10))*0.0001
//Components
MA200 = Average[200,0](close)
BollUp = BollingerUp[20](close)
BollDown = BollingerDown[20](close)
FastEMA = Average[6,1](close)//can be optimized between 6 and 8
SlowEMA = Average[13,1](close)
TS = (highest[9](high)+lowest[9](low))/2 //Tenkan-Sen
KS = (highest[26](high)+lowest[26](low))/2 //Kijun-Sen
SA = (TS+KS)/2 //Senkou-Span A (projected 26 periods forward)
SB = (highest[52](high)+lowest[52](low))/2 //Senkou-Span B (projected 26 periods forward)
LevelUp1, LevelDown1, LevelMid1, IFTRSI1 = CALL "PRC_InverseFisherTrans_RSI_1"[10, 1, 9, 50, 100, 0](close)
LevelUp2, LevelDown2, LevelMid2, IFTRSI2 = CALL "PRC_InverseFisherTrans_RSI_2"[32, 0, 9, 50, 80, 20](close)
FractalDim, FractalLevel = CALL "PRC_Ehlers_FDI"[30, 1.4](close)
LimitTrendTrades = 1 //Limits number of trades per trend change
If (FastEMA[1] < SlowEMA[1] and FastEMA > SlowEMA) or ((FastEMA[1] > SlowEMA[1] and FastEMA < SlowEMA)) or (FastEMA[2] < SlowEMA[2] and FastEMA[1] = SlowEMA[1] and FastEMA > SlowEMA) or ((FastEMA[2] > SlowEMA[2] and FastEMA[1] = SlowEMA[1] and FastEMA < SlowEMA)) Then
TrendTrades = 0
StrongTrend = 0
TSPB = 1 //TenkanSen pullback Required by Default
If (FastEMA > SlowEMA and IFTRSI1 > IFTRSI1[1] and IFTRSI1 < LevelMid1 and IFTRSI2 <= LevelDown2) or (FastEMA < SlowEMA and IFTRSI1 < IFTRSI1[1] and IFTRSI1 > LevelMid1 and IFTRSI2 >= LevelUp2) Then
StrongTrend = 1
EndIf
EndIf
If onmarket[1] = 0 and onmarket = 1 Then
LE = 0
SE = 0
TrendTrades = TrendTrades + 1
EndIf
EMARangeLim = 0
For i = 1 to 20 Do
If Round(FastEMA[i]*PointFactor) = round(SlowEMA[i]*PointFactor) Then
EMARangeLim = EMARangeLim + 1
EndIf
Next
//Rules
If onmarket = 0 and FastEMA > SlowEMA and TrendTrades < LimitTrendTrades and EMARangeLim < 1 Then //Up Trend
SEC = 0 //Special Exit Conditions Indicator
If close < MA200 and close < max(SA[26],SB[26]) and close < TS and close < KS and IFTRSI1 > IFTRSI1[1] and BollUp > highest[50](close)[1] Then
Buy possize contract at BollUp stop//market
SEC = 2
ElsIf StrongTrend = 1 and IFTRSI1 > IFTRSI1[1] and IFTRSI1 < LevelMid1 and IFTRSI2 <= LevelDown2 Then //Perfect Long Indicator Setup
If close > MA200 and close > max(SA[26],SB[26]) and SA > SB and SA > SA[26] and close > KS and close < KS and FractalDim >= FractalLevel and abs(open-close) < abs(open[1]-close[1])*5 Then
Buy possize contract at market
ElsIf close < min(SA[26],SB[26]) and close > TS and close > KS Then
Buy possize contract at market
If close > MA200 Then
SEC = 1
Else
SEC = 2
EndIf
EndIf
ElsIf IFTRSI1 > IFTRSI1[1] and (IFTRSI2 > LevelDown2 or FractalDim < FractalLevel) Then //Weak Long Signal
If TSPB = 1 and close < TS Then
TSPB = 0
EndIf
If TSPB = 0 and IFTRSI2 < LevelUp2 and low - max((min(open,close)-low),(high-max(open,close))) > KS Then
Buy possize contract at market
EndIf
EndIf
ElsIf onmarket = 0 and FastEMA < SlowEMA and TrendTrades < LimitTrendTrades and EMARangeLim < 1 Then //Downtrend
SEC = 0 //Special Exit Conditions Indicator
If close > MA200 and close > min(SA[26],SB[26]) and close < TS and close < KS and IFTRSI1 < IFTRSI1[1] and BollDown < lowest[50](close)[1] Then
Sellshort possize contract at BollDown Stop// market
SEC = 2
ElsIf StrongTrend = 1 and IFTRSI1 < IFTRSI1[1] and IFTRSI1 > LevelMid1 and IFTRSI2 >= LevelUp2 Then //Perfect Short Indicator Setup
If close < MA200 and close < min(SA[26],SB[26]) and SA < SB and SA < SA[26] and close < KS and FractalDim <= FractalLevel and abs(open-close) < abs(open[1]-close[1])*5 Then
Sellshort possize contract at market
ElsIf close > max(SA[26],SB[26]) and close < TS and close < KS Then
Sellshort possize contract at market
If close < MA200 Then
SEC = 1
Else
SEC = 2
EndIf
EndIf
ElsIf IFTRSI1 < IFTRSI1[1] and (IFTRSI2 < LevelUp2 or FractalDim > FractalLevel) Then //Weak Short Signal
If TSPB = 1 and close > TS Then
TSPB = 0
EndIf
If TSPB = 0 and IFTRSI2 > LevelDown2 and high + max((high - max(open,close)),(min(open,close)-low)) < KS Then
Sellshort possize contract at market
EndIf
EndIf
EndIf
//Conditional Exits
If longonmarket and SEC = 1 and close < TS and (close < min(SA[26],SB[26]) or (close > min(SA[26],SB[26]) and (IFTRSI1 < IFTRSI1[1] or IFTRSI2 > LevelMid2))) Then
Sell at market
ElsIf longonmarket and SEC = 2 and (close < TS or high >= MA200) Then
Sell at market
ElsIf shortonmarket and SEC = 1 and close > TS and (close > max(SA[26],SB[26]) or (close < max(SA[26],SB[26]) and (IFTRSI1 > IFTRSI1[1] or IFTRSI2 < LevelMid2))) Then
Exitshort at market
ElsIf shortonmarket and SEC = 2 and (close > TS or high <= MA200) Then
Exitshort at market
EndIf
If longonmarket and LE = 0 and IFTRSI2 > LevelUp2 and IFTRSI1 < IFTRSI1[1] and (close < TS or close <= max(highest[2](open)[1],highest[2](close)[1])) Then
Sell at market
ElsIf longonmarket and LE = 0 and IFTRSI2 > LevelUp2 Then
LE = 1
ElsIf longonmarket and LE = 1 and IFTRSI2 < LevelUp2 Then
LE = 0
ElsIf longonmarket and LE = 1 and IFTRSI1 < IFTRSI1[1] and (close < TS or close <= max(highest[2](open)[1],highest[2](close)[1])) Then
Sell at market
ElsIf longonmarket and LE = 1 and IFTRSI1 < IFTRSI1[1] Then
LE = 2
ElsIf longonmarket and LE = 2 and IFTRSI1 > IFTRSI1[1] and close > TS Then
LE = 1
ElsIf longonmarket and LE = 2 and (close < TS or close <= max(highest[2](open)[1],highest[2](close)[1]) or FractalDim < FractalLevel) Then
Sell at market
ElsIf shortonmarket and SE = 0 and IFTRSI2 < LevelDown2 and IFTRSI1 > IFTRSI1[1] and (close > TS or close >= min(lowest[2](open)[1],lowest[2](close)[1])) Then
Exitshort at market
ElsIf shortonmarket and SE = 0 and IFTRSI2 < LevelDown2 Then
SE = 1
ElsIf shortonmarket and SE = 1 and IFTRSI2 > LevelDown2 Then
SE = 0
ElsIf shortonmarket and SE = 1 and IFTRSI1 > IFTRSI1[1] and (close > TS or close >= min(lowest[2](open)[1],lowest[2](close)[1]) or FractalDim > FractalLevel) Then
Exitshort at market
ElsIf shortonmarket and SE = 1 and IFTRSI1 > IFTRSI1[1] Then
SE = 2
ElsIf shortonmarket and SE = 2 and IFTRSI1 < IFTRSI1[1] and close < TS Then
SE = 1
ElsIf shortonmarket and SE = 2 and (close > TS or close >= min(lowest[2](open)[1],lowest[2](close)[1]) or FractalDim > FractalLevel) Then
Exitshort at market
EndIf
//Immediate Exits
If longonmarket and ((close < KS and IFTRSI1 < IFTRSI1[1] and IFTRSI1 > LevelDown1) or (LE >= 1 and IFTRSI1 < IFTRSI1[1] and close < TS and IFTRSI1 > LevelDown1 and FractalDim < FractalLevel)) Then
Sell at market
ElsIf shortonmarket and ((close > KS and IFTRSI1 > IFTRSI1[1] and IFTRSI1 < LevelUp1) or (SE >= 1 and IFTRSI1 > IFTRSI1[1] and close > TS and IFTRSI1 < LevelUp1 and FractalDim > FractalLevel)) Then
Exitshort at market
EndIf
//Graph LE coloured(0,0,255) as "LE"
//Graph SE coloured(255,0,0) as "SE"
//Graph SEC as "SEC"
//Graph TSPB as "TSPB"
Below is two examples both configured exactly the same (FastEMA = 6), USDJPY (Spread: 0.8) and US Crude (Spread: 5)