qjol:
Done :)
add this function
//------------------------------------------------+ // check for new bar | //------------------------------------------------+ //---- Check Is New Bar bool NewBar() { static datetime Time.PrevBar; bool PrevBar = ( Time.PrevBar < Time[0]); if(Time.PrevBar < Time[0]) { Time.PrevBar = Time[0]; return(true); } else return(false); }
& call it
if (NewBar()) { OrderClose(.....); }
Bump
Fixed, used
int barsCount = 0; int init() { return(0); } int deinit() { return(0); } int start() { if(Bars > barsCount){ if(OrdersTotal() > 0){ for(int c = 0; c < OrdersTotal(); c++){ OrderSelect(c, SELECT_BY_POS); if(OrderType() == OP_BUY){ OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue); }else if(OrderType() == OP_SELL){ OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); } } } barsCount = Bars; return(0);
When your chart has the max number of bars on it Bars will no longer increment . . . will your code work then ?
RaptorUK:
When your chart has the max number of bars on it Bars will no longer increment . . . will your code work then ?
When your chart has the max number of bars on it Bars will no longer increment . . . will your code work then ?
Ah yes, you're right.. It won't
Thanks, back to qjol's code!
I'm running into difficulties with Qjol's code, when I disable eachtickmode the EA waits 1 bar until it trades again (so it cant close an order & re-enter on the same bar)
When I enable it, it can close & re-enter on the same bar BUT the re-enter order is executed twice: Re-enter -> closed right away -> Re-enter again -> closed correctly (on newbar)
Any tips?
Log:
2011.07.25 23:10:23 _1 GBPUSD: close #10354630 sell 0.10 GBPUSD at 1.62889 at price 1.62811 2011.07.25 22:59:38 _1 GBPUSD: SELL order opened : 1.6289 2011.07.25 22:59:38 _1 GBPUSD: open #10354630 sell 0.10 GBPUSD at 1.62889 ok 2011.07.25 22:59:37 _1 GBPUSD: close #10354626 sell 0.10 GBPUSD at 1.62889 at price 1.62897 2011.07.25 22:59:36 _1 GBPUSD: SELL order opened : 1.6289 2011.07.25 22:59:36 _1 GBPUSD: open #10354626 sell 0.10 GBPUSD at 1.62889 ok
Tried to add a sleep() function after the ordersend, didnt make a difference

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi,
Need some help, I tried to change the code below but the EA kept crashing MT4.
I want the order to close when the current bar (so the bar where the order was executed) closes. Basically trade one bar.
This is the original code, it trades from signal to signal.
Can anyone help me out?