Trying my first Indicator. Any Support is really appreciated. Code Attachhed.

 

Hi, this is my first indicator and I'm struggling to resolve an error. Any help is really appreciated to get me started.

I get the last 100 Bars on USDCAD and the last 100 Bars on EURUSD and I am tryting to find the ratio by dividing the USDCAD timeseries by the EURUSD timeseries.

However, for some reason on the final data point on the Indicator Plot, the drawing is plotted at zero. (Attached).

Goes to Zero


int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,RatioPriceBuffer,INDICATOR_DATA);
//--- don't show indicator data in DataWindow
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,clrRed);

//---
   return(INIT_SUCCEEDED);
  }

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[])
  {
   double longSeries[];
   double shortSeries[];
   double ratioPriceSeries[];
   int result;

   result=CopyClose("USDCAD",PERIOD_H4,1,100,longSeries);
   if(result==-1)
     {
      Print("Error: ",GetLastError());
     }
   else
     {
      //Print("Succeeded");
     }

   result=CopyClose("EURUSD",PERIOD_H4,1,100,shortSeries);
   if(result==-1)
     {
      Print("Error: ",GetLastError());
     }
   else
     {
      //Print("Succeeded");
     }

   ArrayResize(ratioPriceSeries,100);
   for(int i=0; i<100; i++)
     {
      ratioPriceSeries[i]=longSeries[i]/shortSeries[i];
      //Print("Price Long: ",i,"  - ",longSeries[i]);
      //Print("Price Short: ",i,"  - ",shortSeries[i]);
      //Print("Ratio Series: ",ratioPriceSeries[i]);
      RatioPriceBuffer[i]=ratioPriceSeries[i];
     }

//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 

Hi please study the examples provided with the platform.

//+------------------------------------------------------------------+
//| 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 limit;
   if(prev_calculated==0)
     {
      limit=0;
     }
   else
     {
      limit=prev_calculated-1;
     }
//--- calculate value
   for(int i=limit;i<rates_total && !IsStopped();i++)
     {
      //--- do some calculations here...  


      SomeBuffer[i]=high[i];// <-- assign some value to the buffer here,
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: