Download MetaTrader 5

Draw Indicator in Experts

To add comments, please log in or register
Airwaver
3
Airwaver 2013.05.19 12:55 

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!

Alain Verleyen
Moderator
31090
Alain Verleyen 2013.05.19 13:19  
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
To add comments, please log in or register