Custom Stochastic Indicator to Display V_Line at Crossover

 
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_buffers 1
#property indicator_chart_window
#property indicator_width1 1
#property indicator_color1 clrChartreuse
double tops[];
extern int k=12,d=3,s=6;
double main0[],main1[],signal0[],signal1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
   SetIndexBuffer(0,tops);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,"tops");

   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[]) {
//---
   for(int i=Bars-1; i>=0; i--) {

      main0[i] = iStochastic(NULL,0,k,d,s,MODE_EMA,0,MODE_MAIN,i);
      main1[i] = iStochastic(NULL,0,k,d,s,MODE_EMA,0,MODE_MAIN,i+1);
      signal0[i] = iStochastic(NULL,0,k,d,s,MODE_EMA,0,MODE_SIGNAL,i);
      signal1[i] = iStochastic(NULL,0,k,d,s,MODE_EMA,0,MODE_SIGNAL,i+1);
      if(main1[i]<signal1[i] && main0[i]>signal0[i]) {
         tops[i]=ObjectCreate(ChartID(),"Stochastic Cross Over",OBJ_VLINE,0,NULL,NULL);
      }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+

Hi All, 

I'm attempting to create a custom indicator that draws a vertical line at the point of a stochastic crossover. The compiler shows no errors, however, the chart does not display anything that was not already there. Any tips on how to fix are appreciated. 

 
many errors , one is :
tops[i]=ObjectCreate(ChartID(),"Stochastic Cross Over",OBJ_VLINE,0,NULL,NULL);
 
ObjectCreate(ChartID(),"Stochastic Cross Over",OBJ_VLINE,0,NULL,NULL);

noted. care to elaborate on the rest?

 

replace

 for(int i=Bars-1; i>=0; i--) {

by

int limit = MathMax (rates_total - prev_calculated, 2)-1;
for (int i=limit; i>0; i--) {

which doesnt test candle 0 (i>0) and avoid unnecessary loop (limit)

Reason: