Hello,
I have built an multiTimeframe and MultiSymbol EA. For example, i am using Moving Average, it create handle for all the selected symbols and timeframe.
1. Sometime Due to Moving Average full EA get stuck
2. Sometime CopyBuffer get failed and return 0 (for all indicators)
3. When i deinit and init again by changing Timeframe my EA getting stuck (Until i close and reopen metatrader again).
My Code :
I have attached full handle EA for multiple indicator (In-case if you needed for reference), Kindly check the attachment.
Please Help me optimism and fix the code.
Traders and coders are working for free:
- if it is interesting for them personally, or
- if it is interesting for many members on this forum.
Freelance section of the forum should be used in most of the cases.
- 2026.02.14
- www.mql5.com
Traders and coders are working for free:
- if it is interesting for them personally, or
- if it is interesting for many members on this forum.
Thanks for remaindering me again. I know and i am not asking as Job but as request and i can wait for someone to answer. :)
Yes i know and i use it a lot too. I converted my 5 EA MQL4 to MQL5 through paid freelancer only. this small work does not requires freelancer as per my requirement as i want to do it myself so i can learn more about MQL5.
Hello,
Nothing is wrong with MA itself. The problem is how MT5 loads history synchronizes series and calculates indicators when you request hundreds of handles at once.
Count your EA creates
Symbols
timeframes
MAs handless
mt5 indicator engine is single thread/sym series. So, u create a queue of hundreds of calculation that's why your ma freezes whole EA
Try
// Global or better — member of class struct MAKey { string symbol; ENUM_TIMEFRAMES tf; int period; int ma_shift; ENUM_MA_METHOD method; ENUM_APPLIED_PRICE price; }; MAKey keys[]; int handles[]; // parallel array // Fast lookup helper (linear search is OK for <500 items) int FindHandleIndex(const string sy, ENUM_TIMEFRAMES tf, int per, int mshift, ENUM_MA_METHOD meth, ENUM_APPLIED_PRICE pr) { for(int i = 0; i < ArraySize(keys); i++) { if(keys[i].symbol == sy && keys[i].tf == tf && keys[i].period == per && keys[i].ma_shift == mshift && keys[i].method == meth && keys[i].price == pr) return i; } return -1; } // ──────────────────────────────────────────────── int GetOrCreateMAHandle(string sy, ENUM_TIMEFRAMES tf, int period, int ma_shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price) { int idx = FindHandleIndex(sy, tf, period, ma_shift, method, price); if(idx >= 0) return handles[idx]; // Safety minimal checks if(!SymbolSelect(sy, true)) { Print("SymbolSelect failed: ", sy); return INVALID_HANDLE; } if(Bars(sy, tf) < period + 10) { Print("Not enough bars: ", sy, " ", EnumToString(tf)); return INVALID_HANDLE; } int h = iMA(sy, tf, period, ma_shift, method, price); if(h == INVALID_HANDLE) { Print("iMA failed: ", sy, " ", EnumToString(tf)); return INVALID_HANDLE; } // Store int n = ArraySize(keys); ArrayResize(keys, n+1); ArrayResize(handles,n+1); keys[n].symbol = sy; keys[n].tf = tf; keys[n].period = period; keys[n].ma_shift = ma_shift; keys[n].method = method; keys[n].price = price; handles[n] = h; return h; } // ──────────────────────────────────────────────── // Recommended fMA version (shift=0 means current bar, shift=1 previous completed bar) double fMA(string sy, ENUM_TIMEFRAMES tf, int period, int ma_shift, ENUM_MA_METHOD method, ENUM_APPLIED_PRICE price, int buffer_shift = 1) { int h = GetOrCreateMAHandle(sy, tf, period, ma_shift, method, price); if(h == INVALID_HANDLE) return 0; int calculated = BarsCalculated(h); if(calculated <= buffer_shift) { // Not ready yet (common on first ticks after history load) return 0; } double buf[1]; if(CopyBuffer(h, 0, buffer_shift, 1, buf) != 1) { //Print("CopyBuffer failed ", GetLastError()); return 0; } return buf[0]; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I have built an multiTimeframe and MultiSymbol EA. For example, i am using Moving Average, it create handle for all the selected symbols and timeframe.
1. Sometime Due to Moving Average full EA get stuck
2. Sometime CopyBuffer get failed and return 0 (for all indicators)
3. When i deinit and init again by changing Timeframe my EA getting stuck (Until i close and reopen metatrader again).
My Code :
I have attached full handle EA for multiple indicator (In-case if you needed for reference), Kindly check the attachment.
Please Help me optimism and fix the code.