EA (sometimes) doesn't open some orders...

 

Hi everyone,

First of all let me tell you that I am pretty new to coding and I read a lot of stuff and spent a lot of time before asking this question... This forum really helps a lot, thanks to all contributors.

I have written an EA that is more like a scalper. I say "like" because it's not exactly a scalper. So on average it opens 5-6 trades daily (per pair) and closes on a profit level when reached. It works with 4 different indicators (rsi, atr, etc.). Anyway, these are not really important as the problem, I guess, is not related to these.

So what happens: I launch MT4 and load the EA to the chart and turn on trading, within the first 24 hours or so, it opens all orders it needs to open (I check it with strategy tester later in the day and the orders that I see on tester were also all opened and closed in real time as well, so all in blotter even at exactly same price as tester suggests). However after some time (usually after that initial 24 hours) the EA starts opening noticeably less trades. I run the EA on 20 different pairs so normally I have around 90-100 traders per day and this number drops to 40-50 after that first 24 hours. When I run it in the tester for that time frame, I also see that some trades that are opened in tester were not opened (in real time) at all. EA is not stuck as it does open some of the trades it should open... I don't see any errors in the logs as well.  

I believe the code is not the problem, as sometimes it works perfectly and opens all trades as they should be opened. Is there anyone who can suggest a solution or at least a way to track down what's going on?

Many thanks in advance... 

 
demirozyurek: I believe the code is not the problem, as sometimes it works perfectly and opens all trades as they should be opened. Is there anyone who can suggest a solution or at least a way to track down what's going on?
Nothing but the code opens orders. If it doesn't do what you want, your code is broken. Fix your code. Print your variables before the ifs and add a print inside the ifs so you find out why.
 
WHRoeder:
Nothing but the code opens orders. If it doesn't do what you want, your code is broken. Fix your code. Print your variables before the ifs and add a print inside the ifs so you find out why.

Appreciate the comments WHRoeder. 

Thou (maybe I am too dumb to figure it out but) I really cannot understand how the code is broken, as for example it worked just fine from Sunday market open thru Monday evening and suddenly switched to a state that it opens some of the orders and ignores the others from then on. In case it's broken, shouldn't it just react the same all the time? And also in tester it goes all well. 

I'll put prints in the ifs as per your suggestion although, as I said before that the code is not very professional and there are too many ifs inside. But I'll try... 

Can you think of any other cause rather than the code itself?

 
Last time my ea won't open orders. Turns out that the spread is the culprit. Smaller spread gap is good but it is precise. So, if the condition is not met, ea wouldn't open orders.
 
deysmacro:
Last time my ea won't open orders. Turns out that the spread is the culprit. Smaller spread gap is good but it is precise. So, if the condition is not met, ea wouldn't open orders.
I didn't understand what you mean by spread; but in case you meant slippage, I thought about it and put a quite toleranced slippage in order to make sure it doesn't prevent the EA from opening orders...
 
Then, use Print() before opening orders so that you will know what happens. Use Print() also if opening new orders fails.
 
I have the same problem. How did you solve it?
 
hello. I am also having this problem. I made an EA and it works well in backtesting. However, when I tried it in real account in a VPS. sometimes it works great, but there are times that it does'nt open orders at all. I am also not seeing any error in the code. so I guess I also need to try your suggestion to place a Print function in every if's. Thank you.
 
Stephen Nidea #:
hello. I am also having this problem. I made an EA and it works well in backtesting. However, when I tried it in real account in a VPS. sometimes it works great, but there are times that it does'nt open orders at all. I am also not seeing any error in the code. so I guess I also need to try your suggestion to place a Print function in every if's. Thank you.

I had the same problem. But when I increase slippage in the OrderSend and OrderClose the problem is solved.

Reason: