Question about changing profile on MT4 - how it affects EA?

 

I have just written my first simple EA.

There is only the Start() special function in there without init() and deinit().

My questions are on the flow of EA execution after I switch profile and back again to the original profile.

This is not exactly my program but I would like to highlight the essence of my question with the example below

*********************************************

start()

{

Hello(); // call user-defined function;

return(0);

}

void Hello() // user-defined function;

{

static int counter=1;
if (counter==1)
{
Alert("Hello");
counter++;
}
else Alert("Bye!");
}

*********************************

What I expect this EA to do is to alert "Hello" only once when I first load it onto a chart in a profile and then alert "Bye" thereafter for every tick that comes in.

And it works fine if I leave the EA running in the chart in a profile.

The issue I have is during the running of EA in that chart and if I switch profile and then back to the original profile, I get another "Hello" followed by a stream of Byes with every tick.

It is like reloading the EA from scratch thereby initializing the static counter to 1 again.

I guess this is normal (or not?) and how do I avoid the 'reloading of EA'? I mean I would like to view other profiles and yet at the same time want my EA to function like I have never left it.

Any help or feedback from readers are most appreciated.

Thanks

CY

 

Changing profile closes the chart where the EA is running. The EA exits too. No chart, no EA.

The new profile opens new charts. If the EA is attached to one or more, it is started "from scratch" on each chart it is attached to.

Normal operation.

 

Why not leave your EA operating in peace and do your monitoring on another instance of the MT4 platform.

Just copy your entire MT4 install into another folder.

CB

 
phy:

Changing profile closes the chart where the EA is running. The EA exits too. No chart, no EA.

The new profile opens new charts. If the EA is attached to one or more, it is started "from scratch" on each chart it is attached to.

Normal operation.


thanks for the feedback phy.

pardon me but if you say the EA exits as profile is changed, then how do you explain that the external variable still remains the same as before when you 'return' to the original profile?

What I mean is this: say your EA has an external variable (integer) called A and it is defaulted to 10. Say you drag the EA to the EURUSD on a profile called P and the input windows pops out. You then set A to 5 (overididng the default value). Then you switch profile for 10secs and then move back to P again. The Expert tab by now should show that this EA is loaded. Check the EA settings and A is still 5. If it is 'started from scratch', it would have been defaulted to 10, wouldn't it?

I hope my question makes sense otherwise please correct me.

Thanks

 
cloudbreaker:

Why not leave your EA operating in peace and do your monitoring on another instance of the MT4 platform.

Just copy your entire MT4 install into another folder.

CB


Thanks CB, do you mean that when an EA is attached to a chart, we must never exit from the profile that contains it?

Am I right to say that the EA would still be running okay if we were to view other charts on the same profile ?

For example, profile P contains usdjpy, eurusd and audusd. I place my EA on usdjpy and then switch to view eurusd and audusd. Will the EA still continue to work or will it be removed/stopped?

 

Don't know, I'm not a profile switcher.

 
cloudbreaker:

Why not leave your EA operating in peace and do your monitoring on another instance of the MT4 platform.

Just copy your entire MT4 install into another folder.

CB


CB, does this mean if i have 3 differnt EAs then I should open 4 MT4 folders ( one for each EA and the 4th one for monitoring)?

Sounds kinda troublesome.

CY

 

The answer is - it depends.

Each instance of MT4 can be connected to one account and have just one "trading context".

You may run different charts in that instance/context each with one EA (and these EAs may not be the same of course).

If there is a chance that the EAs will attempt to perform TRADING operations at the same time, therefore contending for the single trading context, then you must decide either to:

- live with trade failures due to "Trade Context Busy" errors

- code your EAs to share the trading context by handling the above errors

- or implement multiple instances of the MT4 platform (all of which may operate on the same account, or on different accounts)

If you are attempting to build a reliable solution, multiple instances are really no big deal.

CB

 
cloudbreaker:

The answer is - it depends.

Each instance of MT4 can be connected to one account and have just one "trading context".

You may run different charts in that instance/context each with one EA (and these EAs may not be the same of course).

If there is a chance that the EAs will attempt to perform TRADING operations at the same time, therefore contending for the single trading context, then you must decide either to:

- live with trade failures due to "Trade Context Busy" errors

- code your EAs to share the trading context by handling the above errors

- or implement multiple instances of the MT4 platform (all of which may operate on the same account, or on different accounts)

If you are attempting to build a reliable solution, multiple instances are really no big deal.

CB


I just thought that there is a workaround to this issue other than opening new MT4 folders but thanks CB. Appreciate your help here..

Reason: