break of previous day high low

 

Hi Guys,


Im tring to create an indicator to draw an arrow with a buffer on the chart for when the price crosses above the high or low of the previous day. but cant seem to get it to work, what am i doing wrong? Many Thanks in advance

#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 "Buy"

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

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

extern int Candle_Index = 1;
double myPoint; //initialized in OnInit

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(2);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, EMPTY_VALUE);
   SetIndexArrow(0, 241);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, EMPTY_VALUE);
   SetIndexArrow(1, 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);
   ArraySetAsSeries(Buffer2, true);
   //--- initial zero
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, EMPTY_VALUE);
      ArrayInitialize(Buffer2, 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   
      
      int barshift_D1 = iBarShift(Symbol(), PERIOD_D1, Time[i]);
      if(barshift_D1 < 0) continue;
      
      //Indicator Buffer 1
      RefreshRates();
      if(Bid > iHigh(NULL, PERIOD_D1, 2+barshift_D1) //Price > Candlestick High
      )
        {
         Buffer1[i] = Low[1+i]; //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      RefreshRates();
      if(Bid < iLow(NULL, PERIOD_D1, 2+barshift_D1) //Price < Candlestick Low
      )
        {
         Buffer2[i] = High[1+i]; //Set indicator value at Candlestick High
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
shabaz:

Hi Guys,


Im tring to create an indicator to draw an arrow with a buffer on the chart for when the price crosses above the high or low of the previous day. but cant seem to get it to work, what am i doing wrong? Many Thanks in advance

  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   
      
      int barshift_D1 = iBarShift(Symbol(), PERIOD_D1, Time[i]);
      if(barshift_D1 < 0) continue;

      //Indicator Buffer 1
      RefreshRates();
      if(Close[i] > iHigh(NULL, PERIOD_D1, 1+barshift_D1) //Price > Candlestick High
      )
        {
         Buffer1[i] = Low[1+i]; //Set indicator value at Candlestick Low
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
      //Indicator Buffer 2
      RefreshRates();
      if(Close[i] < iLow(NULL, PERIOD_D1, 1+barshift_D1) //Price < Candlestick Low
      )
        {
         Buffer2[i] = High[1+i]; //Set indicator value at Candlestick High
        }
      else
        {
         Buffer2[i] = EMPTY_VALUE;
        }
     }
   return(rates_total);
  }

Maybe this is what you want?

 
Daniel Cioca #:

Maybe this is what you want?

Thank you so much!!!!!!