Problem with a simple indicator

 

Hello, here is a simple EA I wrote working along a custom indicator I also wrote.


EA

double Lots;
//double UBand, MBand, LBand; 
double SMASlope;
 
int init()
  {
 
   return(0);
  }
  
int deinit()
  {
//----
   
//----
   return(0);
  }
  
int start()
  {
  
//----
   Lots = (MathCeil((AccountBalance()/500))/10);
//   UBand = iBands(Symbol(),Period(),20,2,NULL,PRICE_CLOSE,MODE_UPPER,0);
//   MBand = iBands(Symbol(),Period(),20,2,NULL,PRICE_CLOSE,MODE_MAIN,0);
//   LBand = iBands(Symbol(),Period(),20,2,NULL,PRICE_CLOSE,MODE_LOWER,0);
   SMASlope = iCustom(Symbol(), Period(), "SMA Slope", NULL, 0, 0);
   
  if (OrdersTotal()<1) //Check for open orders
  {
      if (SMASlope<0)
      {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Bid+20*Point,Bid-20*Point,"macd sample",16384,0,Green);
      }
 
      if (SMASlope>0)
      {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Ask-20*Point,Ask+20*Point,"macd sample",16384,0,Green);
      }
  }
   
   return(0);
  }


And the indicator:

#property indicator_separate_window
#property indicator_minimum -1
#property indicator_maximum 1
#property indicator_buffers 3
#property indicator_color1 LawnGreen
 
//---- input parameters
extern double AvgPeriod=8;
//---- buffers
double Buffer1[];
 
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buffer1);
 
//----
   return(0);
  }
  
int deinit()
  {
//----
   
//----
   return(0);
  }
  
int start()
{
 
   int    counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars;
 
   double SMA, Prev_SMA;
 
   double SlopeSum;
   double AvgSlope;
   int shift;
   //----
   for (shift = 0; shift < limit; shift++)
   {
      SMA = iMA(Symbol(),Period(),20,NULL,MODE_SMA,PRICE_CLOSE,shift);
      Prev_SMA = iMA(Symbol(),Period(),20,NULL,MODE_SMA,PRICE_CLOSE,shift+AvgPeriod);
      //---   
      SlopeSum = SMA-Prev_SMA;
    
      AvgSlope = SlopeSum/(AvgPeriod*Point*MathPow(Period(),0.5));
   
      Buffer1[shift] = AvgSlope;
           
   }
//----
   return(0);
  }


The problem is that the EA always goes long... As if the indicator always returned a value above 0, which isn't the case if I look at the line drawn on the chart by the indicator. Does anyone know what's going on?

 
Update: after printing the value of the SMASlope variable in the log, I got the value 2,147,483,647; that is the greatest value that can be stored in a signed 32bits variable!
 
Your iCustom() call does not seem to include the input parameter for the indicator.
 
phy:
Your iCustom() call does not seem to include the input parameter for the indicator.

And what could that be? I dont think my indicator expects any kind of parameter...


Edit: Nm, I got it now! By specifying NULL, my the indicator used no parameter at all, instead of using the default params... THX Phy!

Reason: