Hi everyone I am writing an MT5 multi-currency EA that uses several indicators.
Rather than create Handles and Arrays for each Indicator/Currency I created functions to easily get the values for each indicator that I use in the OnTick on every new candle. It takes however rather long to calculate. Can anyone suggest an alternative? Thank you
The functions
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+ double Ma_Function(
string symbol, // symbol name ENUM_TIMEFRAMES period, // period int ma_period, // averaging period int ma_shift, // horizontal shift ENUM_MA_METHOD ma_method, // smoothing type ENUM_APPLIED_PRICE applied_price, // applied price int buffernumber=0, //buffer numberint shift=0//shift
)
{
double valueArray[];
ArraySetAsSeries(valueArray,true);
int Handle=iMA(symbol,period,ma_period,ma_shift,ma_method,applied_price);
CopyBuffer(Handle,buffernumber,shift,1,valueArray);
double value=valueArray[0];
return value;
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+ double MACD_Function(
string symbol, // symbol name ENUM_TIMEFRAMES period, // period int fast_ema_period, // period for Fast average calculation int slow_ema_period, // period for Slow average calculation int signal_period, // period for their difference averaging ENUM_APPLIED_PRICE applied_price, // type of price or handle int buffernumber=0, //buffer numberint shift=0//shift
)
{
double valueArray[];
ArraySetAsSeries(valueArray,true);
int Handle=iMACD(symbol,period,fast_ema_period, slow_ema_period,signal_period,applied_price);
CopyBuffer(Handle,buffernumber,shift,1,valueArray);
double value=valueArray[0];
return value;
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+ double RSI_Function(
string symbol, // symbol name ENUM_TIMEFRAMES period, // period int ma_period, // period for Fast average calculation ENUM_APPLIED_PRICE applied_price, // type of price or handle int buffernumber=0, //buffer numberint shift=0//shift
)
{
double valueArray[];
ArraySetAsSeries(valueArray,true);
int Handle=iRSI(symbol,period,ma_period,applied_price);
CopyBuffer(Handle,buffernumber,shift,1,valueArray);
double value=valueArray[0];
return value;
}
And I use the functions in the OnTick of the code on every new bar to get the values
There are two ways to create an indicator handle for further accessing to its values. The first way is to directly specify a function name from the list of technical indicators. The second method using the IndicatorCreate() is to uniformly create a handle of any indicator by assigning an identifier from the ENUM_INDICATOR...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi everyone
I am writing an MT5 multi-currency EA that uses several indicators.
Rather than create Handles and Arrays for each Indicator/Currency I created functions to easily get the values for each indicator that I use in the OnTick on every new candle.
It takes however rather long to calculate.
Can anyone suggest an alternative?
Thank you
The functions
And I use the functions in the OnTick of the code on every new bar to get the values