Candlestick Trend, code conversion from MT4

Forums ProRealTime English forum ProBuilder support Candlestick Trend, code conversion from MT4

Viewing 8 posts - 1 through 8 (of 8 total)
  • #85372

    Candlestick bar changes colour to green when the fast moving average crosses over the slow moving average and red when the fast moving averages crosses below the slow moving average. ( MT4 Code Attached ). In the attached it is the 10 period WMA against the 50 WMA.  The value of the MA can be changed according to the trader’s preference.

    Is it possible to code this for use in PureDeal.

    Thanks

     

    Kishore Rochey


    //+——————————————————————+
    //| Indicator: Trend Colored Copy02.mq4 |
    //+——————————————————————+
    #property copyright “Created with EABuilder.com”
    #property link “http://eabuilder.com”
    #property version “1.00”
    #property description “Colored candlesticks showing the trend based on two moving averages and the slope of the slow moving average. For long”
    #property description ” term trends use Period2 = 200.”

    #include <stdlib.mqh>
    #include <stderror.mqh>

    //— indicator settings
    #property indicator_chart_window
    #property indicator_buffers 16

    #property indicator_type1 DRAW_HISTOGRAM
    #property indicator_style1 STYLE_SOLID
    #property indicator_width1 3
    #property indicator_color1 0x00FF00
    #property indicator_label1 “Bullish”

    #property indicator_type2 DRAW_HISTOGRAM
    #property indicator_style2 STYLE_SOLID
    #property indicator_width2 3
    #property indicator_color2 0x00FF00
    #property indicator_label2 “Bullish”

    #property indicator_type3 DRAW_HISTOGRAM
    #property indicator_style3 STYLE_SOLID
    #property indicator_width3 1
    #property indicator_color3 0x00FF00
    #property indicator_label3 “Bullish”

    #property indicator_type4 DRAW_HISTOGRAM
    #property indicator_style4 STYLE_SOLID
    #property indicator_width4 1
    #property indicator_color4 0x00FF00
    #property indicator_label4 “Bullish”

    #property indicator_type5 DRAW_HISTOGRAM
    #property indicator_style5 STYLE_SOLID
    #property indicator_width5 3
    #property indicator_color5 0x008000
    #property indicator_label5 “Bullish Weak”

    #property indicator_type6 DRAW_HISTOGRAM
    #property indicator_style6 STYLE_SOLID
    #property indicator_width6 3
    #property indicator_color6 0x008000
    #property indicator_label6 “Bullish Weak”

    #property indicator_type7 DRAW_HISTOGRAM
    #property indicator_style7 STYLE_SOLID
    #property indicator_width7 1
    #property indicator_color7 0x008000
    #property indicator_label7 “Bullish Weak”

    #property indicator_type8 DRAW_HISTOGRAM
    #property indicator_style8 STYLE_SOLID
    #property indicator_width8 1
    #property indicator_color8 0x008000
    #property indicator_label8 “Bullish Weak”

    #property indicator_type9 DRAW_HISTOGRAM
    #property indicator_style9 STYLE_SOLID
    #property indicator_width9 3
    #property indicator_color9 0x4763FF
    #property indicator_label9 “Bearish Weak”

    #property indicator_type10 DRAW_HISTOGRAM
    #property indicator_style10 STYLE_SOLID
    #property indicator_width10 3
    #property indicator_color10 0x4763FF
    #property indicator_label10 “Bearish Weak”

    #property indicator_type11 DRAW_HISTOGRAM
    #property indicator_style11 STYLE_SOLID
    #property indicator_width11 1
    #property indicator_color11 0x4763FF
    #property indicator_label11 “Bearish Weak”

    #property indicator_type12 DRAW_HISTOGRAM
    #property indicator_style12 STYLE_SOLID
    #property indicator_width12 1
    #property indicator_color12 0x4763FF
    #property indicator_label12 “Bearish Weak”

    #property indicator_type13 DRAW_HISTOGRAM
    #property indicator_style13 STYLE_SOLID
    #property indicator_width13 3
    #property indicator_color13 0x0000FF
    #property indicator_label13 “Bearish”

    #property indicator_type14 DRAW_HISTOGRAM
    #property indicator_style14 STYLE_SOLID
    #property indicator_width14 3
    #property indicator_color14 0x0000FF
    #property indicator_label14 “Bearish”

    #property indicator_type15 DRAW_HISTOGRAM
    #property indicator_style15 STYLE_SOLID
    #property indicator_width15 1
    #property indicator_color15 0x0000FF
    #property indicator_label15 “Bearish”

    #property indicator_type16 DRAW_HISTOGRAM
    #property indicator_style16 STYLE_SOLID
    #property indicator_width16 1
    #property indicator_color16 0x0000FF
    #property indicator_label16 “Bearish”

    //— indicator buffers
    double Buffer1[];
    double Buffer2[];
    double Buffer3[];
    double Buffer4[];
    double Buffer5[];
    double Buffer6[];
    double Buffer7[];
    double Buffer8[];
    double Buffer9[];
    double Buffer10[];
    double Buffer11[];
    double Buffer12[];
    double Buffer13[];
    double Buffer14[];
    double Buffer15[];
    double Buffer16[];

    extern int Period1 = 3;
    extern int Period2 = 34;
    double myPoint; //initialized in OnInit

    void myAlert(string type, string message)
    {
    if(type == “print”)
    Print(message);
    else if(type == “error”)
    {
    Print(type+” | Trend Colored Copy02 @ “+Symbol()+”,”+Period()+” | “+message);
    }
    else if(type == “order”)
    {
    }
    else if(type == “modify”)
    {
    }
    }

    //+——————————————————————+
    //| Custom indicator initialization function |
    //+——————————————————————+
    int OnInit()
    {
    IndicatorBuffers(16);
    SetIndexBuffer(0, Buffer1);
    SetIndexEmptyValue(0, 0);
    SetIndexBuffer(1, Buffer2);
    SetIndexEmptyValue(1, 0);
    SetIndexBuffer(2, Buffer3);
    SetIndexEmptyValue(2, 0);
    SetIndexBuffer(3, Buffer4);
    SetIndexEmptyValue(3, 0);
    SetIndexBuffer(4, Buffer5);
    SetIndexEmptyValue(4, 0);
    SetIndexBuffer(5, Buffer6);
    SetIndexEmptyValue(5, 0);
    SetIndexBuffer(6, Buffer7);
    SetIndexEmptyValue(6, 0);
    SetIndexBuffer(7, Buffer8);
    SetIndexEmptyValue(7, 0);
    SetIndexBuffer(8, Buffer9);
    SetIndexEmptyValue(8, 0);
    SetIndexBuffer(9, Buffer10);
    SetIndexEmptyValue(9, 0);
    SetIndexBuffer(10, Buffer11);
    SetIndexEmptyValue(10, 0);
    SetIndexBuffer(11, Buffer12);
    SetIndexEmptyValue(11, 0);
    SetIndexBuffer(12, Buffer13);
    SetIndexEmptyValue(12, 0);
    SetIndexBuffer(13, Buffer14);
    SetIndexEmptyValue(13, 0);
    SetIndexBuffer(14, Buffer15);
    SetIndexEmptyValue(14, 0);
    SetIndexBuffer(15, Buffer16);
    SetIndexEmptyValue(15, 0);
    //initialize myPoint
    myPoint = Point();
    if(Digits() == 5 || Digits() == 3)
    {
    myPoint *= 10;
    }
    return(INIT_SUCCEEDED);
    }

    //+——————————————————————+
    //| Custom indicator iteration function |
    //+——————————————————————+
    int OnCalculate(const int rates_total,
    const int prev_calculated,
    const datetime& time[],
    const double& open[],
    const double& high[],
    const double& low[],
    const double& close[],
    const long& tick_volume[],
    const long& volume[],
    const int& spread[])
    {
    int limit = rates_total – prev_calculated;
    //— counting from 0 to rates_total
    ArraySetAsSeries(Buffer1, true);
    ArraySetAsSeries(Buffer2, true);
    ArraySetAsSeries(Buffer3, true);
    ArraySetAsSeries(Buffer4, true);
    ArraySetAsSeries(Buffer5, true);
    ArraySetAsSeries(Buffer6, true);
    ArraySetAsSeries(Buffer7, true);
    ArraySetAsSeries(Buffer8, true);
    ArraySetAsSeries(Buffer9, true);
    ArraySetAsSeries(Buffer10, true);
    ArraySetAsSeries(Buffer11, true);
    ArraySetAsSeries(Buffer12, true);
    ArraySetAsSeries(Buffer13, true);
    ArraySetAsSeries(Buffer14, true);
    ArraySetAsSeries(Buffer15, true);
    ArraySetAsSeries(Buffer16, true);
    //— initial zero
    if(prev_calculated < 1)
    {
    ArrayInitialize(Buffer1, 0);
    ArrayInitialize(Buffer2, 0);
    ArrayInitialize(Buffer3, 0);
    ArrayInitialize(Buffer4, 0);
    ArrayInitialize(Buffer5, 0);
    ArrayInitialize(Buffer6, 0);
    ArrayInitialize(Buffer7, 0);
    ArrayInitialize(Buffer8, 0);
    ArrayInitialize(Buffer9, 0);
    ArrayInitialize(Buffer10, 0);
    ArrayInitialize(Buffer11, 0);
    ArrayInitialize(Buffer12, 0);
    ArrayInitialize(Buffer13, 0);
    ArrayInitialize(Buffer14, 0);
    ArrayInitialize(Buffer15, 0);
    ArrayInitialize(Buffer16, 0);
    }
    else
    limit++;

    //— main loop
    for(int i = limit-1; i >= 0; i–)
    {
    if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent “Array out of range” or slow calculation
    //Indicator Buffer 1
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer1[i] = Open[i]; //Set indicator value at Candlestick Open
    }
    else
    {
    Buffer1[i] = 0;
    }
    //Indicator Buffer 2
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer2[i] = Close[i]; //Set indicator value at Candlestick Close
    }
    else
    {
    Buffer2[i] = 0;
    }
    //Indicator Buffer 3
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer3[i] = High[i]; //Set indicator value at Candlestick High
    }
    else
    {
    Buffer3[i] = 0;
    }
    //Indicator Buffer 4
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer4[i] = Low[i]; //Set indicator value at Candlestick Low
    }
    else
    {
    Buffer4[i] = 0;
    }
    //Indicator Buffer 5
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer5[i] = Open[i]; //Set indicator value at Candlestick Open
    }
    else
    {
    Buffer5[i] = 0;
    }
    //Indicator Buffer 6
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer6[i] = Close[i]; //Set indicator value at Candlestick Close
    }
    else
    {
    Buffer6[i] = 0;
    }
    //Indicator Buffer 7
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer7[i] = High[i]; //Set indicator value at Candlestick High
    }
    else
    {
    Buffer7[i] = 0;
    }
    //Indicator Buffer 8
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average > Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer8[i] = Low[i]; //Set indicator value at Candlestick Low
    }
    else
    {
    Buffer8[i] = 0;
    }
    //Indicator Buffer 9
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer9[i] = Open[i]; //Set indicator value at Candlestick Open
    }
    else
    {
    Buffer9[i] = 0;
    }
    //Indicator Buffer 10
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer10[i] = Close[i]; //Set indicator value at Candlestick Close
    }
    else
    {
    Buffer10[i] = 0;
    }
    //Indicator Buffer 11
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer11[i] = High[i]; //Set indicator value at Candlestick High
    }
    else
    {
    Buffer11[i] = 0;
    }
    //Indicator Buffer 12
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) > iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average > Moving Average
    )
    {
    Buffer12[i] = Low[i]; //Set indicator value at Candlestick Low
    }
    else
    {
    Buffer12[i] = 0;
    }
    //Indicator Buffer 13
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer13[i] = Open[i]; //Set indicator value at Candlestick Open
    }
    else
    {
    Buffer13[i] = 0;
    }
    //Indicator Buffer 14
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer14[i] = Close[i]; //Set indicator value at Candlestick Close
    }
    else
    {
    Buffer14[i] = 0;
    }
    //Indicator Buffer 15
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer15[i] = High[i]; //Set indicator value at Candlestick High
    }
    else
    {
    Buffer15[i] = 0;
    }
    //Indicator Buffer 16
    if(iMA(NULL, PERIOD_CURRENT, Period1, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) //Moving Average < Moving Average
    && iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, Period2, 0, MODE_SMA, PRICE_CLOSE, 1+i) //Moving Average < Moving Average
    )
    {
    Buffer16[i] = Low[i]; //Set indicator value at Candlestick Low
    }
    else
    {
    Buffer16[i] = 0;
    }
    }
    return(rates_total);
    }
    //+——————————————————————+

    #85386

    Hi, thanks for the proper request formatting of your post. We not provide support for IG PureDeal (and I’m not sure it is possible to do custom coding for it). Our website is dedicated to ProRealTime programming, do you want it to be converted for this platform?

    #85393

    Hello. Thank You for the quick response.

    Yes. Could you convert this for me in ProRealTime programming. I would appreciate that.

     

    regards

     

    Kishore

    #85394

    Ok, could you please attach the .mq4 file in your next post, easier for me to work on than full text. Thanks.

    #85413

    Please see the attachments.

     

    Thanks

     

    Kishore

    #85426

    You can find the indicator to download in our library: MA trend colored

     

     

    1 user thanked author for this post.
    #85623

    Thank You for everything. I noticed that the Moving Average in the code is written as

    MA1 = 2

    MA2 = 2

     

    The number 2 would represent the type of moving average ? 2 would mean Weight Average. What if a trader wanted to choose either Simple, Exponential or Weight ?

    Would you be able to add a box in the window for this ?

    #85749

    Every parameters are already in the settings box, download the .itf file and import it.

    It is not possible to define external variables with the code, they are added manually in the platform, so to get the ones I made, you need to import the file I added in the post.

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login