The OnTick event handler is only called for new tick events of the current chart symbol. It is NOT called for any other symbol.
For multi-symbol, you need to adopt a different approach of event handling, such as using OnTimer() or using custom chart events from specialised indicators for this purpose.
The Implementation of a Multi-currency Mode in MetaTrader 5
Konstantin Gruzdev, 2011.02.18 17:58
For a long time multi-currency analysis and multi-currency trading has been of interest to people. The opportunity to implement a full fledged multi-currency regime became possible only with the public release of MetaTrader 5 and the MQL5 programming language. In this article we propose a way to analyze and process all incoming ticks for several symbols. As an illustration, let's consider a multi-currency RSI indicator of the USDx dollar index.Forum on trading, automated trading systems and testing trading strategies
Multi symbol expert advisor change result depending on symbol selected in backtesting setting
fxsaber, 2023.12.10 19:35
Multi symbol OnTick.Forum on trading, automated trading systems and testing trading strategies
Multi symbol expert advisor change result depending on symbol selected in backtesting setting
fxsaber, 2023.12.14 09:11
You can use this ready-made wrapper to immediately write code without being distracted by the features of the tester.
Sir,
I tried to Void OnTimer () ..
It has 3 Trade in "GBPUSD" symbol (Please see this photo attached) but I want to only one Trade in GPBUSD.
I tested but It has some problem.
Please Solve this code 👇
//+------------------------------------------------------------------+ //| MA_PipStep.mq5 | //| vik20011902@gmail.com| //+------------------------------------------------------------------+ #property link "vik20011902@gmail.com" #property version "1.00" // Moving Average int MA_Handle[]; double MA[]; // Point double point = 0 ; double StopLoss_point[] ; double TakeProfit_point[]; double Ask[]; double Bid[]; double Spread[]; int AmountSymbols = 4; string symbol[] = {"AUDUSD.s", "EURUSD.s", "GBPUSD.s", "USDCAD.s"}; input int MagicNumber = 12345; input int MA_Period = 20; input int MA_Shift = 1; input int TakeProfit = 1000; input int StopLoss = 1000; input int MaxTrade = 3; input int PipStep = 5; input ENUM_TIMEFRAMES Time_Frame = PERIOD_M1; double iclose[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(1); for(int i = 0; i < AmountSymbols; i++) { ArrayResize(MA_Handle, AmountSymbols); MA_Handle[i] = iMA(symbol[i], PERIOD_CURRENT, MA_Period, MA_Shift, MODE_SMA, PRICE_CLOSE); if(MA_Handle[i] == INVALID_HANDLE) { Print("Failed ", symbol[i], " Loading this Indicator "); return (INIT_FAILED); } //Digits int digits = 1; if(Digits() == 3 || Digits() == 5) { digits = 10; point = Point() * digits; } else if(Digits() <= 2 || Digits() == 4) { digits = 10; point = Point() * 1; } ArrayResize(StopLoss_point, AmountSymbols); ArrayResize(TakeProfit_point, AmountSymbols); StopLoss_point[i] = StopLoss * point ; TakeProfit_point[i] = TakeProfit * point ; } //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { for(int s = 0; s < AmountSymbols; s++) { ArrayResize(MA_Handle, AmountSymbols); if(MA_Handle[s] != INVALID_HANDLE) { IndicatorRelease(MA_Handle[s]); } } EventKillTimer(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTimer() { for(int i = 0; i < AmountSymbols; i++) { // Moving Average Buffer ArraySetAsSeries(MA, true); int count = 3; if(!CopyBuffer(MA_Handle[i], 0, 1, count, MA)) { Print("Failed to create Indicator"); } //Bars if(Bars(symbol[i], PERIOD_CURRENT) < 100) { Print("Bars less than 100"); return; } ArrayResize(Spread, AmountSymbols); Spread[i] = (double)SymbolInfoInteger(symbol[i], SYMBOL_SPREAD); Comment("Spread = ", Spread[i]); ArrayResize(Ask, AmountSymbols); ArrayResize(Bid, AmountSymbols); Ask[i] = SymbolInfoDouble(symbol[i], SYMBOL_ASK); Bid[i] = SymbolInfoDouble(symbol[i], SYMBOL_BID); // Maximum Trade int total = 0; for(int i = CalculateAllPositions(symbol[i]) - 1; i >= 0; i--) { ulong Position_Ticket = PositionGetTicket(i); if(PositionSelectByTicket(Position_Ticket)) { string check_Symbol = PositionGetString(POSITION_SYMBOL); if(check_Symbol == symbol[i]) { total++; } if(total > MaxTrade) { return; } } } // New Current Bar if(New_Current_Bar(symbol[i])) { ArrayResize(iclose, AmountSymbols); iclose[i] = iClose(symbol[i], PERIOD_CURRENT, 1); if(CalculateAllPositions(symbol[i]) == 0) { if(MA[0] < Ask[i] && iclose[i] > MA[0]) { // Buy Buy(symbol[i], MagicNumber, Ask[i], StopLoss_point[i], TakeProfit_point[i]); } else if(MA[0] > Bid[i] && iclose[i] < MA[0]) { // Sell Sell(symbol[i], MagicNumber, Bid[i], StopLoss_point[i], TakeProfit_point[i]); } } if(CalculateAllPositions(symbol[i]) >= 1) { Pip_Step(symbol[i], MagicNumber, StopLoss_point[i], TakeProfit_point[i]); } } } } // New Current Bar bool New_Current_Bar(string symbol_name) { static datetime prevTime = 0; datetime lastTime[1]; if(CopyTime(symbol_name, PERIOD_CURRENT, 0, 1, lastTime) == 1 && prevTime != lastTime[0]) { prevTime = lastTime[0]; return true; } return false; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CalculateAllPositions(string symbol_name) { int total = 0; for(int i = PositionsTotal() - 1; i >= 0; i--) { ulong Position_Ticket = PositionGetTicket(i); if(PositionSelectByTicket(Position_Ticket)) { ENUM_POSITION_TYPE Position_Type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); string check_Symbol = PositionGetString(POSITION_SYMBOL); if(check_Symbol == symbol_name) { total++; } } //--- } return(total); } /* void CalculateAllPositions(int &count_buys,int &count_sells) { count_buys = 0; count_sells = 0; for(int i=PositionsTotal()-1; i>=0; i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic) { if(m_position.PositionType()==POSITION_TYPE_BUY) count_buys++; else if(m_position.PositionType()==POSITION_TYPE_SELL) count_sells++; } } */ /* I removed this code because Iam Unabe to send this message forum MQL5 if it says "Message may not exceed 64000 characters" Buy & Sell Trade function */ // PipStep (it doesn't work to 4 Symbol) int Pip_Step(string sparam, int magic_2, double StopLoss_3, double TakeProfit_3) { double Open_Price = 0; bool LastIsBuy = false; int TotalBuy = 0; int TotalSell = 0; double Spread_1 = (double)SymbolInfoInteger(sparam, SYMBOL_SPREAD); double Ask_1 = SymbolInfoDouble(sparam, SYMBOL_ASK); double Bid_1 = SymbolInfoDouble(sparam, SYMBOL_BID); double iclose_1 = iClose(sparam, PERIOD_CURRENT, 1); for(int iCount = CalculateAllPositions(sparam) - 1; iCount >= 0; iCount--) { ulong Position_Ticket = PositionGetTicket(iCount); if(PositionSelectByTicket(Position_Ticket)) { int Position_Type = (int)PositionGetInteger(POSITION_TYPE); string check_Symbol = PositionGetString(POSITION_SYMBOL); long magic = PositionGetInteger(POSITION_MAGIC); double open_price = PositionGetDouble(POSITION_PRICE_OPEN); if(Position_Type == POSITION_TYPE_BUY && check_Symbol == sparam && magic == magic_2) { if(Open_Price == 0) { Open_Price = open_price; } if(Open_Price > open_price) { Open_Price = open_price; } LastIsBuy = true; TotalBuy++; if(TotalBuy == MaxTrade) { Print("Maximum Trade is reached"); return(0); } } if(Position_Type == POSITION_TYPE_SELL && check_Symbol == sparam && magic == magic_2) { if(Open_Price == 0) { Open_Price = open_price; } if(Open_Price < open_price) { Open_Price = open_price; } LastIsBuy = false; // Next Sell won't Trade TotalSell++; if(TotalSell == MaxTrade) { Print("Maximum Trade is reached"); return(0); } } } } /* If the Price is downtrend to Buy Order, check the Bid */ if(LastIsBuy) { if(Bid_1 <= Open_Price - (Spread_1 * point) - (PipStep * point)) { if(MA[0] < Ask_1 && iclose_1 > MA[0]) { Buy(sparam, magic_2, Ask_1, StopLoss_3, TakeProfit_3); } LastIsBuy = false; return(0); } } /* If the direction is Uptrend to Sell Order, check the value of Ask */ else if(!LastIsBuy) { if(Ask_1 >= Open_Price + (Spread_1 * point) + (PipStep * point)) { if(MA[0] > Bid_1 && iclose_1 < MA[0]) { Sell(sparam, magic_2, Bid_1, StopLoss_3, TakeProfit_3); } return(0); } } return(0); }
I am sorry Sir..I don't understand this 2nd & 3rd Articles Because There is Russian Language in this 1st Website & 2nd Website but I am from India . I translated this English language but it has some wronged this English lang in this website .
I understand this Void OnChartEvent() But I saw this Website if It is used Indicator.
I don't know how to make MT5 EA code in Void OnChartEvent() function but I am a Intermediate Programmer.

- 2018.01.28
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Sir ,
I want to practice this Example EA MT5.
1)
It is working to grid Trading into One Symbol.
2)
It has some working into grid trading to 4 multi symbol..but it doesn't work to trade in this Second symbol "EURUSD" ( Please see this 1st photo attached)
It has 2 Trade in "GBPUSD" symbol (Please see this 2nd photo attached) but I want only one Trade in GPBUSD.
It has some problem ...Please Test it & solve this code itself 👇