How do I make multi time frame and multi currency pair scanner with alert for mt4 indicator

 

Hello,

I am new to Meta trader 4 programing . I have this moving average indicator that display Blue (buy) and  Red(sell) when certain conditions are met.

At the moment it works on just the current chart time frame.  I have  been difficulty  trying to make it scan multiple currency pairs accross multiple  time frame so as to save time finding pairs that meet condition of the inidcator.

It is to say which code will I need to add to current indicator code  so that ones the indicator is loaded in a single chart it will scan multiple time frames using the  list of currency pairs (major and minor) available in the Market Watch window or using preset currency pair input. Ones the indicator detects a currency pair, it will alert it in a dash board .

Please if you have any idea kindly share. Thank yo

Please code below:

-------------------------------------------------------------------------------------------------------------------------------------

//+------------------------------------------------------------------+

//|                             Indicator: Double Ma above_cross.mq4 |

//|                                                                  |

//|                                                                  |

//+------------------------------------------------------------------+



#include <stdlib.mqh>

#include <stderror.mqh>



//--- indicator settings

#property indicator_separate_window

#property indicator_buffers 2



#property indicator_type1 DRAW_ARROW

#property indicator_width1 2

#property indicator_color1 Blue

#property indicator_label1 "Buy"



#property indicator_type2 DRAW_ARROW

#property indicator_width2 2

#property indicator_color2 Red

#property indicator_label2 "Sell"



//--- indicator buffers

double Buffer1[];

double Buffer2[];



extern int EMA1 = 5;

extern int EMA2 = 20;

extern int EMA_Bar_Shift_5 = 0;

extern int EMA_Bar_Shift_20 = 0;

double myPoint; //initialized in OnInit



void myAlert(string type, string message)

  {

   if(type == "print")

      Print(message);

   else if(type == "error")

     {

      Print(type+" | Double Ma cross @ "+Symbol()+","+IntegerToString(Period())+" | "+message);

     }

   else if(type == "order")

     {

     }

   else if(type == "modify")

     {

     }

  }



//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {   

   IndicatorBuffers(2);

   SetIndexBuffer(0, Buffer1);

   SetIndexEmptyValue(0, 0);

   SetIndexArrow(0, 241);

   SetIndexBuffer(1, Buffer2);

   SetIndexEmptyValue(1, 0);

   SetIndexArrow(1, 242);

   //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);

   //--- initial zero

   if(prev_calculated < 1)

     {

      ArrayInitialize(Buffer1, 0);

      ArrayInitialize(Buffer2, 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, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i) > iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i)

      && iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+1) < iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+1) //Moving Average crosses above Moving Average

      )||(iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+1) > iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+1)

      && iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+2) < iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+2) //Moving Average crosses above Moving Average

      )

      )

        {

         Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range

        }

      else

        {

         Buffer1[i] = 0;

        }

      //Indicator Buffer 2

      if((iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i) < iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i)

      && iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+1) > iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+1) //Moving Average crosses below Moving Average

      )||(iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+1) < iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+1)

      && iMA(NULL, PERIOD_CURRENT, EMA1, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_5+i+2) > iMA(NULL, PERIOD_CURRENT, EMA2, 0, MODE_EMA, PRICE_CLOSE, EMA_Bar_Shift_20+i+2) //Moving Average crosses below Moving Average

      )

      )

        {

         Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range

        }

      else

        {

         Buffer2[i] = 0;

        }

     }

   return(rates_total);

  }

//+------------------------------------------------------------------+
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks, as a small error in the expert or indicator logic can cause losses on the trading account. That is why we have developed a series of basic checks to ensure the required quality level of the Market products. If any errors are identified by the Market...
 
I know that it is not obvious, but topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

Please edit your post and use the code button (Alt+S) when pasting code


 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button


 
Elterry: I have  been difficulty  trying to make it scan multiple currency pairs accross multiple  time frame 

-------------------------------------------------------------------------------------------------------------------------------------

  1. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum 2018.05.12

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.

              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4 2019.05.20


Reason: