How to copy an array from an indicator to an EA?

 

Hi folks,

I am trying to figure out how to copy an array from an indicator to an EA. I am using global variables in order to do that, but that obviously has its flaws ( you cannot use tester, problems when applying to multiple instruments, etc.).

I know how to use iCustom in order to copy, or map or call buffered values to an EA. My question though is if it is possible to make a buffer from an array which has 13 values and move all 13 values to from the indi to the EA.

SetIndexBuffer(0, lines)

double lines [13];

[/CODE]

and then in the ea...

[CODE]

double lines [13];

double lines[0]=iCustom (...)

double lines[1]=iCustom (...)

double lines[2]=iCustom (...)

double lines[3]=iCustom (...)

.

.

.

.

Thank you for helping me to find the right direction...

 
rookie_forawhile:
Hi folks,

I am trying to figure out how to copy an array from an indicator to an EA. I am using global variables in order to do that, but that obviously has its flaws ( you cannot use tester, problems when applying to multiple instruments, etc.).

I know how to use iCustom in order to copy, or map or call buffered values to an EA. My question though is if it is possible to make a buffer from an array which has 13 values and move all 13 values to from the indi to the EA.

SetIndexBuffer(0, lines)

double lines [13];

[/CODE]

and then in the ea...

[CODE]

double lines [13];

double lines[0]=iCustom (...)

double lines[1]=iCustom (...)

double lines[2]=iCustom (...)

double lines[3]=iCustom (...)

.

.

.

.

Thank you for helping me to find the right direction...

Why don't you always "recalculate" 13 last bars (filling the buffer elements 0 to 12 with your desired values) in your indicator and then you can retrieve the 13 last values from that buffer using regular iCustom()?

 

Hi Mladen,

could you please be more specific? I have no slightest idea of how to recalculate values for each bar and fill the buffer with them. I just know how to use iCustom, but i have never created a buffer.

But I see your point. Then in the EA i would just use diffrent shifts within each iCustom for each element and create a new array there.

Thanks a lot.

 
rookie_forawhile:
Hi Mladen,

could you please be more specific? I have no slightest idea of how to recalculate values for each bar and fill the buffer with them. I just know how to use iCustom, but i have never created a buffer.

But I see your point. Then in the EA i would just use diffrent shifts within each iCustom for each element and create a new array there.

Thanks a lot.

Yes, then iCustom() can very easily access the 13 alements of the buffer that you are usinm to store values. Simply set the loop that usually goes in indicators to be at least 13, and then you can assign the values to a desired buffer up to index 13 (or even simpler use something like

For (inti-0; i<13; i++) buffer[1] = array;

And then use iCustom() to read those buffer values from a buffer (now, in a new metatarder 4 you can have up to 128 buffers so you can use buffer no 127 for that purpose, for example)

 

I thought that the number of buffers is limited to 8. Is it not?

 
rookie_forawhile:
I thought that the number of buffers is limited to 8. Is it not?

Not any more. You wrote your post while I was adding explanation. Please read my previous post

 

Awesome sauce! Thanks a lot for your help. Now I can get rid of those globals :-) I think that I dont even need the cycle i ll just code it statically. It would save like 7 lines or something...

Reason: