Indicator not working stops painting-needs mt4 to be restart to update chart.

 

Hi fam....

I have this Indicator, it does not work. it is supposed to plot BuyArrow and SellArrow when the conditions are met. The problem im encountering is that once I open mt4 the indicator workks,it will plot previous arrows and maybe 1 or 2 arrows after,then it stops.It then needs mt4 to be restarted again to update chart.Ive tried ruunning it with autorefresh,,but it doesnt refresh.

Ive tried to add alert for BuyArrow and SellArrow,but the alerts trigger every minute  when SUPER CALL and SUPER SELL. I have since removed them.


#property indicator_separate_window

#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

extern int MaFast_period = 1;
extern ENUM_MA_METHOD MaValue = MODE_SMA;
extern int MaSlow_period = 34;
extern int Signal_period = 5;
extern color colorBuy = LimeGreen;
extern color colorSell = Red;
extern bool visibleBuy = true;
extern bool visibleSell = true;

double smaFastBuffer[];
double smaSlowBuffer[];

int OnInit()
{
    SetIndexBuffer(0, smaFastBuffer);
    SetIndexBuffer(1, smaSlowBuffer);

    SetIndexStyle(0, DRAW_ARROW);
    SetIndexArrow(0, 233);
    SetIndexLabel(0, "SUPER CALL");

    SetIndexStyle(1, DRAW_ARROW);
    SetIndexArrow(1, 234);
    SetIndexLabel(1, "SUPER SELL");

    IndicatorShortName("super");

    return(INIT_SUCCEEDED);
}

int start()
{
    int limit = Bars - IndicatorCounted();

    if (limit <= 0)
        return(0);

    for (int i = 0; i < limit; i++)
    {
        smaFastBuffer[i] = iMA(NULL, 0, MaFast_period, 0, MaValue, PRICE_CLOSE, i);
        smaSlowBuffer[i] = iMA(NULL, 0, MaSlow_period, 0, MaValue, PRICE_CLOSE, i);
    }

    for (int j = limit - 1; j >= 1; j--)
    {
        bool buySignal = (smaFastBuffer[j] > smaSlowBuffer[j] && smaFastBuffer[j - 1] < smaSlowBuffer[j - 1]);
        bool sellSignal = (smaFastBuffer[j] < smaSlowBuffer[j] && smaFastBuffer[j - 1] > smaSlowBuffer[j - 1]);

        if (buySignal)
        {
            ObjectCreate("BuyArrow" + IntegerToString(j), OBJ_ARROW_UP, 0, Time[j], High[j] + 10 * Point);
            ObjectSetInteger(0, "BuyArrow" + IntegerToString(j), OBJPROP_COLOR, colorBuy);
            ObjectSetInteger(0, "BuyArrow" + IntegerToString(j), OBJPROP_SELECTABLE, false);
            ObjectSetInteger(0, "BuyArrow" + IntegerToString(j), OBJPROP_SELECTED, false);
        }

        if (sellSignal)
        {
            ObjectCreate("SellArrow" + IntegerToString(j), OBJ_ARROW_DOWN, 0, Time[j], Low[j] - 10 * Point);
            ObjectSetInteger(0, "SellArrow" + IntegerToString(j), OBJPROP_COLOR, colorSell);
            ObjectSetInteger(0, "SellArrow" + IntegerToString(j), OBJPROP_SELECTABLE, false);
            ObjectSetInteger(0, "SellArrow" + IntegerToString(j), OBJPROP_SELECTED, false);
        }
    }

    return (0);

 
 ObjectCreate("BuyArrow" + IntegerToString(j), OBJ_ARROW_UP, 0, Time[j], High[j] + 10 * Point);

Do not use series index in object names, as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g., “name0”), same, existing, previous, name (e.g., “name0” now on bar one.)

Use time (as int) or a non-series index:

#define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
 

OK, let me give it a try. thanks

 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893