Examples: Features of Experts Advisors

 

New article Features of Experts Advisors has been published:

Creation of expert advisors in the MetaTrader trading system has a number of features.

Author: MetaQuotes Software Corp.

 
//+------------------------------------------------------------------+
//|                                       GoldminerAbsoluteEntry.mq4 |
//|                                             Copyright © 2009, Me |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Me"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Yellow

extern string Remark1 = "-- Goldminer1 Settings --";
extern int RISK = 4;
extern int VerifyShift = 1;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,234);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,233);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   //+------------------------------------------------------------------+
   //| Goldminer Begin                                                  |
   //+------------------------------------------------------------------+

   double GN1,GN2;
   string GoldMiner;

   for(int a=0;a<Bars;a++){//For Loop
   GN1=iCustom(0,0,"goldminer1",RISK,Bars,0,a+VerifyShift);
   GN2=iCustom(0,0,"goldminer1",RISK,Bars,1,a+VerifyShift);

   if(GN2>GN1){GoldMiner="Up";
      ExtMapBuffer2[a]=Low[a];}
   else if(GN1>GN2){GoldMiner="Down";
      ExtMapBuffer1[a]=High[a];}
   else {GoldMiner="None";}

   }//End Of For Loop

   //+---------------------------------------------------------------+
   return(0);
  }
//+------------------------------------------------------------------+
 
Sumit Dutta:
any one help i want my indicator alart up when back singel candel is green or alart down when back sigel candel is reed filter signal
 
//+------------------------------------------------------------------+
//|                                       GoldminerAbsoluteEntry.mq4 |
//|                                             Copyright © 2009, Me |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Me"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Yellow

extern string Remark1 = "-- Goldminer1 Settings --";
extern int RISK = 4;
extern int VerifyShift = 1;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
    //---- indicators
    SetIndexStyle(0, DRAW_ARROW);
    SetIndexArrow(0, 234);
    SetIndexBuffer(0, ExtMapBuffer1);
    SetIndexEmptyValue(0, 0.0);
    SetIndexStyle(1, DRAW_ARROW);
    SetIndexArrow(1, 233);
    SetIndexBuffer(1, ExtMapBuffer2);
    SetIndexEmptyValue(1, 0.0);
    //----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    //+------------------------------------------------------------------+
    //| Goldminer Begin                                                  |
    //+------------------------------------------------------------------+

    double GN1, GN2;
    string GoldMiner;

    // Ensure there are enough bars
    if (Bars <= VerifyShift) return(0);

    int counted_bars = IndicatorCounted();
    int limit = Bars - counted_bars;

    // Clear buffers
    ArraySetAsSeries(ExtMapBuffer1, true);
    ArraySetAsSeries(ExtMapBuffer2, true);

    for (int a = limit - 1; a >= 0; a--)
    {
        GN1 = iCustom(NULL, 0, "goldminer1", RISK, Bars, 0, a + VerifyShift);
        GN2 = iCustom(NULL, 0, "goldminer1", RISK, Bars, 1, a + VerifyShift);

        if (GN2 > GN1)
        {
            GoldMiner = "Up";
            ExtMapBuffer2[a] = Low[a];
            // Check if previous candle is green (bullish)
            if (Close[1] > Open[1])
            {
                Alert("GoldMiner Up signal with previous candle green.");
            }
        }
        else if (GN1 > GN2)
        {
            GoldMiner = "Down";
            ExtMapBuffer1[a] = High[a];
            // Check if previous candle is red (bearish)
            if (Close[1] < Open[1])
            {
                Alert("GoldMiner Down signal with previous candle red.");
            }
        }
        else
        {
            GoldMiner = "None";
        }
    }

    //+---------------------------------------------------------------+
    return(0);
  }
//+------------------------------------------------------------------+