Conversion of indicator ADX(14) from the Metatrader4 trading software

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #129280 quote
    highschool2005
    Participant
    New

    Hi everyone,

    I’m looking to add the DM+ and DM- with period 14 on close from Metatrader 4 to PRT. I found the ADX(14) on PRT but for some reasons, the indicator is different from the one on MT4. I would like someone to help me with the coding. They are almost the time so I’m sure it’s something small that must be tweaked but I have no idea what precisely. The most important to me is that both line cross each other at the same time.

    Capture-d’écran-2020-05-01-à-18.54.01.png Capture-d’écran-2020-05-01-à-18.54.01.png Capture-d’écran-2020-05-01-à-19.01.56.png Capture-d’écran-2020-05-01-à-19.01.56.png Capture-d’écran-2020-05-01-à-19.01.38.png Capture-d’écran-2020-05-01-à-19.01.38.png Capture-d’écran-2020-05-01-à-18.54.44.png Capture-d’écran-2020-05-01-à-18.54.44.png
    #129295 quote
    Vonasi
    Moderator
    Master

    It is most likely because the data it is applied to is different. If you are with IG then they have different candles to your MT4 feed. For example IG have six candle weeks on their daily charts as they have Sunday candles.

    What you put in effects what you get out! 🙂

    #129345 quote
    highschool2005
    Participant
    New

    Thank you Vonasi for your reply. I am in fact looking at data from Tradersway on MT4 and data from Interactive Broker on PRT. So it makes sense that the graph is different. However I find it suspicious that my DM+ and DM- curves have such stronger movements on MT4 and are so much flater on PRT. As far as I know, it’s not possible to import data from Interactive Broker into MT4 or import data from Tradersway into PRT: this was an idea to doublecheck your hypothesis.

    I will show you one area for example that’s very different to me compared to the chandeliers’ movements (there is one hour difference between both broker).

    Capture-d’écran-2020-05-02-à-10.32.52.png Capture-d’écran-2020-05-02-à-10.32.52.png Capture-d’écran-2020-05-02-à-10.32.29.png Capture-d’écran-2020-05-02-à-10.32.29.png
    #129386 quote
    Nicolas
    Keymaster
    Master

    Please post here the ADX mq4 code you are using, in order to check the calculation (as an attached file).

    #129413 quote
    highschool2005
    Participant
    New

    I found a similar indicator online with the same results in MQ4.

    //+------------------------------------------------------------------+
    //| average-directional-index.mq4 |
    //| ©2011 Best-metatrader-indicators.com. All rights reserved |
    //| http://www.best-metatrader-indicators.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright © 2011 Best-metatrader-indicators.com."
    #property link "http://www.best-metatrader-indicators.com"
    
    #property indicator_separate_window
    #property indicator_buffers 3
    #property indicator_color1 DodgerBlue
    #property indicator_color2 Tomato
    #property indicator_color3 Gold
    //---- input parameters
    extern int ADXPeriod=14;
    //---- buffers
    double ADXBuffer[];
    double PlusDiBuffer[];
    double MinusDiBuffer[];
    double PlusSdiBuffer[];
    double MinusSdiBuffer[];
    double TempBuffer[];
    string Copyright="\xA9 WWW.BEST-METATRADER-INDICATORS.COM";
    string MPrefix="FI";
    //+------------------------------------------------------------------+
    //| Custom indicator initialization function |
    //+------------------------------------------------------------------+
    int init()
    {
    //---- 3 additional buffers are used for counting.
    IndicatorBuffers(6);
    //---- indicator buffers
    SetIndexBuffer(0,ADXBuffer);
    SetIndexBuffer(1,PlusDiBuffer);
    SetIndexBuffer(2,MinusDiBuffer);
    SetIndexBuffer(3,PlusSdiBuffer);
    SetIndexBuffer(4,MinusSdiBuffer);
    SetIndexBuffer(5,TempBuffer);
    //---- name for DataWindow and indicator subwindow label
    IndicatorShortName("ADX("+ADXPeriod+")");
    SetIndexLabel(0,"ADX");
    SetIndexLabel(1,"+DI");
    SetIndexLabel(2,"-DI");
    //----
    SetIndexDrawBegin(0,ADXPeriod);
    SetIndexDrawBegin(1,ADXPeriod);
    SetIndexDrawBegin(2,ADXPeriod);
    //----
    DL("001", Copyright, 5, 20,Gold,"Arial",10,0);
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Custor indicator deinitialization function |
    //+------------------------------------------------------------------+
    int deinit()
    {
    //----
    ClearObjects();
    return(0);
    }
    //+------------------------------------------------------------------+
    //| Custom indicator iteration function |
    //+------------------------------------------------------------------+
    int start()
    {
    double pdm,mdm,tr;
    double price_high,price_low;
    int starti,i,counted_bars=IndicatorCounted();
    //----
    i=Bars-2;
    PlusSdiBuffer[i+1]=0;
    MinusSdiBuffer[i+1]=0;
    if(counted_bars>=i) i=Bars-counted_bars-1;
    starti=i;
    //----
    while(i>=0)
    {
    price_low=Low[i];
    price_high=High[i];
    //----
    pdm=price_high-High[i+1];
    mdm=Low[i+1]-price_low;
    if(pdm<0) pdm=0; // +DM
    if(mdm<0) mdm=0; // -DM
    if(pdm==mdm) { pdm=0; mdm=0; }
    else if(pdm<mdm) pdm=0;
    else if(mdm<pdm) mdm=0; //---- double num1=MathAbs(price_high-price_low); double num2=MathAbs(price_high-Close[i+1]); double num3=MathAbs(price_low-Close[i+1]); tr=MathMax(num1,num2); tr=MathMax(tr,num3); //---- counting plus/minus direction if(tr==0) { PlusSdiBuffer[i]=0; MinusSdiBuffer[i]=0; } else { PlusSdiBuffer[i]=100.0*pdm/tr; MinusSdiBuffer[i]=100.0*mdm/tr; } //---- i--; } //---- last counted bar will be recounted if(counted_bars>0) counted_bars--;
    int limit=Bars-counted_bars;
    //---- apply EMA to +DI
    for(i=0; i<=limit; i++)
    PlusDiBuffer[i]=iMAOnArray(PlusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
    //---- apply EMA to -DI
    for(i=0; i<=limit; i++) MinusDiBuffer[i]=iMAOnArray(MinusSdiBuffer,Bars,ADXPeriod,0,MODE_EMA,i); //---- Directional Movement (DX) i=Bars-2; TempBuffer[i+1]=0; i=starti; while(i>=0)
    {
    double div=MathAbs(PlusDiBuffer[i]+MinusDiBuffer[i]);
    if(div==0.00) TempBuffer[i]=0;
    else TempBuffer[i]=100*(MathAbs(PlusDiBuffer[i]-MinusDiBuffer[i])/div);
    i--;
    }
    //---- ADX is exponential moving average on DX
    for(i=0; i<limit; i++)
    ADXBuffer[i]=iMAOnArray(TempBuffer,Bars,ADXPeriod,0,MODE_EMA,i);
    //----
    return(0);
    }
    //+------------------------------------------------------------------+
    //| DL function |
    //+------------------------------------------------------------------+
    void DL(string label, string text, int x, int y, color clr, string FontName = "Arial",int FontSize = 12, int typeCorner = 1)
    
    {
    string labelIndicator = MPrefix + label;
    if (ObjectFind(labelIndicator) == -1)
    {
    ObjectCreate(labelIndicator, OBJ_LABEL, 0, 0, 0);
    }
    
    ObjectSet(labelIndicator, OBJPROP_CORNER, typeCorner);
    ObjectSet(labelIndicator, OBJPROP_XDISTANCE, x);
    ObjectSet(labelIndicator, OBJPROP_YDISTANCE, y);
    ObjectSetText(labelIndicator, text, FontSize, FontName, clr);
    
    }
    
    //+------------------------------------------------------------------+
    //| ClearObjects function |
    //+------------------------------------------------------------------+
    void ClearObjects()
    {
    for(int i=0;i<ObjectsTotal();i++)
    if(StringFind(ObjectName(i),MPrefix)==0) { ObjectDelete(ObjectName(i)); i--; }
    }
    //+------------------------------------------------------------------+

     

    `

    average-directional-index.zip Capture-d’écran-2020-05-02-à-15.02.47.png Capture-d’écran-2020-05-02-à-15.02.47.png
    #129968 quote
    highschool2005
    Participant
    New

    Hi everyone! Have you had time to check this code by any chance? Would like to get your opinion…

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Conversion of indicator ADX(14) from the Metatrader4 trading software


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by highschool2005
5 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 05/01/2020
Status: Active
Attachments: 8 files
Logo Logo
Loading...