Download MetaTrader 5

Indictor alert multiple currency pairs and timeframes

To add comments, please log in or register
greenpar
38
greenpar  

I'm trying to build an indicator that will alert me when a candle reaches a set size across multiple currency pairs and timeframes. I managed to get it working across two timeframes on one currency pair but have since modified it (see code below). I have searched the forum and managed to get some guidance but was hoping to get some further assistance/direction.

I've highlighted some code at the top of the indicator that covers the timeframes and currency pairs. Further along in the indictor I've highlighted some more code, "currencyPairs[],timeFrame[]", which replaced "Symbol(),Period()" (multiple times) in the one currency pair/two timeframe working version of this indicator.

In time I'm hoping to add further indictors (such as ADX) to this indictor.

Thank you for your help.


#property link          "https://www.mql5.com/en/code/14388"
#property description   "Indicator alerts when candle size is larger than CandlePoint value for specified period"
#property strict

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0


//+------------------------------------------------+
//| Declaring Constants                            |
//+------------------------------------------------+
#define RESET 0                 // Constant for returning to the terminal the command to recalculate the indicator

//+------------------------------------------------+ 
//| Enumeration for the indication of operation        |
//+------------------------------------------------+ 
enum START_POINT // Constant Type
{
OPEN_CLOSE,             // Price move from open to close
HIGH_LOW                // Candle size from low to high
};

//+------------------------------------------------+
//| Input parameters of the indicator                   |
//+------------------------------------------------+ 
input uint CandlePointM1 = 50;                  // Minimum candle points for Period M1
input uint CandlePointM5 = 100;                 // Minimum candle points for Period M5
input START_POINT SP = HIGH_LOW;                // Movement option
int timeFrameNumber = 3;
int timeFrame = {1,5,60};
string timeFrame[] = {"M1", "M5", "H1"};
string currencyPairs[] = {"AUDCAD", "AUDNZD", "AUDJPY"}

//+------------------------------------------------------------------+    
//| Custom indicator initialisation function                         | 
//+------------------------------------------------------------------+  
int OnInit()
{
return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+    
//| Deinitialisation                         | 
//+------------------------------------------------------------------+  
void OnDeinit(const int reason)
{
}

//+------------------------------------------------------------------+  
//| Custom iteration function                                        | 
//+------------------------------------------------------------------+  
int OnCalculate(const int rates_total,  // The amount of history in bars on the current tick
const int prev_calculated,                              // The amount of history in bars on the previous tick
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[])

{
//--- Checking the number of bars for sufficiency for calculating
if(Bars(currencyPairs[],timeFrame[])<1) return(RESET);
//--- Indexing of elements in arrays as in timeseries
ArraySetAsSeries(time,true);
int range;
static datetime alert_bar = 0; // used for one alert/bar
static datetime lasttime,itime;
datetime iTime[1];
//--- Copy newly appeared data into arrays
if(SP==HIGH_LOW)
        {
        double iLow[1],iHigh[1];
        if(CopyLow(currencyPairs[],timeFrame[],time[0],1,iLow)<=0) return(RESET);
        if(CopyHigh(currencyPairs[],timeFrame[],time[0],1,iHigh)<=0) return(RESET);
        range=int((iHigh[0]-iLow[0])/_Point);
        }
        else
        {
        double iOpen[1],iClose[1];
        if(CopyOpen(currencyPairs[],timeFrame[],time[0],1,iOpen)<=0) return(RESET);
        if(CopyClose(currencyPairs[],timeFrame[],time[0],1,iClose)<=0) return(RESET);
        range=int((MathAbs(iClose[0]-iOpen[0]))/_Point);
        }
        if(CopyTime(currencyPairs[],timeFrame[],time[0],1,iTime)<=0) return(RESET);
        if(iTime[0]!=itime)
        {
        lasttime=NULL;
        itime=iTime[0];
        }
        if(alert_bar != Time[0])
                {
                if(Period()==PERIOD_M1)
                        if(range>int(CandlePointM1))
                        {
                        Alert("",currencyPairs[]," ",timeFrame[]," candle > ",CandlePointM1," points");
                        alert_bar = Time[0];
                        }
                if(Period()==PERIOD_M5)
                        if(range>int(CandlePointM5))
                        {
                        Alert("",currencyPairs[]," ",timeFrame[]," candle > ",CandlePointM5," points");
                        alert_bar = Time[0];
                        }
                }
return(rates_total);
}
Naguisa Unada
118
Naguisa Unada  
 int timeFrameNumber = 3 ;
 //int timeFrame = {1,5,60}; 
 //string timeFrame[] = {"M1", "M5", "H1"}; 
 int timeFrame[] = { PERIOD_M1 , PERIOD_M5 , PERIOD_H1 };
 string currencyPairs[] = { "AUDCAD" , "AUDNZD" , "AUDJPY" }
 //if(CopyLow(currencyPairs[],timeFrame[],time[0],1,iLow)<=0) return(RESET); 
 if ( CopyLow (currencyPairs[ 0 ], timeFrame[ 1 ], time[ 0 ], 1 , iLow ) <= 0 ) return (RESET);

1. In this case, currencyPairs [0] = "AUDCAD", timeFrame [1] = PERIOD_M5.

2. Since iLow, iHigh, iOpen, iClose, iTime are reserved words in MQL 4 language, they can not be used as variables.

3. I think that it is better to use iLow than to use CopyLow.

 double price_low = iLow (currencyPairs[ 0 ], timeFrame[ 1 ], 0 );
greenpar
38
greenpar  
Naguisa Unada:

1. In this case, currencyPairs [0] = "AUDCAD", timeFrame [1] = PERIOD_M5.

2. Since iLow, iHigh, iOpen, iClose, iTime are reserved words in MQL 4 language, they can not be used as variables.

3. I think that it is better to use iLow than to use CopyLow.


Thank you for your help. I incorporated the changes you suggested but couldn't get it to work across multiple timeframes and currency pairs. I'll post over in the 'Multi Timeframe Indicators' thread and see if they can help me there.

To add comments, please log in or register