Need help to automate these MQL5 Indicators

Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #78443 quote
    Nicolas
    Keymaster
    Master

    indis 3/ and 4/ successfully converted, the code is attached to this post. Example attached: above oscillator is RSI and below is RSX.

    Next is 5/ FDI, to check the differences between MT5 and PRT version already available.

    ehlers-inverse-fisher-transform-of-RSI-and-RSX.png ehlers-inverse-fisher-transform-of-RSI-and-RSX.png
    #78446 quote
    juanj
    Participant
    Master

    Awesome Nicolas!

    I will start coding the strategy using the existing Fractal Dimension Index! And then just swop it out with the new version if you find you need to update it.

    #78450 quote
    Nicolas
    Keymaster
    Master

    Here is the updated version of FDI. Please use this one. The difference came from the applied price for the calculation.

    PRC_Ehlers_FDI.itf ehlers-fractal-dimension-index-fdi.png ehlers-fractal-dimension-index-fdi.png
    #78457 quote
    juanj
    Participant
    Master

    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…

    AlgoAlex thanked this post
    PRT-Adapted.jpg PRT-Adapted.jpg
    #78460 quote
    Nicolas
    Keymaster
    Master

    Good luck! 😆

    #78506 quote
    juanj
    Participant
    Master

    Update! 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.
    AlgoAlex thanked this post
    #78573 quote
    juanj
    Participant
    Master

    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)

    Advanced-Trend-Trader.itf USDJPY.jpg USDJPY.jpg USCrude.jpg USCrude.jpg
    #78610 quote
    juanj
    Participant
    Master

    So 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.

    #88662 quote
    juanj
    Participant
    Master

    So 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.

    USCrude-4H.jpg USCrude-4H.jpg USDJPY-4H.jpg USDJPY-4H.jpg
    #88680 quote
    Nicolas
    Keymaster
    Master

    @juanj

    Thanks 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.

    #88715 quote
    juanj
    Participant
    Master

    Thanks, Nicolas, I appreciate the kind words, the automated PRT version of this strategy would not have been possible without your help

    #88732 quote
    Mags67
    Participant
    Average

    Dear 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

    #88741 quote
    juanj
    Participant
    Master

    Hi Mags, my apologies. We decided to log separate requests for each of the indicators:

    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)
    #88836 quote
    Mags67
    Participant
    Average

    Great, thanks a lot!

    #88848 quote
    Mags67
    Participant
    Average

    Hi 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!

Viewing 15 posts - 16 through 30 (of 31 total)
  • You must be logged in to reply to this topic.

Need help to automate these MQL5 Indicators


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
juanj @juanj Participant
Summary

This topic contains 30 replies,
has 5 voices, and was last updated by Holy Grail
7 years ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/14/2018
Status: Active
Attachments: 12 files
Logo Logo
Loading...