Download MetaTrader 5

Whats wrong with this simple code?

To add comments, please log in or register
Bro840
104
Bro840  

//+------------------------------------------------------------------+
//|                                                  HistoricoBB.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_minimum -1000
#property indicator_maximum +1000
#property indicator_label1  "Historico de Dias Positivos&Negativos"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1


double Historico[]
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Historico,INDICATOR_DATA);

   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])

{
   Historico[0] = 0.00;

   for (int i= 0; i<rates_total;i++)
   {
 
         if (open[i] < close[i])
         {
               Historico[i] = Historico[i-1] + 1.00;
         }
         else if(open[i] == close[i])
         {
               Historico[i] = Historico[i-1];
         }
         else if (open[i] > close[i])
         {
               Historico[i] = Historico[i-1] -1.00;
         }
   }

   return(rates_total);
}

 

please help! it's driving me crazy :)  it shows always 0

Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Bro840
104
Bro840  

semi colon was missing on array declaration :)

To add comments, please log in or register