Down Arrow on current Bar High if High[i] > High[iHighest(NULL,0,MODE_HIGH,50,0)]

 
//+------------------------------------------------------------------+
//|                                                 Pinbarsiraj2.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 3
#property indicator_width2 3


extern double   bmi=33.0;
extern int   minSize=20.0;
double up[];
double down[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {bmi*=0.01;
//--- indicator buffers mapping
   SetIndexBuffer (0,up);
   SetIndexStyle (0,DRAW_ARROW);
   SetIndexArrow (0,233);
   SetIndexLabel (0,"UP ARROW");
   
   SetIndexBuffer (1,down);
   SetIndexStyle (1,DRAW_ARROW);
   SetIndexArrow (1,234);
   SetIndexLabel (1,"DOWN ARROW");
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
      int limit = MathMax(rates_total-prev_calculated,2);
      for ( int i=1; i<limit; i++ )
      {
      double total = High[i]-Low[i];
      double body = MathAbs(Open[i]-Close[i]);
      double maxSize=total*bmi;
      double H=High[iHighest(NULL,0,MODE_HIGH,20,0)];
      double L=Low[iLowest(NULL,0,MODE_LOW,20,0)];
      
      if(body<maxSize && total>minSize*Point 
      &&Open[i]<Close[i]
      &&High[i]-Open[i]<maxSize
      &&Low[i]<Low[1+i]
      &&Low[i]<Low[iLowest(NULL,0,MODE_LOW,20,0)])
      up[i]=Low[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]>Close[i]
      &&High[i]-Close[i]<maxSize
      &&Low[i]<Low[1+i]
      &&Low[i]<Low[iLowest(NULL,0,MODE_LOW,20,0)])
      up[i]=Low[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]>Close[i]
      &&Open[i]-Low[i]<maxSize
      &&High[i]>High[1+i]
      &&High[i]>High[iHighest(NULL,0,MODE_HIGH,20,0)])
      down[i]=High[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]<Close[i]
      &&Close[i]-Low[i]<maxSize
      &&High[i]>High[1+i]
      &&High[i]>High[iHighest(NULL,0,MODE_HIGH,20,0)])
      down[i]=High[i];
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hello Coders, please help to modify my code in such that the Arrow only appears if the condition for High and Low is met, which is if High[i] is more then the Highest high among last 50 bars and vice versa for Low.

Thanks!

 
      int limit = MathMax(rates_total-prev_calculated,2);
      for ( int i=1; i<limit; i++ )
      {
      double total = High[i]-Low[i];
      double body = MathAbs(Open[i]-Close[i]);
      double maxSize=total*bmi;
      double H=High[iHighest(NULL,0,MODE_HIGH,20,0)];
      double L=Low[iLowest(NULL,0,MODE_LOW,20,0)];

Is there a reason that you are using values of the most recent 20 bars when you are calculating with Bar[i]?



      double L=Low[iLowest(NULL,0,MODE_LOW,20,0)];
&&Low[i]<Low[iLowest(NULL,0,MODE_LOW,20,0)])

You have already calculated the value, why re-calculate it?

&&Low[i]<L)
 

MUST BE HIGHER THEN LAST 50 BARS HIGHEven if I have change according to your suggestion, still the result is not what I expected

//+------------------------------------------------------------------+
//|                                                 Pinbarsiraj2.mq4 |
//|                        Copyright 2017, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_width1 3
#property indicator_width2 3


extern double   bmi=33.0;
extern int   minSize=20.0;
double up[];
double down[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {bmi*=0.01;
//--- indicator buffers mapping
   SetIndexBuffer (0,up);
   SetIndexStyle (0,DRAW_ARROW);
   SetIndexArrow (0,233);
   SetIndexLabel (0,"UP ARROW");
   
   SetIndexBuffer (1,down);
   SetIndexStyle (1,DRAW_ARROW);
   SetIndexArrow (1,234);
   SetIndexLabel (1,"DOWN ARROW");
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
      int limit = MathMax(rates_total-prev_calculated,2);
      for ( int i=1; i<limit; i++ )
      {
      double total = High[i]-Low[i];
      double body = MathAbs(Open[i]-Close[i]);
      double maxSize=total*bmi;
      double H=High[iHighest(NULL,0,MODE_HIGH,20,0)];
      double L=Low[iLowest(NULL,0,MODE_LOW,20,0)];
      
      if(body<maxSize && total>minSize*Point 
      &&Open[i]<Close[i]
      &&High[i]-Open[i]<maxSize
      &&Low[i]<Low[1+i]
      &&Low[i]<L)
      up[i]=Low[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]>Close[i]
      &&High[i]-Close[i]<maxSize
      &&Low[i]<Low[1+i]
      &&Low[i]<L)
      up[i]=Low[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]>Close[i]
      &&Open[i]-Low[i]<maxSize
      &&High[i]>High[1+i]
      &&High[i]>H)
      down[i]=High[i];
      
      else if(body<maxSize && total>minSize*Point 
      &&Open[i]<Close[i]
      &&Close[i]-Low[i]<maxSize
      &&High[i]>High[1+i]
      &&High[i]>H)
      down[i]=High[i];
      }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
SIRAJ Multani:

Even if I have change according to your suggestion, still the result is not what I expected


You have changed the repeated calculations. You have not addressed my previous question

      int limit = MathMax(rates_total-prev_calculated,2);
      for ( int i=1; i<limit; i++ )
      {
      double total = High[i]-Low[i];
      double body = MathAbs(Open[i]-Close[i]);
      double maxSize=total*bmi;
      double H=High[iHighest(NULL,0,MODE_HIGH,20,0)];
      double L=Low[iLowest(NULL,0,MODE_LOW,20,0)];

Is there a reason that you are using values of the most recent 20 bars when you are calculating with Bar[i]?

Also you are calculating for a 20 bar period not 50 as you seem to expect. Don't hard code 20 use an input variable.
 
Keith Watford:

You have changed the repeated calculations. You have not addressed my previous question

Also you are calculating for a 20 bar period not 50 as you seem to expect. Don't hard code 20 use an input variable.
But I really could not find the solution to it....Please help
 
He already told you what the problem is. Fix it.
Keith Watford: Is there a reason that you are using values of the most recent 20 bars when you are calculating with Bar[i]?
Reason: