if (OrdersTotal()==0 &&IsNewBar&& buysignal)
if at first tick opening trade fails your code is not trying to open at next tick
Print("OrderSend (",nameEA,") failed with error #", GetLastError());return;
what did you try to open Sell or Buy and what errors do you get if it fails ??
if (OrdersTotal()>0 && IsNewBar) {closeorders();} //placed after OrderSend
if at newbar a trade is open it has to close that trade first then there won't be done a OrderSend same bar
Hi People
I have MT4 build 625 and have written a small EA which checks for buy and sell signals and then once just one trade has been opened checks for a signal to close it. The EA is supposed to check for all of these signals once per Bar.
The problem is sometimes the EA responds to the signals and sometimes not ?? Could you please look over my code to see what may be the problem/s
My 'closeorder' function is as follows
Your help is greatly appreciated
Thanks
Barry
Welcome to mql4.com forum,
I suppose that you mean your EA doesn't open a trade when you got a buysignal or sellsignal ? But you don't show how these values are obtained, so it's difficult to help you. You have to print the value of buysignal/sellsignal and check it.
de Vries
I have never received any errors when trying to open a trade . The program either opens a trade or it doesn't sometimes. Same with closing, sometimes it closes and then sometimes it doesn't.
I get the feeling that it seems to be 'brushing' past some of the code ??
It is also not necessary for me to immediately open a new trade when I have just closed an open trade (buy or sell).
The presumed program flow is :
(1).On signal buy or sell if there are no open orders (2). If an order is open then close it when the correct signal is received. (3) Wait for next signal to buy/sell.
I do not have more than 1 trade open at a time .
angevoyageur
Thanks for input, as above sometimes a trade will go through correctly and then sometimes it doesn't . Thus I must presume that the correct value is being read, but sometimes MT4 ignores it.
de Vries
I have never received any errors when trying to open a trade .
Do you look for Print output at your Terminal (Ctrl+T) ==>kolom Journal // Experts ??
The program either opens a trade or it doesn't sometimes. Same with closing, sometimes it closes and then sometimes it doesn't.
I get the feeling that it seems to be 'brushing' past some of the code ??
It is also not necessary for me to immediately open a new trade when I have just closed an open trade (buy or sell).
With the code you made it is necessary
if (OrdersTotal()==0 &&IsNewBar&& buysignal)
second tick you have IsNewBar=false;
if(LastBarOpenAt == Time[0]) {IsNewBar=false;}
the next signal you get with IsNewBar
de Vries
The journal shows no sign of any error message.
Could you explain a bit more about your explanation ? Do you mean the code I have written checks for my entry signal on the 'second tick' which is not the start of the new bar and therefore is not being executed ??
I should perhaps encapsulate all code that needs to be executed at the start of the new bar within the 'if' statement. ?
de Vries
The journal shows no sign of any error message.
Could you explain a bit more about your explanation ? Do you mean the code I have written checks for my entry signal on the 'second tick' which is not the start of the new bar and therefore is not being executed ??
I should perhaps encapsulate all code that needs to be executed at the start of the new bar within the 'if' statement. ?
no your ordersend will only be done if there is no open trade,
you can have open trades also if you have manually opend one or more or if another EA is trading
also pendingtrades are counted in OrdersTotal()
if your EA sends an order and it fails you have to wait for opening newbar will it try again to do a trade
Investigate the situations you did think the EA had to trade but it didn't.
de Vries
The journal shows no sign of any error message.
Could you explain a bit more about your explanation ? Do you mean the code I have written checks for my entry signal on the 'second tick' which is not the start of the new bar and therefore is not being executed ??
I should perhaps encapsulate all code that needs to be executed at the start of the new bar within the 'if' statement. ?
If nothing is printed and no trade is open when executing the code you posted here, that can only means OrderSend() is not executed.
As your conditions are executed on each new bar if there is no open trade, if OrderSend() is not executed that can only means that buysignal and sellsignal are false.
As Devries said you, MT4 can't ignore your code, so either your code is buggy or you are wrong when you are thinking a trade must be executed. As you don't see the code where buysignal/sellsignal are set, it's not possible to decide.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi People
I have MT4 build 625 and have written a small EA which checks for buy and sell signals and then once just one trade has been opened checks for a signal to close it. The EA is supposed to check for all of these signals once per Bar.
The problem is sometimes the EA responds to the signals and sometimes not ?? Could you please look over my code to see what may be the problem/s
My 'closeorder' function is as follows
Your help is greatly appreciated
Thanks
Barry