EA Running on multiple pairs Problem - page 2

 

Hi Ubzen,

It fires ! Now, AUDUSD and GBPJPY firing the EA repeatedly as I write, while the rest are idling. ....!? This morning, AUDUSD was idling.... Sigh !

 

Hi,

I have located the problem as to why my EA stop running in some pairs. The reason is my EA stalled when executing a couple of routines. I have each routine for each strategy built in my EA. When I placed a probe in each routine, it turns out that my EA stalled at those routines that attempt to obtain Zigzag nodes. When I remove these routines, my EA sails through very quickly. Here is the thing I did in those routines that stall the EA.

I use iCustom(NULL,TF, "ZigZag",80,35,12,0,i) to locate the nodes. (80,35,12) is a big Zigzag that takes time to go through many bars to determine the nodes. It seems that the EA is not able to complete the task, and kept attempting to repeat it again and again. That is why my EA stalled at these routines. Anyone has any advise how to go about resolving such problem?

Many thanks.

Novalight

 
novalight: It fires ! Now, AUDUSD and GBPJPY firing the EA repeatedly as I write, while the rest are idling. ....!? This morning, AUDUSD was idling.... Sigh !
Your EAs are interfering with each other. You probably have
Wrong
Correct
if(OrdersTotal()==0)..
if (MyOrdersTotal() == 0) ..
:
// Only select my orders
int MyOrdersTotal(){
   int count = 0; 
   for(iPos = OrdersTotal() - 1; iPos >= 0 ; iPos--)
    if (MySelect(iPos, SELECT_BY_POS)) count++;
   return(count);
}
bool    MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
    if (!OrderSelect(iWhat, eSelect, ePool)   ) return (false);
    if (OrderMagicNumber() <  magic.number    ) return (false);
    if (OrderMagicNumber() >  magic.number.max) return (false);
    if (OrderSymbol()      != analyze.pair    ) return (false);
    if (ePool != MODE_HISTORY                 ) return (true);
    return(OrderType() <= OP_SELL); //Avoid cr/bal forum.mql4.com/32363#325360
                                    //Never select canceled orders.
}


Or you have the EA on the same pair, multiple TFs and didn't change the magic number.

