How to create a custom forex indicator for MT4

//

Keith

In this post, I am going to show you How to create a custom forex indicator for MT4. But if you learn how to, please note that the code below is given for educational purposes and if you want to to use it for commercial/ selling, you need to attribute the source. The code is licensed under creatives common…. Simply add https://keithrainz.me/ when giving it out.

We are going to create a Belly System simple indicator

This is part 1 of coding an indicator like belly system. For part 2, simply like the video, comment part 2, subscribe to my channel and share the video. will release part 2 when the video below gets 1k views.

Requirements to create a custom forex indicator for MT4

  • You will need MT4 installed
  • An internet connection.

How to create a custom forex indicator for MT4?

Watch the video below and get the error-free well coded source code.

//---- File Properties
#property copyright   "Keith Rainz"
#property link        "https://keithrainz.me/how-to-create-a-custom-forex-indicator-for-mt4/"
#property description "belly system-like indicator that plots breakout arrows."
#property version     "1.0"
#property strict
//---- Indicator drawing and buffers
#property indicator_chart_window
#property indicator_buffers 2
//---- Colors and sizes for buffers
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrTomato
#property indicator_width1 2
#property indicator_width2 2
//---- Buffer Arrays
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------
//| Custom indicator initialization function 
//+------------------------------------------
int init()
{
    // First buffer
    SetIndexBuffer(0, ExtMapBuffer1);  // Assign buffer array
    SetIndexStyle(0, DRAW_ARROW);      // Style to arrow
    SetIndexArrow(0, 233);             // Arrow code
    
    //Second buffer
    SetIndexBuffer(1, ExtMapBuffer2);  // Assign buffer array          
    SetIndexStyle(1, DRAW_ARROW);      // Style to arrow
    SetIndexArrow(1, 234);             // Arrow code
    
    // Exit
    return(0);
}
  
//+-------------------------------------
//| 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[])
{
    // Start and limit
    int start = 1;
    int limit;
    
    // Bars counted so far
    int counted_bars = IndicatorCounted();
    // No more bars?
    if(counted_bars < 0) 
        return(-1);
    // Do not check repeated bars
    limit = Bars - 1 - counted_bars;
    
    // Iterate bars from past to present
    for(int i = limit; i >= start; i--)
    {
      // If not enough data...
      if(i > Bars-2) continue;
      
      // Check buy signal
      if(Close[i] > High[i+1])
      {
         ExtMapBuffer1[i] = Low[i];
      }
      
      // Sell check signal
      if(Close[i] < Low[i+1])
      {
         ExtMapBuffer2[i] = High[i];
      }
    }
    
    // Exit
    return(rates_total);
}
how to create a forex indicator

Leave a Comment

Keith Rainz

Contact me

Along Kafue Road, Chilanga, Lusaka Zambia.

Contact me

Connect with me