declaration of 'myrequest' hides global declaration

 

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

      } 

 

 

 

} 
 
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.
 

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
 
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.
Thank you very much!!!!  ;*