Need help to automate these MQL5 Indicators
Forums › ProRealTime English forum › ProBuilder support › Need help to automate these MQL5 Indicators
- This topic has 30 replies, 5 voices, and was last updated 5 years ago by Holy Grail.
Tagged: Ehlers, fdi, fractal dimension index, sinewave
-
-
08/17/2018 at 11:49 AM #7844308/17/2018 at 11:53 AM #7844608/17/2018 at 12:07 PM #7845008/17/2018 at 12:37 PM #78457
Okay, made some cosmetic changes and now we have a perfect match to the MetaTrader Setup!
Now for the fun part, coding the strategy along with it’s rules!
Will hopefully have it ready later tonight…
1 user thanked author for this post.
08/17/2018 at 1:01 PM #7846008/17/2018 at 9:42 PM #78506Update! I’m 90% there and so far so good. Just need to build in this exception to rule 5:
If we are below the 200MA and below or in the cloud (and also above Tenkan-Sen and Kijun-Sen) and condition 1-2 is validated but we have a strong close above the Bollinger Band with a Bollinger W-Bottom structure taken out, take a long position and use the 200MA as the target. Use a close below Tenkan-Sen as a stop. The opposite would apply for short positions.Getting late so might have to continue tomorrow.1 user thanked author for this post.
08/18/2018 at 8:52 PM #78573Firstly 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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163//Strategy: Advanced Trend trader//Author: Juan Jacobs (www.FXautomate.com)Defparam cumulateorders = Falsepossize = 1DigitFactor = 6 //should be optimed between 1 and 10 to cater for different market types i.e. forex or indexesPointFactor = EXP(DigitFactor*LOG(10))*0.0001//ComponentsMA200 = Average[200,0](close)BollUp = BollingerUp[20](close)BollDown = BollingerDown[20](close)FastEMA = Average[6,1](close)//can be optimized between 6 and 8SlowEMA = Average[13,1](close)TS = (highest[9](high)+lowest[9](low))/2 //Tenkan-SenKS = (highest[26](high)+lowest[26](low))/2 //Kijun-SenSA = (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 changeIf (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)) ThenTrendTrades = 0StrongTrend = 0TSPB = 1 //TenkanSen pullback Required by DefaultIf (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) ThenStrongTrend = 1EndIfEndIfIf onmarket[1] = 0 and onmarket = 1 ThenLE = 0SE = 0TrendTrades = TrendTrades + 1EndIfEMARangeLim = 0For i = 1 to 20 DoIf Round(FastEMA[i]*PointFactor) = round(SlowEMA[i]*PointFactor) ThenEMARangeLim = EMARangeLim + 1EndIfNext//RulesIf onmarket = 0 and FastEMA > SlowEMA and TrendTrades < LimitTrendTrades and EMARangeLim < 1 Then //Up TrendSEC = 0 //Special Exit Conditions IndicatorIf 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] ThenBuy possize contract at BollUp stop//marketSEC = 2ElsIf StrongTrend = 1 and IFTRSI1 > IFTRSI1[1] and IFTRSI1 < LevelMid1 and IFTRSI2 <= LevelDown2 Then //Perfect Long Indicator SetupIf 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 ThenBuy possize contract at marketElsIf close < min(SA[26],SB[26]) and close > TS and close > KS ThenBuy possize contract at marketIf close > MA200 ThenSEC = 1ElseSEC = 2EndIfEndIfElsIf IFTRSI1 > IFTRSI1[1] and (IFTRSI2 > LevelDown2 or FractalDim < FractalLevel) Then //Weak Long SignalIf TSPB = 1 and close < TS ThenTSPB = 0EndIfIf TSPB = 0 and IFTRSI2 < LevelUp2 and low - max((min(open,close)-low),(high-max(open,close))) > KS ThenBuy possize contract at marketEndIfEndIfElsIf onmarket = 0 and FastEMA < SlowEMA and TrendTrades < LimitTrendTrades and EMARangeLim < 1 Then //DowntrendSEC = 0 //Special Exit Conditions IndicatorIf 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] ThenSellshort possize contract at BollDown Stop// marketSEC = 2ElsIf StrongTrend = 1 and IFTRSI1 < IFTRSI1[1] and IFTRSI1 > LevelMid1 and IFTRSI2 >= LevelUp2 Then //Perfect Short Indicator SetupIf 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 ThenSellshort possize contract at marketElsIf close > max(SA[26],SB[26]) and close < TS and close < KS ThenSellshort possize contract at marketIf close < MA200 ThenSEC = 1ElseSEC = 2EndIfEndIfElsIf IFTRSI1 < IFTRSI1[1] and (IFTRSI2 < LevelUp2 or FractalDim > FractalLevel) Then //Weak Short SignalIf TSPB = 1 and close > TS ThenTSPB = 0EndIfIf TSPB = 0 and IFTRSI2 > LevelDown2 and high + max((high - max(open,close)),(min(open,close)-low)) < KS ThenSellshort possize contract at marketEndIfEndIfEndIf//Conditional ExitsIf 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))) ThenSell at marketElsIf longonmarket and SEC = 2 and (close < TS or high >= MA200) ThenSell at marketElsIf 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))) ThenExitshort at marketElsIf shortonmarket and SEC = 2 and (close > TS or high <= MA200) ThenExitshort at marketEndIfIf 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])) ThenSell at marketElsIf longonmarket and LE = 0 and IFTRSI2 > LevelUp2 ThenLE = 1ElsIf longonmarket and LE = 1 and IFTRSI2 < LevelUp2 ThenLE = 0ElsIf longonmarket and LE = 1 and IFTRSI1 < IFTRSI1[1] and (close < TS or close <= max(highest[2](open)[1],highest[2](close)[1])) ThenSell at marketElsIf longonmarket and LE = 1 and IFTRSI1 < IFTRSI1[1] ThenLE = 2ElsIf longonmarket and LE = 2 and IFTRSI1 > IFTRSI1[1] and close > TS ThenLE = 1ElsIf longonmarket and LE = 2 and (close < TS or close <= max(highest[2](open)[1],highest[2](close)[1]) or FractalDim < FractalLevel) ThenSell at marketElsIf 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])) ThenExitshort at marketElsIf shortonmarket and SE = 0 and IFTRSI2 < LevelDown2 ThenSE = 1ElsIf shortonmarket and SE = 1 and IFTRSI2 > LevelDown2 ThenSE = 0ElsIf 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) ThenExitshort at marketElsIf shortonmarket and SE = 1 and IFTRSI1 > IFTRSI1[1] ThenSE = 2ElsIf shortonmarket and SE = 2 and IFTRSI1 < IFTRSI1[1] and close < TS ThenSE = 1ElsIf shortonmarket and SE = 2 and (close > TS or close >= min(lowest[2](open)[1],lowest[2](close)[1]) or FractalDim > FractalLevel) ThenExitshort at marketEndIf//Immediate ExitsIf 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)) ThenSell at marketElsIf 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)) ThenExitshort at marketEndIf//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)
08/19/2018 at 8:34 PM #78610So after another day of testing and coding, I made some more enhancements to the above.
I added additional criteria to identify weak signals and I also replaced the second Indicator with Ehlers latest Sinewave indicator and I also replaced the Fractal Dimension Indicator with Ehlers Hurst Coefficient.
Thank you Nicolas for all your help!
I won’t be posting every iteration of this strategy, but if you are interested you are welcome to contact me.
01/15/2019 at 11:22 AM #88662So perhaps just an update on this strategy:
I have been keeping an eye on it since my last post (5months ago) and the edge so far appears to remain valid. Attached are the results for USDJPY and US Crude for comparison against the previous ones. I have submitted the strategy including the changes I made on 19/08/18 to the library for approval.
01/15/2019 at 2:17 PM #88680Thanks a lot, the strategy is now available in the library (and with a nice and complete description thanks to you) here: Advanced Trend Trader
Good job! I appreciate a lot.
01/15/2019 at 7:04 PM #8871501/16/2019 at 6:43 AM #88732Dear Juanj,
I read this thread a couple of times and have difficulties finding the code for the indicators that your final version of the “Advanced Trend Trader” -strategy uses. Can you pls single out the codes for the indicators in a reply? Thanks!
//Mags
01/16/2019 at 8:47 AM #88741Hi Mags, my apologies. We decided to log separate requests for each of the indicators:
- https://www.prorealcode.com/topic/ehler-fractal-dimension-conversion-code-mq5-to-prt/
- https://www.prorealcode.com/topic/ehlers-inverse-fisher-transform-of-rsi-conversion-code-mq5-to-prt/
- https://www.prorealcode.com/topic/ehlers-inverse-fisher-transform-conversion-code-mq5-to-prt/
When you install the ITF of the Advanced Trend Trader strategy (found in the library) you will also automatically have the following indicators installed:
- Ehlers Even Better Sinewave (used in place of the Ehlers Inverse Fisher Transform of RSI)
- Ehlers Hurst Coefficient (used in place of the Ehler Fractal Dimension)
01/16/2019 at 4:49 PM #8883601/16/2019 at 6:39 PM #88848Hi again Juanj!
I actually have need for some more clarification.
The last two indicators you refer to – Ehlers Even Better Sinewave and Ehlers Hurst Coefficient do not seem to be quoted here in ProRealCode? Maybe these are your own developments, but if they are ok to share please do!
-
AuthorPosts
Find exclusive trading pro-tools on