"Ghost" Indicator

To add comments, please log in or register
Forex Trader
114514
Forex Trader  
This is an indicator which simply displays the previous weekdays high and low as horizontal lines, the length of which is input by the user. The indicator is working about 90%. Sometimes when I switch from one timeframe to another a "shadow" horizontal line appears to the left of the correct indicator which is aligned on the right hand side of the chart. In the main, this seems to happen when switching to a lower timeframe for the 1st time.


//+------------------------------------------------------------------+
//|                                                  PrevDayHiLo.mq4 |
//|                                        Tyrone Faulkner - May 2007|
//|                        Show the High and Low for the previous day|
//+------------------------------------------------------------------+
#property copyright "Tyrone Faulkner"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightBlue
#property indicator_color2 Salmon

//---- Input Parms
extern int HiLoMarker=30;

//---- buffers
double DayHi[];
double DayLo[];

//---- Global variables
double dHigh = 0.000000, dLow = 999999.999999;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,DayHi);
   SetIndexDrawBegin(0,0);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,DayLo);
   SetIndexDrawBegin(1,0);  
//----
   int counted_bars=IndicatorCounted();
   int pos;
//---- check for possible errors
   if (counted_bars<0) return(-1);
//----
   datetime dayChk = TimeDayOfWeek(Time[0]);
   datetime dayChkHld;
   
//---- Find previous days high and low

   for(pos=1;pos<Bars;pos++)
     {
       dayChkHld = TimeDayOfWeek(Time[pos]);
       if (dayChkHld != dayChk && dayChkHld != 0 && dayChkHld != 6) //---- Find previous day which is not a Saturday or Sunday
          { 
           if(High[pos] > dHigh) dHigh = High[pos];
           if(Low[pos] < dLow) dLow = Low[pos];
             if(TimeDayOfWeek(Time[pos+1]) != dayChkHld) pos = Bars; //---- Test for end of previous day
          }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//---- Put your code here
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int pos;
   if (counted_bars == 0) pos = HiLoMarker-1;
   else pos = Bars - counted_bars - 1;         
   while(pos>=0)
     {
         DayHi[pos] = dHigh;
         DayLo[pos] = dLow;
         if (counted_bars>0)  //---- Roll the High Low markers forward.
         {
            DayHi[pos+HiLoMarker] = EMPTY_VALUE;
            DayLo[pos+HiLoMarker] = EMPTY_VALUE;
         }
         pos--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+


To add comments, please log in or register