Labels aren't getting printed at runtime

 
Below is the code. It is for some reason isn't printing the labels (up and down arrows) at runtime. If I change the timeframe and comeback to the 5 minutes again I see the label getting printed. I want it to print at runtime as the candle closes and send the alert. What am I missing here?

//+------------------------------------------------------------------+
//|                                                     EMACross.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#define z (0)
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

input color buyClr = clrGreen;
input color sellClr = clrRed;
input bool showCross = true;
input int move = 20;
input int emaPeriod = 20;
input int closePercent = 75;
input double pipPercent = .13;
input bool prevCandleCheck = false;
input int maxCandleCheck = 15;
input bool showUniqueSig = false;
input bool sendAlert = true;
input bool checkFourthCandle = true;
input bool checkForCandleCount = true;
input int dominantCandleNumber = 10;
int barIndex = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  
   int totalObjects  = ObjectsTotal();
//--- indicator buffers mapping
   
//---
   for(int iTotal=totalObjects - 1 ;  iTotal >= 0 ;  iTotal-- ) {
      
      //printf("Object Type"+ObjectType(iTotal));
      if(StringFind(ObjectName(iTotal),"DownArr",0) != -1 || StringFind(ObjectName(iTotal),"UpArr",0) != -1){
      
         ObjectDelete(ObjectName(iTotal));
      }
      
      //ObjectDelete(ObjectName(iTotal));
      
   }
   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 start()
  {
  
  //s = IntegerToString(barIndex);
   //int counted_bars = prev_calculated > 0 ? prev_calculated - 1 : 0;
   //int limit = rates_total - 1 - counted_bars ;
   //int limit = rates_total - 1;
   int counted_bars=IndicatorCounted();
   int limit=Bars-counted_bars;
   //if (rates_total == prev_calculated) return(rates_total);

   //int limit = rates_total - 1;
   /*int counted_bars = IndicatorCounted();

if (counted_bars < 0) 
    counted_bars = 0;

if (counted_bars > 0) 
    counted_bars--;

int limit = Bars - counted_bars;*/
   
   double hgh;
   double lw;
   double opn;
   double cls;
   double pos;
   double length;
   double pip;
   string s;
   double ema;
   bool trigger = false;
   string prevSignal = "NA";
   
   int white = 0;
   int black = 0;
   color clrTrade = clrBlack;
   //bool isWeak = false;
   
   if(showCross){
   
      //for(int i=limit-1; i>=1; i--) {
   
      for(int i=1; i<=limit; i++) {
      ema = iMA(NULL,0,emaPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      opn = open[i];
      cls = close[i];
      hgh = high[i];
      lw = low[i];
      
      pip = (cls * pipPercent)/100;
      
      length = hgh - lw;
      length = (length * closePercent)/100;
      
      if(prevCandleCheck == false){
      
         trigger = true;
      }
      
      if(cls > opn){    
         
         pos = lw + length;
         
         if(length >= pip && cls >= pos && (opn < ema || lw < ema) && cls > ema){
         
         if(prevCandleCheck){         
            
            for (int k = 0; k < maxCandleCheck; k++){
            
             opn = open[i+k];
             cls = close[i+k];
             if(cls > opn){
               
               white++;
             }
            //if(ArraySize(open) <15 || ArraySize(close) <15)break;
               if(k >= maxCandleCheck -2){
               
                  continue;
               }
            
               opn = open[i+k];
               cls = close[i+k];
               
               if(cls > opn){
               
                  opn = open[i+(k+1)];
                  cls = close[i+(k+1)];
                  
                  if(cls > opn){
               
                     opn = open[i+(k+2)];
                     cls = close[i+(k+2)];
                     
                     if(cls > opn){
                        
                        if(checkFourthCandle){
                        
                           opn = open[i+(k+3)];
                           cls = close[i+(k+3)];
                        
                           if(cls > opn){
                        
                              trigger = true;
                              clrTrade = clrGreen;
                              break;
                           }
                        }else{
                        
                           trigger = true;
                           clrTrade = clrGreen;
                           break;
                        }                        
                                                
                     }
                  }
               }
            }
         }
         
            if(checkForCandleCount && trigger == false){
            
               if(white >= dominantCandleNumber){
               
                  trigger = true;
                  clrTrade = clrBlack;
               }
               
               white = 0;
            }
            
            if(trigger){
            
               if(showUniqueSig && prevSignal == "green"){
               
                  trigger = false;
               }else{
            
                  prevSignal = "green";
                  //ObjectDelete("UpArr"+s);
                  ObjectCreate("UpArr"+IntegerToString(barIndex),OBJ_ARROW,z,Time[i],Low[i]-1.5 * (move*_Point));
                  ObjectSet("UpArr"+IntegerToString(barIndex),OBJPROP_ARROWCODE,233);
                  ObjectSet("UpArr"+IntegerToString(barIndex), OBJPROP_COLOR, clrTrade);
                  trigger = false;
                  barIndex++;
                  if(i == 1 && sendAlert){
                  
                     SendAlert("BUY");
                  }
               }
            
               
            }           
            
         }
      }else if(cls < opn){
         pos = hgh - length;
         
         if(length >= pip && cls <= pos && (opn > ema || hgh > ema) && cls < ema){
         
            if(prevCandleCheck){
         
            for (int j = 0; j < maxCandleCheck; j++){
            
               opn = open[i+j];
               cls = close[i+j];
               if(cls < opn){
               
                  black++;
               }
               //if(ArraySize(open) <15 || ArraySize(close) <15)break;
               if(j >= maxCandleCheck -2 ){
               
                  continue;
               }
               
               
               
               if(cls < opn){
               
                  opn = open[i+(j+1)];
                  cls = close[i+(j+1)];
                  
                  if(cls < opn){
               
                     opn = open[i+(j+2)];
                     cls = close[i+(j+2)];
                     
                     if(cls < opn){
                        
                        if(checkFourthCandle){
                        
                           opn = open[i+(j+3)];
                           cls = close[i+(j+3)];
                        
                           if(cls < opn){
                        
                              trigger = true;
                              clrTrade = clrRed;
                              break;
                           }     
                        }else{
                           
                           trigger = true;
                           clrTrade = clrRed;
                           break;
                        }
                                           
                     }
                  }
               }
            }
         }
            if(checkForCandleCount && trigger == false){
            
               if(black >= dominantCandleNumber){
               
                  trigger = true;
                  clrTrade = clrBlack;
               }
               
               black = 0;
            }
            
            if(trigger){
            
               if(showUniqueSig && prevSignal == "red"){
               
                  trigger = false;
               }else{
            
                  prevSignal = "red";
                  //ObjectDelete("DownArr"+s);
                  ObjectCreate("DownArr"+IntegerToString(barIndex),OBJ_ARROW,z,Time[i],High[i]+1.5 * (move*_Point));
                  ObjectSet("DownArr"+IntegerToString(barIndex),OBJPROP_ARROWCODE,234);
                  ObjectSet("DownArr"+IntegerToString(barIndex), OBJPROP_COLOR, clrTrade);
                  trigger = false;
                  barIndex++;
                  if(i == 1 && sendAlert){
                  
                     SendAlert("SELL");
                  }
               }
               
               
            }            
         }
      }
   }
   }
   
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
   //return(0);
  }
  
 void SendAlert(string trade){
   
   Alert(trade+" on " , Symbol(), " : ", TimeCurrent());
 }
 
 bool areThreeWhite(bool &opn[], bool &cls[], int i){
 
   bool present = false;
   
   return present;
 }
 
 bool areThreeBlack(bool &opn[], bool &cls[], int i){
 
   bool present = false;
   
   return present;
 }

//+------------------------------------------------------------------+


 
Dhabaleswar Jena:

Do not double post!

I have deleted your duplicated topic.

 
  1.    int counted_bars=IndicatorCounted();
       int limit=Bars-counted_bars;
       ⋮
          for(int i=1; i<=limit; i++) {

    First run IC is zero, limit==Bars, you access arrays[Bars], indicator crashes.

    You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
              Event Handling Functions - MQL4 Reference
              How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)

  2.              opn = open[i+k];
                 cls = close[i+k];

    In MT4, buffers and the predefined arrays are all ordered AsSeries. There is a difference between the arrays passed to OnCalculate (e.g. low[]) and the MT4 predefined variables (e.g. Low[].) The passed arrays have no default direction, just like MT5.

    To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference

 

Keith Watford #:

Dhabaleswar Jena:


Do not double post!

I have deleted your duplicated topic.

Despite this, you have started another new topic!

I have deleted that as well!

If you start another new topic with the same issue, you can expect a ban.

Reason: