How to close order on BAR close?
Results 1 to 7 of 7

Thread: How to close order on BAR close?

  1. #1
    I need help, I would like to shut the order at closing of the same pub of open position.
    There's a way to do this?



  2. #2

  3. #3
    Try do so on open bar that is next, for example, you opened place when new candle if progresses, or has lit, and you want to close at close of THE exact same bar or onto receptive of new one. Use this portion of code (the factors, their initalize and reset worth you may resolve, I expect. That is really for 1hr charts, the daily has the similar logic

    if (pos_open==authentic Hour() == OpenHour 1)

    OrderClose(ticket,...,...,...,.... Blah blah)

    The bool var pos_open you will manage by OrderSelect and OrderCloseTime ==0, as true, else false
    The var OpenHour you initialize at the IF figure where you start the place

    if(pos_open==false ...) //your entry rules

    OrderSend(NULL, OP_BUY, Lots, Ask, 0, Bid-SLNULLStage, Bid PT*Stage);

    It's clear and understandable?

    P.S. for Daily, or alternative TF you can use the similar logic, replace just Hour() Minute() or dawn() - as new candle lights

  4. #4
    Thank you to this code, and I think it's much better gt;= instead ==
    I've tried this.
    If(TimeCurrent() gt;= Time[0] (Stage() * 60 - 1)) ....Close Trade

    However, I still become orderclose mistake 138....requote, '' I do not understand why. .

    Any ideas?


  5. #5
    Gt;= possibly better than ==, however the order you close only once, so that is irrelevant, what you wrote it... you will acquire orderclose error when you realize close by elseway (SL, PT hit, for example), or even the EA is looking near position with wrong ticket amount. Try re-check the orderSelect passing, and attempt recompile without it, simply try attempt/error. I now work on another PC, where I've not some functionable EA, out of.

    I had here only right OrderSelect, You Might edit it for your needs


    OrderSelect(position1, SELECT_BY_TICKET);
    if(OrderCloseTime() ==0)




    else total1=0; //nikdy pozice 1 nebyla

    if(OrderCloseTime() ==0)




    else total2=0;

    EDIT: the re-quote you attempt slove from the slippage debate

  6. #6
    Quote Originally Posted by ;
    gt;= possibly better than ==, but the order you close only once, so this is irrelevant, what you wrote it... ....
    I think is rilevant coz if the second pub is missed the position isn't closed...

  7. #7
    Quote Originally Posted by ;
    I think is rilevant coz if the following bar is overlooked the place is not closed....
    Yes, I agree, this I relevanton M1 or similar charts, on greater TF (for instance 1hr) you've usualy more than 500 tick, so the EA calls the start() work more than 500 times. We were disunderstood about TF which you just play But, you're right, the operator more than or equivalent is more protected wiriting

    Were you solve the issue with closing place??

    Another (maybe stupid) idea: I'd once upon a time a issue with similar signs as yours (OrderSend Error : (I think) 128) - I tried all what's possible - nothing, errors still occurs. I was get mad (very, very upset) the code, what and where it remained I erased and entrie EA re-wrote. The code appears identically, but in older was problem or a hidden error. To current days I do not know where, but by this (extreme) process I solved.

    If you don't see some manner, attempt return on beginning you manner and procced step-by-step

    Sorry, my English is horrible, but I expect you can understood it. (And I must do anything with it )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners more information