Draw Objects on Sub Chart

 

Hi,

Take a look at this indicator :

#property indicator_chart_window

#property indicator_plots 0

string m_object_prefix = "Spread_Indicator_";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    int id = ChartWindowFind();
    ObjectCreate(id, m_object_prefix + "Ask_H", OBJ_HLINE,0, 0, 0);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_COLOR, clrDeepPink);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_WIDTH, 1);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_SELECTABLE, false);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_SELECTED, false);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_HIDDEN, true);
    ObjectSetInteger(id, m_object_prefix + "Ask_H", OBJPROP_TIMEFRAMES, OBJ_ALL_PERIODS);
        
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    int id = ChartWindowFind();
    double ask = SymbolInfoDouble(Symbol(), SYMBOL_ASK);
    ObjectSetDouble(id, m_object_prefix + "Ask_H", OBJPROP_PRICE, ask);
    return(rates_total);
}
//+------------------------------------------------------------------+

As you see, it's a very basic, simple indicator to draw and replace a horizontal line on the ask price. Now, I have an interface with a sub chart, I already know the id of the sub chart and I can manipulate everything (like the bid and ask colors) on this sub chart. Here is the problem, When I use 

ChartIndicatorAdd(sub_chart_id,0,handle);

I can add any internal indicator like iStochastic (when set on the handle), how ever, when I direct the handle toward using my indicator above, even though the handle is valid (already checked), the objects are not being drawn.

I use ask and horizontal line as a simplistic example of what I want to do.

Basically, the handle is using iCustom to get this indicator and add it to 0 subwindow of the subchart. What did I do wrong here? Looks like the chart objects can't be drawn on sub charts this way?

int handle = iCustom(m_symbols[m_symbol_list_index].Name,PERIOD_M15, SPREAD_INDI_ADDRESS);

I also tried adding the indicator on blank chart, saving the template and assigning the template to sub chart by code, same result, the line is not showing up in the sub chart, and, if you have the indicator on the main chart at the same time, the line on the main chart will flicker with every thick on the sub chart !

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5