Hi all
I have finished an EA, I want to use it for my demo account for all symbols with timeframe M15.
Is there an easy way to do it ?
I don't want to open the symbols and drag and drop the EA to them one by one
Peter
not without coding that feature into the ea code.
you can backtest on all marketwatch pairs via strategy tester, but thats not live charts.
It's not that easy I'm afraid as there are a lot of code changes required. And unfortunately - all the articles that wrote about multi-currency EAs have completely overcomplicated the process. Use the trade library as it encapsulates everything.
to give you some tips...
#include <Trade\Trade.mqh> input string Symbols = "EURUSD, GBPUSD, USDJPY"; // Comma-separated list of symbols for the EA to monitor //Global variables CTrade trade; string symbolList[]; int handles[]; int size; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { StringSplit(Symbols, ',', symbolList); size = ArraySize(symbolList); ArrayResize(handles, size); for(int i=0;i<size;i++){ //SymbolSelect(symbolList[i], true); // <-- This forces loading data for that symbol (but you don't need to call this function) handles[i] = iCustom(symbolList[i], _Period, "Examples\\Zigzag Ma Cross" .............); if(handles[i] == INVALID_HANDLE) return INIT_FAILED; } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int symbolsCount = ArraySize(symbolList); static datetime signalTimes[]; // Track signal times per symbol if (ArraySize(signalTimes) != symbolsCount) ArrayResize(signalTimes, symbolsCount); for (int i = 0; i < symbolsCount; i++) // Everything goes inside a loop to loop between all symbols { string symbol = symbolList[i]; datetime barOpenTime = iTime(symbol, _Period, 0); // Fetch buffers for this symbol from its indicator handle CopyBuffer(handles[i], 2, 0, 3, ZigzagColor); CopyBuffer(handles[i], 5, 0, 3, LegState); bool noOpenPositions = (CountSymbolPositions(symbol) == 0); if (noOpenPositions && signalTimes[i] != barOpenTime) { if (BuySignal) OpenBuyStopTrade(symbol); if (SellSignal) OpenSellStopTrade(symbol); signalTimes[i] = barOpenTime; // signal time per symbol } } ManageTrades(); } int CountSymbolPositions(string symbol) { int count = 0; for(int i = 0; i < PositionsTotal(); i++) { if(PositionGetSymbol(i) == symbol) { count++; break; } } return count; } //+------------------------------------------------------------------+ //| Open a sell stop trade | //+------------------------------------------------------------------+ void OpenSellStopTrade(string symbol) { MqlTick tick; if (!SymbolInfoTick(symbol, tick)) { Print("Failed to retrieve tick data for ", symbol); return; } double lotSize = CalculateLotSize(symbol, SL_Pips); double entryPrice = tick.bid - offset*_Point; double tpPrice = entryPrice - TP_Pips * GetPipValue(symbol); double slPrice = entryPrice + SL_Pips * GetPipValue(symbol); trade.SetDeviationInPoints(MaxSlippage); datetime expirationTime = TimeCurrent() + (time_in_minutes * 60); trade.SellStop(lotSize, entryPrice, symbol, slPrice, tpPrice, ORDER_TIME_SPECIFIED, expirationTime); } //+------------------------------------------------------------------+ //| Open a buy stop trade | //+------------------------------------------------------------------+ void OpenBuyStopTrade(string symbol) { MqlTick tick; if (!SymbolInfoTick(symbol, tick)) { Print("Failed to retrieve tick data for ", symbol); return; } double lotSize = CalculateLotSize(symbol, SL_Pips); double entryPrice = tick.ask + offset*_Point; double tpPrice = entryPrice + TP_Pips * GetPipValue(symbol); double slPrice = entryPrice - SL_Pips * GetPipValue(symbol); trade.SetDeviationInPoints(MaxSlippage); datetime expirationTime = TimeCurrent() + (time_in_minutes * 60); trade.BuyStop(lotSize, entryPrice, symbol, slPrice, tpPrice, ORDER_TIME_SPECIFIED, expirationTime); }
Note that you never use the constant _Symbol anymore, you always use a string "symbol" which connects to the array value of the symbol name.
Hi all
I have finished an EA, I want to use it for my demo account for all symbols with timeframe M15.
Is there an easy way to do it ?
I don't want to open the symbols and drag and drop the EA to them one by one
Peter
It can be done with a script and a template.
You save a template from a chart with your EA. Then in a script you loop through all symbols you want to use, open a chart if needed and apply the template.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all
I have finished an EA, I want to use it for my demo account for all symbols with timeframe M15.
Is there an easy way to do it ?
I don't want to open the symbols and drag and drop the EA to them one by one
Peter