(MQL4) HELP! deinit function not working!

 
#property strict
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_width1 5
#property indicator_color1 Red
#property indicator_width2 5
#property indicator_color2 Red

double Buffer_0[];
double Buffer_1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init(){
   IndicatorBuffers(2);
   
   SetIndexBuffer(0,Buffer_0);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,242);

   SetIndexBuffer(0,Buffer_1);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,241);

   return(0);
}

extern int range = 100;
extern double pips = 1;
extern bool vline = true;
extern int RSIperiod = 14;
extern int RSIup = 70;
extern int RSIdown = 30;

int NowBars, a, b, c, d = 0;
int IndexHigh, IndexLow;
double HPrice, LPrice, HRSI, LRSI, RSI, NowClose, NowOpen;

//+------------------------------------------------------------------+
//| 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 = Bars - IndicatorCounted()-1;
   for(int i = limit; i >= 0; i--){
   
      IndexHigh = iHighest(NULL, 0, MODE_HIGH, range, i+2);
      IndexLow = iLowest(NULL, 0, MODE_LOW, range, i+2);

      HPrice = iHigh(NULL, 0, IndexHigh);
      LPrice = iLow(NULL, 0, IndexLow);
   
      HRSI = iRSI(NULL, 0, RSIperiod, 0, IndexHigh);
      LRSI = iRSI(NULL, 0, RSIperiod, 0, IndexLow);
      
      RSI = iRSI(NULL, 0, RSIperiod, 0, i);
      NowClose = iClose(NULL, 0, i);
      NowOpen = iOpen(NULL,0,i);

      if(i > 1 || (i == 1 && NowBars < Bars)){
         NowBars = Bars;
         
         if(HPrice < NowOpen && HPrice < NowClose && HRSI > RSI && RSI >= RSIup){
            Buffer_0[i] = iHigh(NULL,0,i)+pips*10*Point;
            if(vline == true){
               ObjectCreate("LineA"+IntegerToString(a), OBJ_VLINE, 0, iTime(NULL,0,i), 0);
               ObjectSet("LineA"+IntegerToString(a), OBJPROP_COLOR, Red);
               ObjectSet("LineA"+IntegerToString(a), OBJPROP_STYLE, STYLE_DOT);
               a++;

               ObjectCreate("LineB"+IntegerToString(b), OBJ_VLINE, 0, iTime(NULL,0,IndexHigh), 0);
               ObjectSet("LineB"+IntegerToString(b), OBJPROP_COLOR, Yellow);
               ObjectSet("LineB"+IntegerToString(b), OBJPROP_STYLE, STYLE_DOT);
               b++;
            }
         }
         
         if(LPrice > NowOpen && LPrice > NowClose && LRSI < RSI && RSI <= RSIdown){
            Buffer_1[i] = iLow(NULL,0,i)-pips*10*Point;
            if(vline == true){
               ObjectCreate("LineC"+IntegerToString(c), OBJ_VLINE, 0, iTime(NULL,0,i), 0);
               ObjectSet("LineC"+IntegerToString(c), OBJPROP_COLOR, Red);
               ObjectSet("LineC"+IntegerToString(c), OBJPROP_STYLE, STYLE_DOT);
               c++;

               ObjectCreate("LineD"+IntegerToString(d), OBJ_VLINE, 0, iTime(NULL,0,IndexLow), 0);
               ObjectSet("LineD"+IntegerToString(d), OBJPROP_COLOR, Yellow);
               ObjectSet("LineD"+IntegerToString(d), OBJPROP_STYLE, STYLE_DOT);
               d++;
            }
         }
         
         if(vline == true){
            ObjectDelete("Line0");
            ObjectCreate("Line0", OBJ_VLINE, 0, iTime(NULL, 0, range+2), 0);
            ObjectSet("Line0", OBJPROP_COLOR, Red);
         }
      }
   }
   return(rates_total);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+

int deinit(){
   for(int i = ObjectsTotal()-1; 0 <= i; i--){
      string ObjName = ObjectName(i);
      if(StringFind(ObjName, "Line") >= 0)
         ObjectDelete(ObjName);
   }
   return(0);
}
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Dozens of new automated trading applications appear in the MQL5 Market every day. Choose the right app among 10,000 products and forget about unnecessary routine operations of manual trading. Sell your algorithmic trading programs through the largest store of trading applications! Kiss on billions on EURUSD The provided robot is a result of...
 
int init(){
⋮
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 deinit(){

Use the new event handlers or the old ones. Don't mix!

You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference
          How to do your lookbacks correctly - MQL4 programming forum #9-14.

 
William Roeder:

Use the new event handlers or the old ones. Don't mix!

You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
          Event Handling Functions - Functions - Language Basics - MQL4 Reference
          How to do your lookbacks correctly - MQL4 programming forum #9-14.

Hi William,

Thank you for your input.

I have edited the event handlers as advised, but it's still not working...

I tried unifying using old handlers as well but no luck..

I would appreciate your further advice.

 

You should always check the Experts tab when you have a problem.

The Deinit is not the problem.

The problem with your code is an array out of range due to

   SetIndexBuffer(0,Buffer_0);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,242);

   SetIndexBuffer(0,Buffer_1);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,241);

Buffer_0 is not set because you re-assign index 0 to Buffer_1.

You should do

   SetIndexBuffer(1,Buffer_1);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,241);
 
Keith Watford:

You should always check the Experts tab when you have a problem.

The Deinit is not the problem.

The problem with your code is an array out of range due to

Buffer_0 is not set because you re-assign index 0 to Buffer_1.

You should do

Hi Keith,

OMG That was it! You're a genius! Thank you so much!