Need Help with my first indicator

 

I'm trying to write an indicator but it has the following problems:
1- Has a redraw factor of 3. (repaints the last few bars.)
2- Doesn't draw the past correctly.
3- Doesn't seem to match the CCI indicator.

It's my first indicator. Any help is appreciated.

Thanks.


Sorry... Now it can be compiled..


#property copyright "xxx"
#property link "xxx.com"

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 2.0
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 White

extern int WingDingStyle = 110;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];


bool shouldBuy;
  bool    shouldSell;
// External variables

extern bool SignalOnClosedBar=true;

extern int CCI_Period=14;
extern int CCIbuyLevel=30;
extern int CCIsellLevel=-30;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

// Global variables

int current;

// Init function
int init()
  {
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, WingDingStyle);
   
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, WingDingStyle);
   
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(2, DRAW_ARROW, EMPTY);
   SetIndexArrow(2, WingDingStyle);
   
   IndicatorShortName("My Indicator "+iCCI(NULL,0,CCI_Period,PRICE_CLOSE,current));
  

   return (0);///
  }
  
  
// Start function
int start()
  {
// Signal on bar close?
   current=0;
   if(SignalOnClosedBar)
     {
      current=1;
     }

     
// Should I buy or sell?
   determineCondition();

// Draw
//-----------------------------------------------------------------------------
   
   int counted_bars=IndicatorCounted();
   int limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   
   for (int i=limit;i>=0;i--) 
   {
   ExtMapBuffer1[i] = EMPTY_VALUE;
   ExtMapBuffer2[i] = EMPTY_VALUE;
   ExtMapBuffer3[i] = EMPTY_VALUE;
   
      if (shouldBuy) 
      {
         ExtMapBuffer1[i] = 1.0;
      } else if (shouldSell) 
        {
        ExtMapBuffer2[i] = 1.0;
        } else
          {
          ExtMapBuffer3[i] = 1.0;
          }
      
   }
//-----------------------------------------------------------------------------

   return(0);
  }
  
  
  
int determineCondition()
  {

// Check conditions

      shouldBuy=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,current)>CCIbuyLevel;
      shouldSell=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,current)<CCIsellLevel;
  
   return (0);///
  }
  
  
//+------------------------------------------------------------------+
Files:
 

first, if it's your first indicator why not use the new MQL method

second, your indicator cannot be compiled

 
qjol:

first, if it's your first indicator why not use the new MQL method

second, your indicator cannot be compiled


What's the new MQL method? Use OnStart() instead of Start()? What else should I do?

BTW, I edited my post. Now it does compile.

 
syberia_poya:

What's the new MQL method? Use OnStart() instead of Start()? What else should I do?


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 determineCondition()
  {

// Check conditions

      shouldBuy=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,current)>CCIbuyLevel;
      shouldSell=iCCI(NULL,0,CCI_Period,PRICE_CLOSE,current)<CCIsellLevel;
  
   return (0);///
  }
  
  

current is either 1 or zero

So you not doing calculations based on the value of i in your loop

Reason: