Plot Arrow not showing on new candle

 

Hi, i'm trying to create an indicator with claude ai help, and it's almost works well,

this code is intended to draw a plot arrow into the particular candle as a signal based on stochastic level

the only issue i face is the signal only appear on previous candle that already formed,
meanwhile for the last newly candle didn't showed up, 
it will appear on the new candle when i switch to other timeframe first and then back to previous timeframe, or when i re-attached it to the chart,

tried prompt claude to fix it, but no result

any advice to fix this issue ?

#property copyright "nikobaby_"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   4


input group "=== Stochastic Signal Toggle ==="
input bool show2080 = true;    

input group "=== Fast Stochastic Settings ==="
input int fastLength = 14;     
input int fastKSmooth = 1;     
input int fastDSmooth = 3;     

input group "=== Slow Stochastic Settings ==="
input int slowLength = 5;      
input int slowKSmooth = 3;     
input int slowDSmooth = 3;     

input group "=== Display Settings ==="
input int spaceOffset = 280;   


double FastBuy2080[];
double FastSell2080[];
double SlowBuy2080[];
double SlowSell2080[];


double fastK[], fastD[], slowK[], slowD[];


int fastStochHandle, slowStochHandle;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{

    SetIndexBuffer(0, FastBuy2080, INDICATOR_DATA);
    SetIndexBuffer(1, FastSell2080, INDICATOR_DATA);
    SetIndexBuffer(2, SlowBuy2080, INDICATOR_DATA);
    SetIndexBuffer(3, SlowSell2080, INDICATOR_DATA);
    

    PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_ARROW);
    PlotIndexSetInteger(0, PLOT_ARROW, 233); // Buy arrow
    PlotIndexSetInteger(0, PLOT_ARROW_SHIFT, -10);
    PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_ARROW);
    PlotIndexSetInteger(1, PLOT_ARROW, 234); // Sell arrow
    PlotIndexSetInteger(1, PLOT_ARROW_SHIFT, 10);
    PlotIndexSetInteger(2, PLOT_DRAW_TYPE, DRAW_ARROW);
    PlotIndexSetInteger(2, PLOT_ARROW, 233);
    PlotIndexSetInteger(2, PLOT_ARROW_SHIFT, -10);
    PlotIndexSetInteger(3, PLOT_DRAW_TYPE, DRAW_ARROW);
    PlotIndexSetInteger(3, PLOT_ARROW, 234);
    PlotIndexSetInteger(3, PLOT_ARROW_SHIFT, 10);
    

    PlotIndexSetInteger(0, PLOT_LINE_COLOR, clrLime);
    PlotIndexSetInteger(1, PLOT_LINE_COLOR, clrLime);
    PlotIndexSetInteger(2, PLOT_LINE_COLOR, clrLime);
    PlotIndexSetInteger(3, PLOT_LINE_COLOR, clrLime);
    PlotIndexSetString(0, PLOT_LABEL, "Fast Buy 2080");
    PlotIndexSetString(1, PLOT_LABEL, "Fast Sell 2080");
    PlotIndexSetString(2, PLOT_LABEL, "Slow Buy 2080");
    PlotIndexSetString(3, PLOT_LABEL, "Slow Sell 2080");
    

    fastStochHandle = iStochastic(_Symbol, _Period, fastLength, fastKSmooth, fastDSmooth, MODE_SMA, STO_LOWHIGH);
    slowStochHandle = iStochastic(_Symbol, _Period, slowLength, slowKSmooth, slowDSmooth, MODE_SMA, STO_LOWHIGH);
    
    if(fastStochHandle == INVALID_HANDLE || slowStochHandle == INVALID_HANDLE)
    {
        Print("Error creating stochastic handles");
        return(INIT_FAILED);
    }
    

    IndicatorSetString(INDICATOR_SHORTNAME, "YDZ Stoch Single [2080]");
    

    IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
    
    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| 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[])
{
    if(rates_total < MathMax(fastLength, slowLength) + MathMax(fastDSmooth, slowDSmooth))
        return(0);
    
    int limit = prev_calculated > 0 ? prev_calculated - 1 : 0;
    

    if(CopyBuffer(fastStochHandle, 0, 0, rates_total, fastK) <= 0 ||
       CopyBuffer(fastStochHandle, 1, 0, rates_total, fastD) <= 0 ||
       CopyBuffer(slowStochHandle, 0, 0, rates_total, slowK) <= 0 ||
       CopyBuffer(slowStochHandle, 1, 0, rates_total, slowD) <= 0)
    {
        return(0);
    }
    
 
    for(int i = limit; i < rates_total; i++)
    {
        FastBuy2080[i] = EMPTY_VALUE;
        FastSell2080[i] = EMPTY_VALUE;
        SlowBuy2080[i] = EMPTY_VALUE;
        SlowSell2080[i] = EMPTY_VALUE;
    }
    
 
    for(int i = limit + 1; i < rates_total; i++)
    {

        if(show2080)
        {
            if(fastD[i] > 20 && fastD[i-1] <= 20)
                FastBuy2080[i] = low[i] - spaceOffset * _Point;
            if(fastD[i] < 80 && fastD[i-1] >= 80)
                FastSell2080[i] = high[i] + spaceOffset * _Point;
            if(slowD[i] > 20 && slowD[i-1] <= 20)
                SlowBuy2080[i] = low[i] - spaceOffset * _Point;
            if(slowD[i] < 80 && slowD[i-1] >= 80)
                SlowSell2080[i] = high[i] + spaceOffset * _Point;
        }
    }
    
    return(rates_total);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
    if(fastStochHandle != INVALID_HANDLE)
        IndicatorRelease(fastStochHandle);
    if(slowStochHandle != INVALID_HANDLE)
        IndicatorRelease(slowStochHandle);
}
 
