Body length filter Problem

 
hello everyone, I have inserted a "Doji" candle filter to previous arrow signal.
The body of the candle must be above 0.3 pips and it works, but sometimes it happens that in the historic this filter does not work.

I've been wrong a few line of code?


It could be the "for" loop to bother to filter "Doji"?


Thank you


#property copyright ""
#property link      ""
#property version   ""
#property description ""

#include <stdlib.mqh>
#include <stderror.mqh>

//--- indicator settings
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 1
#property indicator_color1 0xFFAA00
#property indicator_label1 ""

#property indicator_type2 DRAW_ARROW
#property indicator_width2 1
#property indicator_color2 0x0000FF
#property indicator_label2 ""

//--- indicator buffers
double Buffer1[];
double Buffer2[];

extern double Doji = 0.3;
datetime time_alert; //used when sending alert
bool Audible_Alerts = true;
double myPoint; //initialized in OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | RSInoRepaint @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      if(Audible_Alerts) Alert(type+" | RSInoRepaint @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexArrow(0, 242);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexArrow(1, 241);
   //initialize myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   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 = rates_total - prev_calculated;
   //--- counting from 0 to rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
     }
   else
      limit++;
   
   //--- main loop
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation   
      //Indicator Buffer 1
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) > 80 //Relative Strength Index > fixed value
      && MathAbs(Open[1+i] - Close[1+i]) > Doji * myPoint //Candlestick Body > fixed value
      )
        {
         Buffer1[i] = Close[i] + 3 * myPoint; //Set indicator value at Candlestick Close + fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", ""); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer1[i] = 0;
        }
      //Indicator Buffer 2
      if(iRSI(NULL, PERIOD_CURRENT, 2, PRICE_CLOSE, i) < 20 //Relative Strength Index < fixed value
      && MathAbs(Open[1+i] - Close[1+i]) > Doji * myPoint //Candlestick Body > fixed value
      )
        {
         Buffer2[i] = Close[i] - 3 * myPoint; //Set indicator value at Candlestick Close - fixed value
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", ""); time_alert = Time[0]; } //Instant alert, only once per bar
        }
      else
        {
         Buffer2[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
  1. fly7680: but sometimes it happens that in the historic this filter does not work
    "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Print out your variables, and find out why.
  3.    for(int i = limit-1; i >= 0; i--){
          if (i >= MathMin(5000-1, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
    Do your lookbacks correctly.
 

Thanks WHRoederI apologize if I expressed myself badly, but I am a beginner and I'm trying to understand the MQL4 language and still are not as good as you.


I will study better what you have suggested.

thank you
Thank you

Reason: