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)
Even 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:
But I really could not find the solution to it....Please help
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.
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]?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!