Is special handling of variables required when using EA on various timeframe charts of same symbol?
2 replies
eawNewbie
10 years ago #115149
The scenario:
On one account
I use same EA on various currency pairs
Each currency pair will likely have at least 2 Charts of different time-frames (possibly M15, M30 & H1) open simultaneously.
Each EA instance handles trades using individual Magic numbers.
The EA contains variables and Array’s running on each Time-Frame.
(This array is just an example)
//---(CCI Signal)
int cciIndex() {
double cci[];
ArrayResize(cci,5);
for(int i=0; i<3; i++)
cci[i] = iCCI(NULL, 0 , 8 , 5 , i);
CCI_index=9;
if(cci[1]>100 && cci[0]<cci[1] && cci[1]>cci[2]) CCI_index=1;
else if(cci[1]>100 && cci[0]<100) CCI_index=2;
else if(cci[1]<-100 && cci[0]>cci[1] && cci[1]<cci[2]) CCI_index=-1;
else if(cci[0]>-100 && cci[1]<-100) CCI_index=-2;
else if(cci[0]>-100 && cci[0]<100) CCI_index=0;
return (CCI_index);
}
The above example placed into the custom functions area of EA Wizards code structure have variables which maybe initialized multiple times on one MT4 platform.
1. How does MT4 identify each variable considering they are initialized with same name (identifier) specifically ” cci ” & ” CCI_index ” ??
2. Do I need to provide a unique name for each variable when attached to each chart (whether same symbol or not)?
My concern obviously is the variable ” cci [1] ” which may contain a value from another time-frame chart.
thanks
0
Mark Fric
10 years ago #137190
this is not a problem, because each EA runs in its own separate “space”, so even if you have multiple EAs using the same variable, each EA uses its own local copy of the variable.
The only thing that is global in MT4 is orders, so make sure you set different Magic Number for each your EA.
Mark
StrategyQuant architect
0
eawNewbie
10 years ago #137209
Thanks for clarifying. I had assumed this but after reading this article https://www.ea-coder.com/attach-multiple-expert-advisors-on-mt4/ I was not sure. It appears the only concern is the handling of orders and yes each chart is assigned a unique Magic number.
I have been monitoring the output of each variable and so far there has not been any duplication or unexpected results.
thanks
0
Viewing 2 replies - 1 through 2 (of 2 total)