Disliked{quote} Unfortunately MT5 is very sensitive to the ammount of data to process, so you need to minimize the ammount of bars it has to process. This means that you can't have too many instances of VWAPs, and then the lower Tf you go to, the more bars there will be to process. Of course, we process all the necessary bars only on the first run. Still, I know of this problem and MT5 doesn't have the option to limit the number of bars on a chart like MT4 does. And when something like that happens, that you see nothing, the usual reason is that the indicator...Ignored
I didn't know how to work with handles in MetaTrader 5 at first, so I found a site that created indicators and experts. The part about creating indicators was free. They used the following method to control array out-of-range errors and slow down calculations.
The codes from that site helped me learn and better understand how to work with buffers and handles in MetaTrader 5.
Code for MT5
Inserted Code
input int BarsBack = 3000;//Bars Back
int PLOT_MAXIMUM_BARS_BACK = BarsBack;
#define OMIT_OLDEST_BARS 50
//--- indicator buffers
double Buffer1[];
int OnInit()
{
SetIndexBuffer(0, Buffer1);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
return(INIT_SUCCEEDED);
}
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);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(Buffer1, EMPTY_VALUE);
}
else
limit++;
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
}
return(rates_total);
} Code for MT4
Inserted Code
input int BarsBack = 3000;//Bars Back
int PLOT_MAXIMUM_BARS_BACK = BarsBack;
#define OMIT_OLDEST_BARS 50
//--- indicator buffers
double Buffer1[];
int OnInit()
{
SetIndexBuffer(0, Buffer1);
SetIndexEmptyValue(0, EMPTY_VALUE);
SetIndexDrawBegin(0, MathMax(Bars(Symbol(), PERIOD_CURRENT)-PLOT_MAXIMUM_BARS_BACK+1, OMIT_OLDEST_BARS+1));
return(INIT_SUCCEEDED);
}
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);
//--- initial zero
if(prev_calculated < 1)
{
ArrayInitialize(Buffer1, EMPTY_VALUE);
}
else
limit++;
//--- main loop
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(PLOT_MAXIMUM_BARS_BACK-1, rates_total-1-OMIT_OLDEST_BARS)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
}
}
return(rates_total);
} Theory of Everything is Liquidity...https://www.youtube.com/@FxArt.Trader