input int OpenTradeTime=0015; input double Lots=0.01; input string TradeComment="D1Long"; input int MagicNumber=200; input int Slippage=200; input int MinutesToWaitForTick=2; bool OpenBuy = true; string symbol[] = { "AUDJPY","USDJPY","EURUSD","GBPUSD"}; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { int ticket; int ct, EndTradeTime; ct = Hour() * 100 + Minute(); EndTradeTime = OpenTradeTime + MinutesToWaitForTick; if(ct >= OpenTradeTime && ct < EndTradeTime) { if (OpenBuy) { { int i; string symbols = ''; for(i=0; i<ArraySize(symbol); i++) { symbols = symbol[i]; } double ask = MarketInfo(symbols,MODE_ASK); ticket = OrderSend(symbols,OP_BUY,Lots,ask,Slippage,0,0,TradeComment,MagicNumber,White); if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); else Print("Error opening BUY order : ",GetLastError()); RefreshRates(); Sleep(200); } } } //--- return(INIT_SUCCEEDED); }
Hi Marco
Thank you for that,
got an error at first '' - single quote needed , so changed them to " " and it compiled, but i get a warning: - declaration of 'symbols' hides local variable :- sorted this, compiles fine now
and it won't open a trade?? - still won't trade.
Print the error;
Print(GetLastError());
And look up the code.
Print the error;
And look up the code.

- www.mql5.com
I shifted the error code around inside my code and the only feedback i got from the log files was '0' no error code
0 21:41:25.372 D1Long GBPUSD,H1 inputs: OpenTradeTime=1442; Lots=0.01; TradeComment=D1Long; MagicNumber=200; Slippage=200; MinutesToWaitForTick=2;
Hard coding of symbolnames can be problematic across different brokers due to pre and postfixes.
You can loop through all symbols.
//+------------------------------------------------------------------+ //| loop through all symbols | //+------------------------------------------------------------------+ for(int i=0;i<SymbolsTotal(1);i++) { Print("SYMBOL: ",SymbolName(i,1)," Found At: ",i); // Do Something... } //+------------------------------------------------------------------+

- www.mql5.com
Your code | for(i=0; i<ArraySize(symbol); i++){ symbols = symbol[i]; } |
Simplified | symbols = symbol[ArraySize(symbol)-1]; |
Is that really what you want?
So i added the loop at the end of the code, changed to the simplified code and left the get last error in.
it still shows no errors, but did generate a list of all the pairs on my platform, which includes the ones in this EA. didn't find any prefixes, the symbol names match the ones in my code.
i must be missing something to tell it to place an order. This is what i just run.
input int OpenTradeTime=0015; input double Lots=0.01; input string TradeComment="D1Long"; input int MagicNumber=200; input int Slippage=200; input int MinutesToWaitForTick=2; bool OpenBuy = true; string symbol[] = { "AUDJPY","USDJPY","EURUSD","GBPUSD"}; //double ask; //double bid; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { int ticket; int ct, EndTradeTime; ct = Hour() * 100 + Minute(); EndTradeTime = OpenTradeTime + MinutesToWaitForTick; { if(ct >= OpenTradeTime && ct < EndTradeTime) { if (OpenBuy) { { //int i; string symbols = ""; //for(i=0; i<ArraySize(symbol); i++) { //symbols = symbol[i]; symbols = symbol[ArraySize(symbol)-1]; } double ask = MarketInfo(symbols,MODE_ASK); ticket = OrderSend(symbols,OP_BUY,Lots,ask,Slippage,0,0,TradeComment,MagicNumber,White); if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); else Print("Error opening BUY order : ",GetLastError()); RefreshRates(); Sleep(200); } } } } //+------------------------------------------------------------------+ //| loop through all symbols | //+------------------------------------------------------------------+ for(int i=0;i<SymbolsTotal(1);i++) { Print("SYMBOL: ",SymbolName(i,1)," Found At: ",i); // Do Something... } //+------------------------------------------------------------------+ Print(GetLastError()); //--- return(INIT_SUCCEEDED); }

- 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 Can any one help i can't seem to clear the Error:- 'symbols'-undeclared identifier in the line
double ask = MarketInfo(symbols,MODE_ASK);