Need help to improve my indicator

 

I have developed an indicator that doesn't work properly. I highly appreciate if someone can fix it.

This indicators shows buy arrow (Up arrow) when the daily high is higher than the highest of last five days, and likewise, it shows Sell arrow ( Down arrow) when the daily low is lower than the lowest of last five days. It should keep the direction if the the daily high or low doesn't break the high or low of the last five days.

Here is the code:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_width1 0
#property indicator_width2 0
#property indicator_color1 clrLimeGreen
#property indicator_color2 clrOrangeRed

double buffBuy[];
double buffSell[];
int cb = 0;
int bar ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int draw = 0;
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexEmptyValue(0,0.0);
   SetIndexLabel(0,"Buy");
   SetIndexLabel(1,"Sell");
   SetIndexDrawBegin(0,draw);
   SetIndexDrawBegin(1,draw);
   SetIndexBuffer(0,buffBuy);
   SetIndexBuffer(1,buffSell);
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0,OBJ_ARROW);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int IndicatorCounted = cb;
   if (bar == Time[0]) return(0);
   int x;
   if(Bars<=100) return(0);
   if (cb<0) return(-1);
   if (cb>0) cb--;
   x=Bars-cb;
   int j=6;
   for(int i=x-6; i<x; i--)
   {
    if (iLow(NULL,PERIOD_D1,i)<iLowest(NULL,PERIOD_D1,MODE_LOW,j,i))
         {j=6;
          buffSell[i] = High[i]+200*Point;}
          
    if (iHigh(NULL,PERIOD_D1,i)>iHighest(NULL,PERIOD_D1,MODE_HIGH,j,i))
         {j=6;
          buffBuy[i] = Low[i]-200*Point;}
         
    else j=j+1;      
         

   } 
   return(0);  
   }
//+------------------------------------------------------------------+
 
mjstock78:

I have developed an indicator that doesn't work properly. I highly appreciate if someone can fix it.

This indicators shows buy arrow (Up arrow) when the daily high is higher than the highest of last five days, and likewise, it shows Sell arrow ( Down arrow) when the daily low is lower than the lowest of last five days. It should keep the direction if the the daily high or low doesn't break the high or low of the last five days.

Here is the code:

iLow()

Returns Low price value for the bar of indicated symbol with timeframe and shift.

Meaning this is a double price value.

However,

iLowest()

Returns the shift of the lowest value over a specific number of bars depending on type.

Meaning this is an integer bar number, you still need to access the Low array to read the price value from that particular bar.


You are essentially saying:

if(Low[i] is < lower then the bar number from the Low Array that is containing the lowest value)

Which makes no sense at all.

 
Marco vd Heijden:

Returns Low price value for the bar of indicated symbol with timeframe and shift.

Meaning this is a double price value.

However,

Returns the shift of the lowest value over a specific number of bars depending on type.

Meaning this is an integer bar number, you still need to access the Low array to read the price value from that particular bar.


You are essentially saying:

if(Low[i] is < lower then the bar number from the Low Array that is containing the lowest value)

Which makes no sense at all.

Thanks Marco for pointing out my dumb mistake :)

What if I say : (iLow(NULL,PERIOD_D1,i)<iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,j,i)))

 
mjstock78:

Thanks Marco for pointing out my dumb mistake :)

What if I say : (iLow(NULL,PERIOD_D1,i)<iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,j,i)))

      if(iLow(Symbol(),PERIOD_D1,i)<iLow(Symbol(),PERIOD_D1,iLowest(Symbol(),PERIOD_D1,MODE_LOW,WHOLE_ARRAY,0)))
       {
        //Do Something...
       }
 
Marco vd Heijden:
I replaced the line into my code but unfortunately it didn't work. Any suggestion?!
 
mjstock78:
I replaced the line into my code but unfortunately it didn't work. Any suggestion?!
Exactly what does not work ?
 
Marco vd Heijden:
Exactly what does not work ?
It doesn't show any sell or buy arrow.
 
input int Period=6;
//---
int start()
  {
   if(Bars<=100)
      return(0);
   static datetime buy,sell;
   int cb=IndicatorCounted();
   int begin=(cb<1)?Bars-Period+1:Bars-cb;
   for(int i=begin;i>=0;i--)
     {
      if(sell!=Time[i] && iLow(NULL,PERIOD_D1,i)<iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,Period,i+1)))
        {
         buffSell[i]=High[i]+200*Point;
         sell=Time[i];
        }
      else if(sell!=Time[i])
         buffSell[i]=0.0;
//---
      if(buy!=time[i] && iHigh(NULL,PERIOD_D1,i)>iHigh(NULL,PERIOD_D1,iHighest(NULL,PERIOD_D1,MODE_HIGH,Period,i+1)))
        {
         buffBuy[i]=Low[i]-200*Point;
         buy=Time[i];
        }
      else if(buy!=Time[i])
         buffBuy[i]=0.0;
     }
  }
 
Ernst Van Der Merwe:
Thanks Ernst, as always, you fixed the code perfectly. The only issue is that on some bars that the high/low of the bar is not breaking out, the arrow is not being showed, while these type of bars should carry the previous direction of arrow either if it was Sell or Buy. I appreciate if you can fix this issue as well.
 
mjstock78:
Thanks Ernst, as always, you fixed the code perfectly. The only issue is that on some bars that the high/low of the bar is not breaking out, the arrow is not being showed, while these type of bars should carry the previous direction of arrow either if it was Sell or Buy. I appreciate if you can fix this issue as well.
      if(sell!=Time[i] && Low[i]<iLow(NULL,PERIOD_D1,iLowest(NULL,PERIOD_D1,MODE_LOW,Period-1,i+1)))
        {
         buffSell[i]=High[i]+200*Point;
         sell=Time[i];
        }
      else if(sell!=Time[i])
         buffSell[i]=0.0;
 
Ernst Van Der Merwe:
Thanks Ernst but it didn't work, still there are bars without any arrow.
Reason: