Download MetaTrader 5
To add comments, please log in or register
Download documentation as one file. It is easy!
Reza Ebrahimi
242
Reza Ebrahimi 2014.07.09 16:15 

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:
qjol
3243
qjol 2014.07.09 16:57  

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

second, your indicator cannot be compiled

Reza Ebrahimi
242
Reza Ebrahimi 2014.07.09 17:05  
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.

qjol
3243
qjol 2014.07.09 18:07  
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[])
Keith Watford
Moderator
7875
Keith Watford 2014.07.09 20:05  
 
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

/
To add comments, please log in or register