A practical example of connecting an indicator from the “MQL5 Market” to your EA
Quite often, users ask how to integrate an indicator purchased on the Market into their trading advisors. It’s time to provide a simple, reliable and feature-rich solution. The connection example is as simple as possible, it will allow even a novice programmer to figure it out.
This is an included class file for connecting the indicator. You need to put it in the “Include” folder of your terminal.
class i_FourAverage { public: int Handle1; bool FirstStart; double Buffer1[]; bool Signal; bool DownloadsIndicator(bool& recalculation, string symbol, ENUM_TIMEFRAMES timeframe, int shift, int preset, int periodFA = 32, int average_1 = 134, int average_2 = 47, int average_3 = 1, int average_4 = 45, int range = 50, int bars = 3); i_FourAverage() { FirstStart = true; Handle1 = -1; } }; bool i_FourAverage::DownloadsIndicator(bool& recalculation, string symbol, ENUM_TIMEFRAMES timeframe, int shift, int preset, int periodFA = 32, int average_1 = 134, int average_2 = 47, int average_3 = 1, int average_4 = 45, int range = 50, int bars = 3) { if(FirstStart) { Handle1 = iCustom(symbol, timeframe, "Market\\FourAverageMT5", preset, "_", periodFA, average_1, average_2, average_3, average_4, range, 0, "_", false, 0, false, 0); FirstStart = false; } Signal = false; int shiftmulti = GetShiftMultiSymbol(symbol, timeframe, shift, false); if(shiftmulti == -1) { recalculation = true; return(false); } string name = "FourAverage"; if(!FillArrayFromBuffer(Handle1, 0, name, shiftmulti, bars, Buffer1, true)) return(false); recalculation = false; return(true); } int GetShiftMultiSymbol(string symbol, ENUM_TIMEFRAMES timeframe, int shift = 1, bool no_search = false) { if(Symbol() == symbol) { return(shift); } else { datetime time_bar1 = iTime(Symbol(), timeframe, shift); int shiftmulti = iBarShift(symbol, timeframe, time_bar1, no_search); return(shiftmulti); } } bool FillArrayFromBuffer ( int indicator_handle, int buffer_num, string name, int start_pos, int count, double &buffer[], bool expand_and_revers = false ) { ResetLastError(); if(expand_and_revers) ArrayResize(buffer, count); if(CopyBuffer(indicator_handle, buffer_num, start_pos, count, buffer) 0) {
An example is getting indicator data in an expert Advisor.
#includestatic i_FourAverage ind_0; input int PeriodFA = 10; input int Average_1 = 112; input int Average_2 = 148; input int Average_3 = 100; input int Average_4 = 146; input int Range = 31; int OnInit() { return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { } void OnTick() { bool recalculate = false; string symbol = Symbol(); if(!ind_0.DownloadsIndicator(recalculate, symbol, PERIOD_CURRENT, 0, 0, PeriodFA, Average_1, Average_2, Average_3, Average_4, Range, 5)) return; if(ind_0.Buffer1[0] > 0) Print("BUY: FA = " + string(ind_0.Buffer1[0])); if(ind_0.Buffer1[0] 0) Print("SELL: FA = " + string(ind_0.Buffer1[0]));
Additional resources and information about the FourAverage indicator