• Join us

How to use two-dimensional array as buffer in SetIndexBuffer() of MQL5?

To add comments, please log in or register
Loong
1404
Loong  

I want to show a lot of MA in a indicator.
So, if I can use two-dimensional array as buffer, It will briefly written form of circulation.

Like this:

   for(int i=0; i<96; i++)
   {
      Param[i]=10*(i+1);
      SetIndexBuffer(i,ArrayMA[][i],INDICATOR_DATA);
      PlotIndexSetString(i,PLOT_LABEL,"MA"+IntegerToString(i,2,'0'));
      mahandle[i]=iMA(Symbol(),0,Param[i],shift,smootMode,price);
   }

How to do it?

Files:
ma96.mq5 5 kb
Loong
1404
Loong  
noncirculation form is OK
Files:
ma16.mq5 10 kb
Loong
1404
Loong  
Um, may I do it with class...
Like this.
class CIndicatorBuffer
{
public:
   int mhandle;
   double mbuffer[];
bool  mArraySetAsSeries(bool set)
{return ArraySetAsSeries(mbuffer, set);}
bool  mSetIndexBuffer(int index, ENUM_INDEXBUFFER_TYPE data_type)
{return SetIndexBuffer(index, mbuffer, data_type);}
bool  mPlotIndexSetInteger(int plot_index, ENUM_PLOT_PROPERTY_INTEGER prop_id, int prop_value)
{return PlotIndexSetInteger(plot_index, prop_id, prop_value);}
bool  mPlotIndexSetString(int plot_index, ENUM_PLOT_PROPERTY_STRING prop_id, string prop_value)
{return PlotIndexSetString(plot_index, prop_id, prop_value);}
int  mCopyBuffer(int count)
{return CopyBuffer(mhandle, 0, 0, count, mbuffer);}
};
CIndicatorBuffer MAA[iNum];
Files:
Loong
1404
Loong  
It can be compiled.
0 error(s), 0 warning(s),
but, 0 indicator(s).
Help me! Also for you!
Loong
1404
Loong  

It seems the error occur when call CopyBuffer().

Returned Value is -1.

Loong
1404
Loong  
first call iMA() in a loop, return 10; later call, return 0. why?
Loong
1404
Loong  

memory leak?

It's terrible.

My MT5 can not open.

Restart windows.

Loong
1404
Loong  

It's OK, just move Param into CIndicatorBuffer as a member.

But why? array member cannot be a ma_period of iMA?

No, I has tested, iMA(NULL,0,Param[i],shift,smootMode,price) is OK.

It's strange.

Files:
ma96_ok_.mq5 8 kb
Loong
1404
Loong  

a pic

Loong
1404
Loong  
It's OVER.
Al W
163
Al W  

Congratulations.

I'm still not sure why it didn't work the first time for you. I noticed on the non-working one, you called the ArraySetAsSeries before SetIndexBuffer, then on the working one, you called it after. Think that was the bug?

12
To add comments, please log in or register