Undeclared identifier

 

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);

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;
   for(i=0; i<ArraySize(symbol); i++)
   {
   string 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);
  }
 


 
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. 

 
Marco vd Heijden:

Print the error;

And look up the code. 

It's not doing anything, not giving any error codes for me to work with.  Can't even run it in debug mode :( 
OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
Before we start developing, let's get acquainted with some features of the OOP, which will be used in this article.  Of course, we will use structures and classes. These are the basics of object oriented languages. A structure is a construction that allows containing a set of variables and functions of different types (except void). A class as...
 

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; 

21:41:25.393 D1Long GBPUSD,H1: 0
0 21:41:25.393 D1Long GBPUSD,H1: initialized
0 21:44:04.877 D1Long GBPUSD,H1: uninit reason 4
0 21:44:04.904 Expert D1Long GBPUSD,H1: removed
 

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...
  }
//+------------------------------------------------------------------+
MQL5 Code Base
MQL5 Code Base
  • www.mql5.com
For a complex object separate its construction from representation. Same construction process can create different representations When I start learning about trading, I remember the trading pioneer Shawn Lucas (founder of Apiary-fund) saying "trading is simple, you go from bound range market to breakout market and vice versa". I looked at few...
 
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);
}
 


 

 

Just moved the loop function into the code just after the 'if (openbuy)' line, I didn't get the symbol list printed this time.

so this must be where my error is, it's not activating the next part after the clock ticks over.


I also moved the loop just above the open buy - still nothing

 

Ok i just realized this will require a bit more effort.

I think it's best you stick with Symbol() and just the chart instrument until you got that part of the logic working and then expand the concept to multi symbol.

I do not see any OnTick() function your code so fix that first.
Reason: