EA removing itself from chart on tick

 

Hi all!

Thank you for looking at this thread. I'm having an issue where an EA keeps removing itself from a chart on tick. It occurs when I add a function to my main EA script. The function is down below. Any help would be greatly appreciated, this is giving me a real headache!

//+------------------------------------------------------------------+
//|                                      avg_true_range_function.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property library
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| My function                                                      |
//+------------------------------------------------------------------+
// int MyCalculator(int value,int value2) export
//   {
//    return(value+value2);
//   }
//+------------------------------------------------------------------+
double avg_true_range_function(int no_candles) export
  {

//Creates a struct where the information about the candles (e.g. price) will be stored.
   MqlRates PriceInfo[];
//Sorts it from the current candle to the oldest candle
   ArraySetAsSeries(PriceInfo,true);
//Copies the price information into the array
   double Data=CopyRates(Symbol(),PERIOD_CURRENT,0,Bars(Symbol(),PERIOD_CURRENT),PriceInfo);

//Creating 'buy' arrays
   double high_price[]; //Store the high price
   double low_price[]; //Store the low price
   double close_price[]; //Store the close price
   ArrayResize(high_price,no_candles);
   ArrayResize(low_price,no_candles);
   ArrayResize(close_price,no_candles);

   for(int i=0; i<no_candles+1; i=i+1)
     {
      high_price[i]=PriceInfo[i+1].high;
      low_price[i]=PriceInfo[i+1].low;
      close_price[i]=PriceInfo[i+1].close;
     }
   double tr[]; //Array to store the value of the true range
   double tr_values_store[],avg_tr=0,high_minus_low=0,high_minus_close=0,low_minus_close=0;
   ArrayResize(tr,no_candles);
   ArrayResize(tr_values_store,3);
   for(int i=no_candles;i>0;i=i-1)
   {
    high_minus_low = high_price[i-1]-low_price[i-1];
    high_minus_close = MathAbs(high_price[i-1]-close_price[i]);
    low_minus_close = MathAbs(low_price[i-1]-close_price[i]);
    /*
    tr_values_store[0] = high_minus_low;
    tr_values_store[1] = high_minus_close;
    tr_values_store[2] = low_minus_close;
    */
    
    
    tr[i-1] = MathMax(MathMax(high_minus_low,high_minus_close),low_minus_close);
   }
   
   double tr_sum=0;
   for(int i=0;i<no_candles;i=i+1)
   {
   tr_sum = tr_sum + tr[i];
   }
   avg_tr = tr_sum/no_candles;
   
   return avg_tr;

  }
//+------------------------------------------------------------------+

Thank you!

 
Please don't double post.