EA disappears off chart when this library function is applied

To add comments, please log in or register
Bartlomiej Winter
Bartlomiej Winter  

Hi all!

Thank you for looking at this thread. I'm writing some basic indicators in MQL5, and I am currently writing one for a simple average true range with no smoothing. Compiling the code leads to no errors or warnings. For some reason when I apply the EA to a chart it loads on fine but then on the next tick it disappears with no warning! I attached my code here, maybe there is something wrong with it?

Thank you for looking!

//|                                      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
//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

   for(int i=0; i<no_candles+1; i=i+1)
   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;
   for(int i=no_candles;i>0;i=i-1)
    high_minus_low = high_price[i-1]-low_price[i-1];
    high_minus_close = high_price[i-1]-close_price[i];
    low_minus_close = 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] = ArrayMaximum(tr_values_store,WHOLE_ARRAY,0);
   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;

Alain Verleyen
Alain Verleyen  

Your title talk about an EA, your post about an indicator, and you posted a library code. Make up your mind and be clearer if you need help.

And check the logs to see why the EA was removed from the chart.

To add comments, please log in or register