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 candleArraySetAsSeries(PriceInfo,true);
//Copies the price information into the arraydouble Data=CopyRates(Symbol(),PERIOD_CURRENT,0,Bars(Symbol(),PERIOD_CURRENT),PriceInfo);
//Creating 'buy' arraysdouble high_price[]; //Store the high pricedouble low_price[]; //Store the low pricedouble close_price[]; //Store the close priceArrayResize(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 rangedouble 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;
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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!
Thank you!