[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 166

 
Xaoss1990:

Gentlemen professionals, I need your help again!

Below is a snippet of code responsible for closing trades, but the thing is that when pending orders are not executed it does not delete them, I can't figure out why. But when I need to close a pending order that has already been executed, everything goes correctly and if the order hasn't been executed then it just hangs there until it executes...

OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
Magic = OrderMagicNumber();
orderticket = OrderTicket();

if (OrdersTotal() == 1 && Magic == 111 && OrderType( ) == 0) {
if (H1_BUY_5 == 0 || H1_BUY_1 == 0) {
OrderClose(orderticket, lots, Bid, 5, Yellow);
if (OrdersTotal() == 1) OrderDelete(orderticket, Brown);
}

}



This is the condition that selects only buy orders,

if (OrdersTotal() == 1 && Magic == 111 && OrderType( ) == 0)

so there is no way to remove the pending order

 
Roger:


Probably because you calculate the lot first and then

Thanks, changed the lot calculation, but it still doesn't work.
 
Sancho77:
Thanks, changed the lot calculation, but it still doesn't work.


How does it not work, what does it say in the logs?

Check what values np takes, here

if (OrderSelect(np, SELECT_BY_POS, MODE_TRADES)) {
      ClosePosBySelect();}
    }
 
There are no error messages in the logbook. Can you look at the whole EA code? It should close 1/3 of lot if stoploss already moved to breakeven by trawl.
 
Sancho77:
There are no error messages in the logbook. Can you look at the whole EA code? It should close 1/3 of lot if stoploss already moved to breakeven by trawl.

Oooooooo how messed up everything is. In general, everything is wrong, easier to throw out and write a new one. Parameters are defined incorrectly, functions are called incorrectly, a lot of unnecessary calculations. Good for a tutorial on how not to write code.
 
Roger:

Oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo messy. All in all, it's all wrong, it's easier to throw it away and write a new one. Parameters are defined incorrectly, functions are called incorrectly, a lot of unnecessary calculations. It will be good for a tutorial on how not to write code.
Ok, let's start from the beginning)
 
Sancho77:
...Should close 1/3 of the lot if a stop loss already moved to breakeven by the trawl is triggered.
I'm looking at all this and thinking to myself - why take up such tasks if you're not sure of the basics? This kind of self-study does more good than harm. The spark of thought drowns in a pile of mistakes.
 
granit77:
I look at all this and think to myself - why take on such tasks if you are not sure of the basics? This kind of self-study does more good than harm. The spark of thought drowns in a pile of mistakes.

Probably meant more harm than good.
 
Yeah, a typo.
 

Please advise us, gentlemen!

Imagine the situation: a stop is triggered, because of the triggering of the N-th condition. But after a couple of candlesticks, the N-th condition has fallen away. With the help of which function you can open the deal again after the N-th condition falls out. That is, you need to determine that triggered a stop some number of bars ago, and because the N-th condition has fallen away, repeat the trade!