![]() |
How to close order on BAR close? I need help, I would like to close the order at close of the same bar of open position. There's a way to do this? Thanks. Lubo |
Anyone? Anyone? |
Try do this on open next bar, for example, you opened position when new candle has lit, or when progresses, and you want to close at close of THE same bar or on open of new one. Use this part of code (the variables, their initalize and reset value you may solve, I hope. This is for 1hr charts, the daily has the similar logic if ( pos_open==true && Hour() == OpenHour+1) { OrderClose(ticket,....,....,....,.... blah blah) } The bool var pos_open you may manage by OrderSelect and OrderCloseTime ==0, as true, else false The var OpenHour you initialize at the IF body where you open the position (Example: if(pos_open==false && ......&&......&&..... ) //your entry rules { OrderSend(NULL, OP_BUY, Lots, Ask, 0, Bid-SL*Point, Bid+PT*Point); OpenHour=Hour(); } It's clear and understandable? P.S. for Daily, or other TF you can use the similar logic, replace only Hour() Minute() or Day() - as new candle lights |
thanks thanks for the code, and I think it's better >= instead == I have tried also this. if(TimeCurrent() >= Time[0] + (Period() * 60 - 1)) ......Close Trade But I still get orderclose error 138.....requote, I don't understand why.. Any ideas? Lubo. |
>= maybe better than ==, but the order you close only once, so this is irrelevant, what you wrote it... you may get orderclose error when you realize close by elseway (SL, PT hit, for example), or the EA is trying close position with wrong ticket number. Try re-check the orderSelect passage, try recompile without it, simply try attempt/error. I now work on another PC, where I have not some functionable EA, from what I can get you a code. I had here only right OrderSelect, you may edit it for your needs if(OrderSelect(position1,SELECT_BY_TICKET)==true) { OrderSelect(position1, SELECT_BY_TICKET); if(OrderCloseTime() ==0) { total1=1; } else { total1=0; } } else total1=0; //nikdy pozice 1 nebyla if(OrderSelect(position2,SELECT_BY_TICKET)==true) { OrderSelect(position2,SELECT_BY_TICKET); if(OrderCloseTime() ==0) { total2=1; } else { total2=0; } } else total2=0; EDIT: the re-quote you try slove by the "slippage" argument |
>=
|
![]() ![]() Were you solve the problem with closing position?? Another (maybe stupid) idea: I had once upon a time some problem with similar signs as yours (OrderSend Error : (i think) 128) - I tried all what is possible - nothing, errors still occurs. I was get angry (very, very angry) the code, what and where it stayed I erased and entrie EA re-wrote. The code looks identically, but in old was some hidden error or problem. To current days I don't know where, but by this (drastic) procedure I solved it. If you don't see some way, try return on start you way and procced step by step ![]() Sorry, my English is horrible, but I hope you can understood it. (And I must do something with it ![]() |
© Forex Factory