Undeclared identifier - page 2

 
Marco vd Heijden:

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.

I think i'm in over my head now.  I didn't think we needed to use the OnTick function, i thought it was an option.

 
Marco vd Heijden:

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.

so went back to the beginning and started with a new EA template.  this version compiles without issues, waits and then trades the chart pair, but it keeps opening trades, so added the 'int total' in for now.

but as soon as i start to add in the mutli currency it all stops. it seems to skip everything after line 60, even though it compiles without error.

#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property version   "1.00"
#property strict
//--- input parameters
input string   TradeComment="10Long";
input int      MagicNumber=400;
input double   Lots=0.01;
input int      Slippage=200;
input int      OpenTradeTime=1120;
input int      MinutesToWaitForTick=2;
//input bool     OpenBuy=true;
//string   symbol[] =   {"AUDJPY","USDJPY","EURUSD","GBPUSD"};
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
  

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
  
//--- OpenTradeTime

   int ticket, total;

   int ct, EndTradeTime;
   
   ct = Hour() * 100 + Minute();
   
  
   

   EndTradeTime = OpenTradeTime + MinutesToWaitForTick;
   
   total=OrdersTotal();
   if(total<1)
   
{
   if(ct >= OpenTradeTime && ct < EndTradeTime)               //<--- line 60
   //if(ct == OpenTradeTime && OpenBuy)
   
  {
   //int i;
 //string symbols = "";
   //for(i=0; i<ArraySize(symbol); i++)
//   //symbols = symbol[i];
 //symbols = symbol[ArraySize(symbol)-1];
//   
   
   //{
   
  //if (OpenBuy)
   //}
 
   
   //double ask = MarketInfo(symbols,MODE_ASK);
   
   {   
   ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,TradeComment,MagicNumber,White);
   if (ticket>0)
   {   
   if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
   }          
   else Print("Error opening BUY order : ",GetLastError()); 
   }          
            
   
   
   RefreshRates();
   Sleep(200);
}




   }
return;
  }
//+------------------------------------------------------------------+
 

You have to set a total for each symbol;

Not just one because then you will only get one order and it will prevent any more orders because total >0

 

thanks for the tips, will get to that.


first got to get it to open the multi currencies, then i can count them.  I've increased the value to 10, as a single currency EA it then opens 10 trades. 

But as a multi currency it's not opening any, so my code for the various pairs is not triggering.  I've even tried a different method for identifying the pairs, which works in a script i currently use (outline below), but it still fails at the same point.

string mySymbol;

if(isIBFXmini) postfix="m";
   mySymbol="AUDJPY"+postfix;  OpenBuy(); 
   mySymbol="AUDUSD"+postfix;  OpenBuy();
   mySymbol="NZDJPY"+postfix;  OpenBuy();
   mySymbol="CHFJPY"+postfix;  OpenBuy();
   mySymbol="EURUSD"+postfix;  OpenBuy();
   mySymbol="EURJPY"+postfix;  OpenBuy();
   mySymbol="GBPJPY"+postfix;  OpenBuy();
   mySymbol="GBPUSD"+postfix;  OpenBuy();
   mySymbol="USDJPY"+postfix;  OpenBuy();
   mySymbol="NZDUSD"+postfix;  OpenBuy(); 

ticket=OrderSend(mySymbol,OP_BUY,Lots,ask,Slippage,0,0,TradeComment,MagicNumber,White);
 

You have to use a separate counter for every symbol in stead of one counter for all symbols.

I think it's best if you first develop the complete operational robot for one symbol and then when that is done, expand it to multi symbol.

 
do you have any recommended reading for this?  it's not easy to find or i'm searching the wrong way for it.
 
jmail5:
do you have any recommended reading for this?  it's not easy to find or i'm searching the wrong way for it.
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property version   "1.00"
#property strict
//--- input parameters
input string   TradeComment="10Long";
input int      MagicNumber=400;
input double   Lots=0.01;
input int      Slippage=200;
input int      OpenTradeTime=1120;
input int      MinutesToWaitForTick=2;
input bool     OpenBuy=true;
int ct,EndTradeTime;
string   symbol[10] =   {"EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD"};

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{  
    
   
    return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  
    ct = Hour() * 100 + Minute();
     int MinutesToWaitForTickToSeconds = 2*60;
    //--- not sure if it's 2 seconds or two minutes'
    //EndTradeTime = OpenTradeTime + MinutesToWaitForTickToSeconds;
    EndTradeTime = OpenTradeTime + MinutesToWaitForTick;
   
   int total=OrdersTotal();
   int totalinsymbol = ArraySize(symbol);
   if(total<1&&total<totalinsymbol)
   {
      
        if(ct >= OpenTradeTime && ct < EndTradeTime)          
        {
            for(int i=0;i<ArraySize(symbol);i++)
            {
                int ticket;
                SymbolSelect(symbol[i],true);
                double ask = MarketInfo(symbol[i],MODE_ASK);
                ticket = OrderSend(symbol[i],OP_BUY,Lots,Ask,Slippage,0,0,TradeComment,MagicNumber,White);
                if (ticket>0)
                {   
                    if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
                        Print("BUY for ", symbol[i]," order opened : ",OrderOpenPrice());        
                    else Print("Error opening BUY order : ",GetLastError()); 
                }         
            }   
        }
        RefreshRates();
        Sleep(200);
    }    

 }

assuming this below is list of multiple symbols

string   symbol[10] =   {"EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD","EURUSD"};
0       16:40:30.557    Expert Multipairs EURUSD,H1: removed
0       16:40:30.576    Expert Multipairs EURUSD,H1: loaded successfully
0       16:40:30.687    TestGenerator: current spread 17 used
1       16:40:32.701    TestGenerator: unmatched data error (volume limit 5863 at 2020.08.26 10:00 exceeded)
2       16:40:32.734    2020.08.26 00:00:00  Multipairs inputs: MagicNumber=400; Lots=0.01; Slippage=200; OpenTradeTime=1120; MinutesToWaitForTick=2; OpenBuy=1; 
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #1 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #2 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #3 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #4 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #5 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #6 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #7 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #8 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #9 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: open #10 buy 0.01 EURUSD at 1.18172 ok
0       16:40:34.406    2020.08.26 11:20:00  Multipairs EURUSD,H1: BUY for EURUSD order opened : 1.18172
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #10 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #9 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #8 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #7 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #6 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #5 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #4 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #3 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #2 is closed
2       16:40:38.033    2020.08.26 23:59:54  Tester: order #1 is closed


conceptually it should work but i am not sure if in MT4 tester multiple pairs simulation is possible by default (i skipped MQL4), others could probably help on this

 
roshjardine: i am not sure if in MT4 tester multiple pairs simulation is possible
It's not. Current symbol only.
 
   {
   int count = 0;
   for(int i=OrdersTotal()-1; i >= 0; i--)
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
   {
   if(OrderSymbol() == symbols && OrderMagicNumber() == MagicBuy)
   {
   count++;
   }
   }
   else
   {
   Print("OrderSend() error - ", ErrorDescription(GetLastError()));
   }
   if(count < 1)
   }

So this is what i went with for the symbol counting, because i'm using both trade comments and Magic numbers which are different for Buy's and Sells, i could select both the symbol pair and if it was a Buy or Sell trade. 


Thanks for everyone's help.

 

If you really want to push these ideas to the surface then i would advice you strongly to look into MT5 since it already has the functionality you are looking for and MT4 is very limited in that area.

Reason: