Ajuda com o função ChartIndicatorAdd()

 

Pessoal,

Quem puder me ajudar estou com o codigo abaixo pra plotar uma media movel janela ativa do grafico mas nao aparece, somente aparece se eu direcionar para uma sub-janela, onde estaria o erro nesse codigo.

//--- input parameters
string          symbol=_Symbol;    // symbol name
input group             ":: AJUSTES DA MEDIA MOVEL"
input ENUM_TIMEFRAMES   timeFrame   =PERIOD_CURRENT;              // Timeframe da Media Movel
input int               maPeriod    =67;                          // Periodo da Media Movel

 
int handle_iMA;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   handle_iMA =iMA(symbol,timeFrame,maPeriod,0,MODE_EMA,PRICE_CLOSE);
   
//--- try to add the indicator on the chart

         int subwindow  =(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL);     
         if(!ChartIndicatorAdd(0,0,handle_iMA))           //-- <-- nesse comando nao funciona para plotar na mesma janela
//         if(!ChartIndicatorAdd(0,0,handle_iMA))                 //-- <-- nesse comando funciona porem plota numa sub-janela

            PrintFormat("Failed to add iMA indicator on %d chart window. Error code  %d",GetLastError());

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
// Expert Advisor performs nothing
  }
 

Tente utilizar assim:


//--- input parameters
input int               maPeriod    =67;                          // Periodo da Media Movel
 
int handle_iMA = INVALID_HANDLE;;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   handle_iMA = iMA(_Symbol,_Period,maPeriod,0,MODE_EMA,PRICE_CLOSE);

   if(!ChartIndicatorAdd(0,0,handle_iMA))
      PrintFormat("Failed to add iMA indicator on %d chart window. Error code %d",0,GetLastError());

   return(INIT_SUCCEEDED);
}
Razão: