Indicator not checking Bid correctly?

 
#property copyright "CVM"
#property link      "https://www.google.com"
#property version   "1.00"
#property description "Trend Following EA Using EMA and eventually HTF confluence"

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

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

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

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

datetime time_alert; //used when sending alert
double myPoint; //initialized in OnInit

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(1);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 242);
   //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);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
     }
   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
      RefreshRates();
      if(Close[1+i] > iMA(NULL, PERIOD_CURRENT, 32, 0, MODE_EMA, PRICE_CLOSE, i) //Candlestick Close > Moving Average
      && iMA(NULL, PERIOD_CURRENT, 16, 1, MODE_EMA, PRICE_CLOSE, i) < iMA(NULL, PERIOD_CURRENT, 32, 1, MODE_EMA, PRICE_CLOSE, i) //Moving Average < Moving Average
      && Bid <= Low[1+i] //Price <= Candlestick Low
      )
        {
         Buffer1[i] = Low[i]; //Set indicator value at Candlestick Low
         if(i == 1 && Time[1] != time_alert) myAlert("indicator", "Sell"); //Alert on next bar open
         time_alert = Time[1];
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Hello, im trying to get indicator to show sell arrow when bid is less than previous candlestick low , with the other ema conditions in place, can anyone assist why its showing arrows too many times when bid hasnt moved below candle [1]?

 
Vince McMahon:

Hello, im trying to get indicator to show sell arrow when bid is less than previous candlestick low , with the other ema conditions in place, can anyone assist why its showing arrows too many times when bid hasnt moved below candle [1]?

"Bid" has only the current value.

Your program checks the condition using the current Bid value, even for past bars.

 
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2.    int limit = rates_total - prev_calculated;
       ⋮
          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
    
    You can drop the convoluted code by doing your lookbacks correctly #9#14 & #19

    .
 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. You can drop the convoluted code by doing your lookbacks correctly #9#14 & #19

    .

thanks WIlliam, didnt see mt4 section the forum layout is really messy for me but i will take a look and post it there thanks

 
Nagisa Unada #:

"Bid" has only the current value.

Your program checks the condition using the current Bid value, even for past bars.

How can I correct that?

 

Don't double post! You already had this thread open.
          General rules and best pratices of the Forum. - General - MQL5 programming forum (2017)

 
Vince McMahon #:

How can I correct that?

There is no way to correctly display arrows in the past.

 
Nagisa Unada #:

There is no way to correctly display arrows in the past.

Im not trying to repaint arrows, Im trying to paint 1 arrow when price crosses below low of previous candle and is above emas. Im hopeing to make this into an EA next so the arrows are purely for debugging the signals and they are not working the way I would like yet

 
Vince McMahon #: Im not trying to repaint arrows, Im trying to paint 1 arrow when price crosses below low of previous candle and is above emas. 
  1. No one said anything about repaint.
  2. The current market Bid has nothing to do with what you want. There is no “when”, that is thinking current; Think about the past, “if” it crossed.
  3. Price crossed below the low of the previous candle, if the high was above and the new low is below.