indicator problem in calculation

 

Hi guys i try  to create a indicator that calculate a CCI  over the ratio of 2 instruments

i code this

//+------------------------------------------------------------------+
//|                                                     CCI_Ratio.mq4 |
//|                        Expert Advisor created by Senior Developer|
//|                                  Istruzioni: inserisci il codice  |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White

// Definisci i parametri di ingresso
input string Cross1 = "EURUSD";
input string Cross2 = "GBPUSD";
input int    CCIPeriod = 14;

// Buffer per CCI
double cciBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Assegna buffer per il valore CCI
   SetIndexBuffer(0, cciBuffer);
   // Nome del buffer indicatore
   IndicatorShortName("CCI Ratio (" + Cross1 + " / " + Cross2 + ") CCI(" + CCIPeriod + ")");
   
   // Disegna livelli tratteggiati a +6, -6, +10, -10, +30 e -30
   DrawDashedLevel(6, clrDodgerBlue);
   DrawDashedLevel(-6, clrDodgerBlue);
   DrawDashedLevel(10, clrDodgerBlue);
   DrawDashedLevel(-10, clrDodgerBlue);
   DrawDashedLevel(30, clrDodgerBlue);
   DrawDashedLevel(-30, clrDodgerBlue);
   
   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[])
  {
   // Calcola i valori CCI basati sul ratio dei prezzi di chiusura delle due coppie.
   int start = 0; // Inizia dalla candela zero
   if(prev_calculated > 0) start = prev_calculated - 1;

   for(int i=start; i<rates_total; i++)
     {
      double Close1 = iClose(Cross1, 0, i);
      double Close2 = iClose(Cross2, 0, i);
      
      if (Close2 == CCIPeriod ) continue;
      
      double Ratio = Close1 / Close2;

      // Calcolo del CCI per il ratio
      cciBuffer[i] = iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, i) * Ratio;

      // Ridimensionamento dell'oscillazione del CCI tra +2 e -2
      cciBuffer[i] = (cciBuffer[i] / 300.0) * 2.0;
     }

   return(rates_total);
  }

//+------------------------------------------------------------------+
//| Funzione per disegnare un livello tratteggiato                   |
//+------------------------------------------------------------------+
void DrawDashedLevel(double level, color clr)
{
   ObjectCreate("Level" + DoubleToStr(level, 2), OBJ_HLINE, 0, Time[0], level);
   ObjectSetInteger(0, "Level" + DoubleToStr(level, 2), OBJPROP_COLOR, clr);
   ObjectSetInteger(0, "Level" + DoubleToStr(level, 2), OBJPROP_STYLE, STYLE_DOT);
   ObjectSetInteger(0, "Level" + DoubleToStr(level, 2), OBJPROP_WIDTH, 1);
}

but i dont know  why  give me always  the same  line also if i change input  cross  anyone  can help me ? thanks

 

Hi

I am not sure what you wanted to do here, but perhaps you don’t have the data from those chosen instruments and you get NULL from them. That’s why you don’t have different results. Besides that why you compare value of close price from Cross2 with CCIPeriod, that does not make sense.

Make sure that you have data available and correct close prices returned from  the chart.  It works perfectly fine for me – so you have to had some problems with data for chosen symbols.

Best Regards