Download MetaTrader 5

declaration of 'myrequest' hides global declaration

To add comments, please log in or register
filipefr
58
filipefr  

I'm trying to open an order but I'm getting this warning:

 declaration of 'myrequest' hides global declaration

How can I solve this? 

This is my code: 

MqlTradeRequest myrequest; 

... 

 void OnTick()

  {

...

  MqlTradeRequest myrequest;

  MqlTradeResult myresult;

  ZeroMemory(myrequest); 

myrequest.action = TRADE_ACTION_DEAL;

      myrequest.type = ORDER_TYPE_BUY;

      myrequest.symbol = _Symbol;

      myrequest.volume = lot_size; // fill in a double value

      myrequest.type_filling = ORDER_FILLING_FOK;

      myrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

      myrequest.sl = 0 ;

      myrequest.tp = 0 ;

      myrequest.deviation =60;

      res = OrderSend(myrequest,myresult);

      if (res < 0) {

         Print("ORder send BUY error #", GetLastError());

      } 

 

 

 

} 
Stuart Browne
5897
Stuart Browne  
You've declared myrequest twice. Once as an EA global and once again in OnTick(). You need to remove one of them depending on your desired outcome.
Enrico Lambino
4358
Enrico Lambino  

Just wanted to add on Filter's comment:

Your program will use the local struct within OnTick(), and will use the global one anywhere else.

Here is some information about variable scope:

https://www.mql5.com/en/docs/basis/variables/variable_scope

Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
  • www.mql5.com
Language Basics / Variables / Visibility Scope and Lifetime of Variables - Reference on algorithmic/automated trading language for MetaTrader 5
To add comments, please log in or register