Help with buggy indicator

 

For some time I have been using an indicator that I found in a forum. I has two little quirks that I have been unable to solve.

1. from time to time there are arrows just randomly displayed all over the chart.

2. to fix the problem above I have been just bringing up the indi properties and hitting "reset", that solves 1 but it also clears other manually created objects off the chart i.e. trendlines.

The code (below) seems pretty simple but I am at a loss as to what is causing the problems.

Any suggestions???

thanks,

dave


//+------------------------------------------------------------------+
//|                                                       LJ_SIG.mq4 |
//|                       Copyright ?2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1

extern int count = 1000;

double sig_up[];
double sig_down[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
      SetIndexBuffer(0,sig_up);
      SetIndexBuffer(1,sig_down);
      
      SetIndexStyle(0,DRAW_ARROW);
      SetIndexArrow(0, 225);
      SetIndexStyle(1,DRAW_ARROW);
      SetIndexArrow(1, 226);  
      
      SetIndexEmptyValue(0,0.0);
      SetIndexEmptyValue(1,0.0);
  
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//   int    counted_bars=IndicatorCounted();
//----
   
   double ha_open = 0.0;
   double ha_close = 0.0;
   double ha_high = 0.0;
   double ha_low = 0.0;
   
   double tdi_green = 0.0;
   double tdi_red = 0.0;
   double tdi_yellow = 0.0;
   
   for (int i = 0; i< count; i++){
      
      tdi_green = iCustom(NULL, 0, "Traders Dynamic Index VISUAL ALERTS", 4, i);
      tdi_red = iCustom(NULL, 0, "Traders Dynamic Index VISUAL ALERTS", 5, i);
      tdi_yellow = iCustom(NULL, 0, "Traders Dynamic Index VISUAL ALERTS", 2, i);
   
      ha_open = iCustom(NULL, 0, "HeikenAshi_DM", 2, i);
      ha_close = iCustom(NULL, 0, "HeikenAshi_DM", 3, i);
   
      if (ha_open < ha_close){
         
         ha_high = iCustom(NULL, 0, "HeikenAshi_DM", 1, i);
         ha_low = iCustom(NULL, 0, "HeikenAshi_DM", 0, i);
         
         if ((ha_close >= iMA(NULL, 0, 5, 0, MODE_SMMA, PRICE_HIGH, i) - 3* Point )
            && ( tdi_green > 50 ) && ( tdi_green > tdi_red ) && ( tdi_green > tdi_yellow ) )
         {
            
            sig_up[i] = iMA(NULL, 0, 5, 0, MODE_SMMA, PRICE_LOW, i) - 20* Point;
            
         }
         
      }
      else{
      
         ha_high = iCustom(NULL, 0, "HeikenAshi_DM", 0, i);
         ha_low = iCustom(NULL, 0, "HeikenAshi_DM", 1, i);
         
         if ((ha_close <= iMA(NULL, 0, 5, 0, MODE_SMMA, PRICE_LOW, i) + 3* Point)
            && ( tdi_green < 50 ) && ( tdi_green < tdi_red ) && ( tdi_green < tdi_yellow ) )
         {
            
            sig_down[i] = iMA(NULL, 0, 5, 0, MODE_SMMA, PRICE_HIGH, i) + 20* Point;
            
         }
         
      }
      
   }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
bdeyes:

For some time I have been using an indicator that I found in a forum. I has two little quirks that I have been unable to solve.

1. from time to time there are arrows just randomly displayed all over the chart.

2. to fix the problem above I have been just bringing up the indi properties and hitting "reset", that solves 1 but it also clears other manually created objects off the chart i.e. trendlines.

The code (below) seems pretty simple but I am at a loss as to what is causing the problems.

Any suggestions???

thanks,

dave

Just change timeframe/period and then change back . . . I have seen a similar thing with one of my Indicators, I'm pretty sure it is when more data is downloaded, for example if you scroll the chart right so new data has to be fetched and the Bars value increases.
 
RaptorUK:
Just change timeframe/period and then change back . . . I have seen a similar thing with one of my Indicators, I'm pretty sure it is when more data is downloaded, for example if you scroll the chart right so new data has to be fetched and the Bars value increases.

Hey thanks for the tip.

After considering your suggestion I decided to change the bar count to see if I could prove your theory.

I have a couple of other indi's I run with this that I only have in an ex4 version, so to restrict their calculation cycle I just run the chart with a limited max bars.

Since the difference between the total bars on the chart and the count limit in this indi wasn't all that much, I though why not just run this on all the bars in the chart.

So I un-commented the counted_bars and substituted counted_bars for the count variable and it has been working great for the past 2 days.


thanks,

dave