Download MetaTrader 5

Cannot add Indicator to miniChart

To add comments, please log in or register
Marcelo Coutinho
1201
Marcelo Coutinho  

Hi there !

Can someone please help here. I am trying to add an indicator with no sucess.

void CreateChartInSubwindow(int             window_number,  // subwindow number
                            int             macd_type,      // macd_type
                            int             x_distance,     // X-coordinate
                            int             y_distance,     // Y-coordinate
                            int             x_size,         // width
                            int             y_size,         // height
                            string          name,           // object name
                            string          pSymbol,        // pSymbol
                            ENUM_TIMEFRAMES timeframe,      // time frame
                            int             subchart_scale, // bar scale
                            bool            show_dates,     // show date scale
                            bool            show_prices,    // show price scale
                            bool            show_ohlc,      // show OHLC prices
                            bool            show_ask_bid,   // show ask/bid levels
                            bool            show_levels,    // show trade levels
                            string          tooltip)        // tooltip
  {
//--- If the object has been created successfully
   if(ObjectCreate(0,name,OBJ_CHART,window_number,0,0))
     {
      //--- Set the properties of the chart object
      ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);   // chart corner
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x_distance);       // X-coordinate
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y_distance);       // Y-coordinate
      ObjectSetInteger(0,name,OBJPROP_XSIZE,x_size);               // width
      ObjectSetInteger(0,name,OBJPROP_YSIZE,y_size);               // height
      ObjectSetInteger(0,name,OBJPROP_CHART_SCALE,subchart_scale); // bar scale
      ObjectSetInteger(0,name,OBJPROP_DATE_SCALE,show_dates);      // date scale
      ObjectSetInteger(0,name,OBJPROP_PRICE_SCALE,show_prices);    // price scale
      ObjectSetString(0,name,OBJPROP_SYMBOL,pSymbol);              // pSymbol
      ObjectSetInteger(0,name,OBJPROP_PERIOD,timeframe);           // time frame
      ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);             // tooltip
      ObjectSetInteger(0,name,OBJPROP_BACK,false);                 // object in the foreground
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);           // object is not available for selection
      ObjectSetInteger(0,name,OBJPROP_COLOR,clrWhite);             // white color
      //--- Get the chart object identifier
      long subchart_id=ObjectGetInteger(0,name,OBJPROP_CHART_ID);
      //--- Set the special properties of the chart object
      ChartSetInteger(subchart_id,CHART_SHOW_OHLC,show_ohlc);           // OHLC
      ChartSetInteger(subchart_id,CHART_SHOW_TRADE_LEVELS,show_levels); // trade levels
      ChartSetInteger(subchart_id,CHART_SHOW_BID_LINE,show_ask_bid);    // bid level
      ChartSetInteger(subchart_id,CHART_SHOW_ASK_LINE,show_ask_bid);    // ask level
      ChartSetInteger(subchart_id,CHART_COLOR_LAST,clrLimeGreen);       // color of the level of the last executed deal
      ChartSetInteger(subchart_id,CHART_COLOR_STOP_LEVEL,clrRed);       // color of Stop order levels 

      if(macd_type==1)
        {
         Print("1: ",subchart_id);
         Print("1: ",iMACD1_handle);
         ChartIndicatorAdd(subchart_id,window_number,iMACD1_handle);
        }

      if(macd_type==2)
        {
         Print("2: ",subchart_id);
         Print("2: ",iMACD2_handle);
         ChartIndicatorAdd(subchart_id,window_number,iMACD2_handle);
        }

      //--- Refresh the chart object
      ChartRedraw(subchart_id);
     }
  }
//+------------------------------------------------------------------+
Alain Verleyen
Moderator
32063
Alain Verleyen  

That's because when you are using this statement :

      long subchart_id=ObjectGetInteger(0,name,OBJPROP_CHART_ID);

Your "mini chart" is not yet created.

Marcelo Coutinho
1201
Marcelo Coutinho  
Alain Verleyen:

That's because when you are using this statement :

Your "mini chart" is not yet created.

Take a look again ... it is there !

See picture below

Files:
Capturar.PNG 48 kb
Capturar.PNG 61 kb
Alain Verleyen
Moderator
32063
Alain Verleyen  
Marcelo Coutinho:

Take a look again ... it is there !

See picture below

Ok, then add error processing and check the returned code of ChartIndicatorAdd().

You cannot add a MACD indicator on a main window, you cannot add an indicator on a non-existent sub-window.

Marcelo Coutinho
1201
Marcelo Coutinho  
Alain Verleyen:

Ok, then add error processing and check the returned code of ChartIndicatorAdd().

You cannot add a MACD indicator on a main window, you cannot add an indicator on a non-existent sub-window.

Please accept my apologies in late answer.

I have solved the problem. It was a sub window error number.

The problem now is that Strategy Tester does not display the mini chart sub windows while the normal operation shows it normally. Any idea ? (pict attached)

Regards.

Files:
Capturar.PNG 15 kb
To add comments, please log in or register