Help please, i cant run it, says declaration of ma_9_h hides global variable

 
#include  <Trade/Trade.mqh>
CTrade trade;
ulong trade_ticket=0;
bool time_passed=true;

//Medias
int ma_9_h=0;
int ma_21_h=0;


//Array
double ma_9_array[];
double ma_21_array[];

int OnInit(){
     ma_9_h = iMA(_Symbol, _Period, 9, 0,MODE_LWMA, PRICE_CLOSE);
     ma_21_h = iMA(_Symbol, _Period, 21, 0,MODE_LWMA, PRICE_CLOSE);
    
    return INIT_SUCCEEDED;
};

void OnTick(){
     CopyBuffer(ma_9_h, 0, 1,3, ma_9_array);
     CopyBuffer(ma_21_h, 0, 1,3, ma_21_array);

      if (PositionSelectByTicket(trade_ticket)) trade_ticket=0;

     
     if (ma_9_array [1]> ma_21_array[1] && ma_9_array [0] < ma_21_array[0] && trade_ticket <=0 && time_passed==true){//compra
     double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits);
     trade.Buy(50, _Symbol, Ask, Ask+20*_Point, Ask+60*_Point, NULL);
     trade_ticket= trade.ResultOrder();
     time_passed=false;
     }  else if (ma_9_array [1]< ma_21_array[1] && ma_9_array [0] > ma_21_array[0] && trade_ticket <=0 && time_passed==true){//venta
        double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits);
        
        trade.Sell(50, _Symbol, Bid, Bid-20*_Point, Bid-60*_Point, NULL);
        trade_ticket= trade.ResultOrder();
        time_passed=false;
        
        EventSetTimer(60*3*2);
     }
     }
     
void OnTimer(){
time_passed=true;
}
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
  1. Please use "</>" icon or Alt-S to add your code. Don't just copy/paste it as normals text. It makes it difficult to read and help you.
  2. Since the Indicator handles will be used globally, remove the "int" in front of the lines that assign the handles.
    int OnInit()
    {
       ma_9_h  = iMA(_Symbol, _Period,  9, 0,MODE_LWMA, PRICE_CLOSE);
       ma_21_h = iMA(_Symbol, _Period, 21, 0,MODE_LWMA, PRICE_CLOSE);
       return INIT_SUCCEEDED;
    };

  3. However, the above code is not enough. You should always check the handles to make sure they are valid before using them elsewhere.
  4. You should also check the return values of the CopyBuffer functions to make sure valid data is returned.
  5. Your code has other problems too, which you will need to fix if you want your code to work properly.
 
doko940904:
***

Do as Fernando said.

Fernando Carreiro #:
  1. Please use "</>" icon or Alt-S to add your code. Don't just copy/paste it ass normals text. It makes it difficult to read and help you.

Do not start another topic.
I have deleted your new topic.

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

 

hides globar variable

I think you are using the same variable nane in 2 or more locations in addition to the global var

Try ctrl-f (from your keyboard) to search the variable name then you must see it duplicated two or more times 
Reason: