Draw Indicator in Experts

 

Hello,

i would like to draw an indicator when my experts starts. Is this possible?

int OnInit()
{
   MAHandle = iMA(_Symbol, _Period, MovingPeriod, 0, MODE_SMA, PRICE_CLOSE);
   if(MAHandle == INVALID_HANDLE)
   {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}


In my case i would like to draw the MAHandle to the chart window.

Thank you!

 
Airwaver:

Hello,

i would like to draw an indicator when my experts starts. Is this possible?


In my case i would like to draw the MAHandle to the chart window.

Thank you!

Yes, you have to use ChartIndicatorAdd(). Something like :

int OnInit()
{
   MAHandle = iMA(_Symbol, _Period, MovingPeriod, 0, MODE_SMA, PRICE_CLOSE);
   if(MAHandle == INVALID_HANDLE)
   {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
   }
   ChartIndicatorAdd(ChartID(), 0, MAHandle); 
   return(INIT_SUCCEEDED);
}
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
Documentation on MQL5: Chart Operations / ChartIndicatorAdd
  • www.mql5.com
Chart Operations / ChartIndicatorAdd - Documentation on MQL5
Reason: