9047: (remember this does not work/compile primarily because the arrays inside the buffer_t structs are not initialised):
#property strict
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Lime
#property indicator_label1 "Local Low"
#property indicator_type1 DRAW_ARROW
#define UP_RIGHT_THIN 228 // Wingding
:
struct buffer_t {
double data[];
};
buffer_t buffers[];
int OnInit(){
int numBuffers=5;
ArrayResize(buffers, numBuffers);
for (int index = 0; index < numBuffers; index++) {
SetIndexBuffer(index, buffers[index].data);
}
SetIndexArrow(0,UP_RIGHT_THIN);
SetIndexArrow(1,DOWN_RIGHT_THIN);
return INIT_SUCCEEDED;
} // OnInit
#define Local_Low buffers[0].data // shims into existing code.
#define Local_High buffers[1].data
int OnCalculate(const int Rates_total, ... ){ // existing code unmodified
:
Local_High[iBar] = hiCur + ArrowDistance();
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Lime
#property indicator_label1 "Local Low"
#property indicator_type1 DRAW_ARROW
#define UP_RIGHT_THIN 228 // Wingding
:
struct buffer_t {
double data[];
};
buffer_t buffers[];
int OnInit(){
int numBuffers=5;
ArrayResize(buffers, numBuffers);
for (int index = 0; index < numBuffers; index++) {
SetIndexBuffer(index, buffers[index].data);
}
SetIndexArrow(0,UP_RIGHT_THIN);
SetIndexArrow(1,DOWN_RIGHT_THIN);
return INIT_SUCCEEDED;
} // OnInit
#define Local_Low buffers[0].data // shims into existing code.
#define Local_High buffers[1].data
int OnCalculate(const int Rates_total, ... ){ // existing code unmodified
:
Local_High[iBar] = hiCur + ArrowDistance();
You may look at the blog post - Arrayed indicator buffers based on operators overloading. Probably it'll be hepful.
I found issue ... I think :)
Thank you very much for the quick responses :D
Thank you very much for the quick responses :D

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
I think this a limitation of the MQL sandbox but I thought I'd ask here just to double check.
I have an indicator the needs to create an arbitrary number of "indicator buffers" based on the input parameters e.g. If the user wants to show 5 results then I need 5 buffers, if they chose 3 then I only need 3 buffers. I've tried the following:
buffer_4[], buffer_5[], buffer_6[],
buffer_7[], buffer_8[], buffer_9[],
.
.
buffer_(N-1)[];
const int MAX_BUFFERS = N;
int numBuffers;
void initIndicatorBuffers(int n) {
IndicatorBuffers(n);
if (n >= 1) SetIndexBuffer(0, buffer_0);
if (n > 1) SetIndexBuffer(1, buffer_1);
if (n > 2) SetIndexBuffer(2, buffer_2);
.
.
.
if (n == N) SetIndexBuffer(N-1, buffer_(N-1));
}
int OnInit() {
numBuffers = /* some function calls etc to determine required number of buffers. */
if (numBuffers > MAX_BUFFERS) {
return(INIT_FAILED);
}
initIndicatorBuffers(numBuffers);
}
double data[];
};
buffer_t buffers[];
int numBuffers;
int OnInit() {
int index;
numBuffers = /* some function calls etc to determine required number of buffers. */
IndicatorBuffers(numBuffers);
ArrayResize(buffers, numBuffers);
for (index = 0; index < numBuffers; index++) {
SetIndexBuffer(index, buffers[index].data);
}
// Other init code...
//
//
//
return(INIT_SUCCEEDED);
}
struct buffer_t {
double data[];
};
buffer_t buffers[];
int numBuffers;
int OnInit() {
int index;
numBuffers = /* some function calls etc to determine required number of buffers. */
IndicatorBuffers(numBuffers + 1);
ArrayResize(buffers, numBuffers);
/* Initialise an array to be an Indicator buffer */
SetIndexBuffer(numBuffers, _prototype_buffer);
SetIndexStyle(numBuffers, DRAW_NONE);
for (index = 0; index < numBuffers; index++) {
/* Copy the initialised buffer then use it */
ArrayCopy(_buffers[index].data, _prototype_buffer);
SetIndexBuffer(index, buffers[index].data);
}
// Other init code...
//
//
//
return(INIT_SUCCEEDED);
}
If anyone can offer some suggestions beyond the first solution that would be greatly appreciated.
Hope I've missed something simple.
9047.