How can draw an arrow in the next bar with this code

 

Hi i need your help, 

I need to draw an arrow on the next bar and not on the current bar which is drawn by this indicator. What could I modify?


Many Thanks.


#property indicator_chart_window

// The number of buffers for calculation, up to 8
#property indicator_buffers 2

// The color for displaying arrows
#property indicator_color1 Green       // Long signal
#property indicator_color2 Maroon         // Short signal

// Width of the arrows
#property indicator_width1 2  // Long signal arrow
#property indicator_width2 2  // Short signal arrow

extern bool UseFullCandleSize = false;
extern int NumberOfCandles = 3;
extern int ArrowDistance = 1;

// Buffers for the calculations
double Up_Arrow_Buffer[];    // Long buffer for display
double Down_Arrow_Buffer[];   // Short buffer for display
int PipFactor = 1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   // Cater for fractional pips
   if (Digits == 3 || Digits == 5)
   {
      PipFactor = 10;
   }
//---- indicators
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexBuffer(0, Up_Arrow_Buffer);
   SetIndexArrow(0, 233); // Up arrow
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexBuffer(1, Down_Arrow_Buffer);
   SetIndexArrow(1, 234); // Down arrow
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;                           // Bar index       
   int Counted_bars;                // Number of counted bars
   //--------------------------------------------------------------------   
   Counted_bars=IndicatorCounted(); // Number of counted bars   
   i=Bars-Counted_bars-1;           // Index of the first uncounted   
   
   while(i>=0)                      // Loop for uncounted bars     
   {  
      Up_Arrow_Buffer[i] = EMPTY_VALUE;
      Down_Arrow_Buffer[i] = EMPTY_VALUE;
      
      if (isUpReversalCandle(i))
      {
         Up_Arrow_Buffer[i] = Low[i] - (ArrowDistance * Point * PipFactor);
         Down_Arrow_Buffer[i] = EMPTY_VALUE;
      }
      if (isDownReversalCandle(i))
      {
         Down_Arrow_Buffer[i] = High[i] + (ArrowDistance * Point * PipFactor);
         Up_Arrow_Buffer[i] = EMPTY_VALUE;
      }
      i--;
   }
//----
   return(0);
}

bool isUpReversalCandle(int index)
{
   if (AllDownCandles(index))
   {
      if (UseFullCandleSize)
      {
         if (High[index] - Low[index] > High[index+1] - Low[index+1])
         {
            return (true);
         }
         return (false);
      }
      else
      {
         if (Close[index] - Low[index] > Close[index+1] - Low[index+1])
         {
            return (true);
         }
         return (false);
      }
   }
   return (false);
}

bool isDownReversalCandle(int index)
{
   if (AllUpCandles(index))
   {
      if (UseFullCandleSize)
      {
         if (High[index] - Low[index] > High[index+1] - Low[index+1])
         {
            return (true);
         }
         return (false);
      }
      else
      {
         if (High[index] - Close[index] > High[index+1] - Close[index+1])
         {
            return (true);
         }
         return (false);
      }
   }
   return (false);
}

bool AllUpCandles(int index)
{
   for (int i=index; i<index+NumberOfCandles; i++)
   {
      if (!isUpCandle(i))
      {
         return (false);
      }
   }
   return (true);
}

bool AllDownCandles(int index)
{
   for (int i=index; i<index+NumberOfCandles; i++)
   {
      if (!isDownCandle(i))
      {
         return (false);
      }
   }
   return (true);
}

bool isUpCandle(int index)
{
   if (Close[index] > Open[index])
   {
      return (true);
   }
   return (false);
}

bool isDownCandle(int index)
{
   if (Close[index] < Open[index])
   {
      return (true);
   }
   return (false);
}
//+------------------------------------------------------------------+
 
monarcatrades: I need to draw an arrow on the next bar and not on the current bar which is drawn by this indicator. What could I modify?
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Shift your two buffers one to the right. SetIndexShift - Custom Indicators - MQL4 Reference

  3. Your code
    bool isDownCandle(int index)
    {
       if (Close[index] < Open[index])
       {
          return (true);
       }
       return (false);
    }
    Simplified
    bool isDownCandle(int index)
    {
       return Close[index] < Open[index];
    }
              Increase Order after stoploss - MQL4 programming forum #1.3 (2017)