Nikobaby_:

Hi, i'm trying to create an indicator with claude ai help, and it's almost works well,

this code is intended to draw a plot arrow into the particular candle as a signal based on stochastic level

the only issue i face is the signal only appear on previous candle that already formed,
meanwhile for the last newly candle didn't showed up, 
it will appear on the new candle when i switch to other timeframe first and then back to previous timeframe, or when i re-attached it to the chart,

any advice to fix this issue ?

Why not prompt Claude to fix it?

Better yet, copy and paste the code into MT5's AI Assistant and prompt for a fix.

 
Ryan L Johnson #:

Why not prompt Claude to fix it?

Better yet, copy and paste the code into MT5's AI Assistant and prompt for a fix.

of course i've tried prompt claude to fix it, 
but since there's no error in it, claude just back and forth change the code with no preferable result
 
Nikobaby_ #:
of course i've tried prompt claude to fix it, 
but since there's no error in it, claude just back and forth change the code with no preferable result

I guess that Claude is a bad little boy.

I've successfully made major edits to several indicators with Beta MT5 Build 6034 and the AI Assistant therein (MQL5 Lite). In my last project, it messed up the code and then attempted to fix the code which failed x 2. I simply prompted, "The indicator is broker beyond repair," because I was ready to give up. To my pleasant surprise, it jumped back into action with heavy thinking and waiting, and then successfully recoded the entire indicator anew with all features included. Therefore, I reiterate that you should give MQL5 Lite a try.

 

@Nikobaby_, fixed with MQL5 Lite (untested):

fix

Files:
 
Ryan L Johnson #:

@Nikobaby_, fixed with MQL5 Lite (untested):

i see, the bug was at the iteration logic,

i've run the change, and the result works as my expectation, 
now the signal can appear on the new fresh candle, 

thanks bro, 

i might try the mql5 ai assistant 

 
Nikobaby_ #:

i see, the bug was at the iteration logic,

i've run the change, and the result works as my expectation, 
now the signal can appear on the new fresh candle, 

thanks bro, 

i might try the mql5 ai assistant 

You're most welcome.👍