Must change MN
EA adjusts
extern int Magic.Number = 20120628;
:
if(OrderMagicNumber()==Magic.Number)
extern int      Magic.Number.Base = 20120628;
int magic.number;
int init(){
    {//++++ Adjust for the current chart timeframe
    int TFperiod[] ={PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30,
                     PERIOD_H1, PERIOD_H4, PERIOD_D1,  PERIOD_W1,
                     PERIOD_MN1 };
    string TFtext[]={"M1",      "M5",      "M15",      "M30",
                     "H1",      "H4",      "D1",       "W1",
                     "MN1"      };
    chart.tf = Period();
    for(int iTF=0; TFperiod[iTF] < chart.tf; iTF++){}
    magic.number = Magic.Number.Base + iTF;

:
if (OrderMagicNumber() ==  magic.number) ..


or both.

Post your code, no mind readers here.

 

Hi WHRoeder,

Thank you very much for your help and advise. I can safely rule out magic number as I used it extensively to store and extract information. If it is wrong, it would have flagged out in many other areas. As for the order management, I have one routine to do that and it is running out on only one chart. No other charts/pairs will execute the order management. Therefore, I can also safely rule out the order management contention issue.

As indicated in my last comment, the problem area is in routines that do searching for Zigzag nodes. There is no other way for me to do without the Zigzag. The strange thing is that I have revamped my EA to run on only one chart, managing all pairs from there, and I thought that MT4 would execute my EA sequentially. In this way, I can avoid any contention of resources. i can see that my EA is now running through each and every pair, going through each time frame. I have a better control of the execution. However, my EA still stalled at the routines getting Zigzag nodes. It appears that the EA could not complete the task in getting the nodes from Zigzag, and it kept repeating it, and that's why it was stalled.

Any idea to resolve such situation? Many thanks.

Novalight

 

novalight:

I can safely rule out magic number as I used it extensively to store and extract information. If it is wrong, it would have flagged out in many other areas.

revamped my EA to run on only one chart, managing all pairs from there, and I thought that MT4 would execute my EA sequentially.

Any idea to resolve such situation? Many thanks.

Start() will be called when a new tick on the one chart pair/TF arrives. ONLY in that pair. YOU are now responsibility for everything. And you can not use Bid/Ask/Point/etc.

You are running multiple pair/multiple TFs. Then a single MN is not sufficient, you must differentiate each trade MN, pair and TF. Both open orders AND your storage.

Much simplier, EA trades one pair on TF on one chart. Use a range of MN to filter TF. Use a mutex to prevent problems. Debug one pair/TF/file. Then it works no matter how many times you add it.

 

@novalight: Well obviously the problem is within your code and not with start() firing. We cannot see your code so there's basically nothing anyone could do other than guess. As far as debugging, well that's your responsibility. If viewing the code and the problem is not obvious, no-one-else is going to line-by-line debug your code for you. So good job on finding the problem.

I'll recommend re-writing the entire code especially if your current code is too-large-to-understand. Chances are as time goes by, a person becomes a better coder and you could probably re-write a more efficient and understandable code now. I know if I was forced to debug someone else's code I'd much rather rewrite it from scratch.

I prefer multiple pairs upon a single chart. Reason I switched was because I was interested in submitting a contest-ea which would have been attached to 1-chart. Not too long before I noticed some benefits.

*Your EA no longer have to compete with itself for Trade-Context-Busy. A simple check if busy then sleep might do, depending on the system and how many other EA's you're running. Think about it, if you wanted to run a second-ea, thats a total of 24-charts opened instead of 2.

*Multi-Currency or Heavy-Execution functions do-not need to be duplicated. A global_variable_set or file or whatever which communicate with every expert telling them that it's processing the function or thread seems like a crude way to solve the problem. The guy in charge might not-fire/tick when some other ea needs the info. <- You just lost the biggest benefit of multiple charts.

*System resources: If the EA is heavy in Variables (ex-Global Variables), it'll consume almost double memory for each chart it's attached to. -- If it's heavy in Processing (ex-Loops), it'll hog the processor% every time a tick-fires-up. Just place the expert on EURUSD or whatever you believe is most active. The chances of EU standing still while something else a ticking like hell is unlikely.

Using iTime and MarketInfo(Current_Symbol, Ask), is not that hard to get used to. The syntax is longer but it's not going to appear more times than Ask. Plus last time I checked, per-defined variables need Refreshing after Sleep. All-In-All, it'll depend on your Strategy & Coding-Skills. Here's an example I'd provided before.

 

Hi WHRoeder,

Thanks for your advise and help.

I always want to know what happen when a new tick is in, and Start() is called while the routine is half way through its process ? Does it stop doing what it is doing and start from the beginning of the EA again? This is crucial as it might explain why a long process routine such as Zigzag is stalled or could not be completed. Your clarification will help me tremendously in my coding.

As for the MN, I use a unique number to represent a pair + time frame number (such as 240,060, 030, 005, etc.) +strategy number (01,02,etc.). Yes, I am aware that I cannot use Ask and Bid, and I am using MarketInfo to get the Ask/Bid prices.

When my EA is running on a single chart, managing all the rest of the pairs, do I still need mutex to control server related commands? Does it mean that MT4 is now executing my EA sequentially, and no more random firing of EA if EA is applied to all charts?

Thanks .....

Novalight

 
novalight:

Hi WHRoeder,

Thanks for your advise and help.

I always want to know what happen when a new tick is in, and Start() is called while the routine is half way through its process ? Does it stop doing what it is doing and start from the beginning of the EA again? This is crucial as it might explain why a long process routine such as Zigzag is stalled or could not be completed. Your clarification will help me tremendously in my coding.

The current start() finishes, when the next tick arrives start() is called again.
 

Thank you, RaptorUK, for the answer. That helps a lot.

I have finally located the problem area why my EA stalled at some pairs. The few routines using Zigzag were coded to search for the nodes starting from i=1 to N. If N happened to be 0, that's is where MT4 stalled. I would assume that "for" loop would not be running if N=0, but that was not the case. Once I fix the issue, my EA now sails through all pairs smoothly. It is my bad to assume that resource contention, CPU, etc., were the problem causing my EA to stall.

Thank you RaptorUK, WHRoeder, and Ubzen for your time and advise. I have learned a lot from this issue - mutex, single chart for multiple pairs, etc.

Take care .....

Novalight

Reason: