I think I see now that I did not select that trade which just opened to assign a value to LongOpen...
Not sure how to select the last opened trade though...
To select order, also assign ticket, i.e. LongTicket and LongOpen, then, select by ticket.
Also, when closing, count orders down vs up.
2cent:
I'd say that your "iClose bit" is true for... losing order, i.e. try " ". To select order, assign ticket instead of price, i.e. LongTicket vs LongOpen, then, select by ticket.
Cheers. I tried the magic number as well ticket integer thing but eventually I managed it by putting the iClose bit into line 6 after the order was selected for closure.I'd say that your "iClose bit" is true for... losing order, i.e. try " ". To select order, assign ticket instead of price, i.e. LongTicket vs LongOpen, then, select by ticket.
if ( d == true && e == true ) { for (cnt = 0 ; cnt < OrdersTotal() ; cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderType() == OP_BUY && iClose(NULL,0,0) > OrderOpenPrice()) { OrderClose(OrderTicket(),OrderLots(),Bid,30,Blue); } } }
Yes, that's the way it works.
In the first example, once it entered the loop, it closed all orders regardless of profit. (And I made a mistake in my suggestion, I apologise.)
2cent:
Also, when closing, count orders down vs up.
You mean like this?
for (cnt = OrdersTotal() ; cnt = 0 ; cnt--)
Like so:
for(cnt = OrdersTotal() - 1; cnt >= 0; cnt--)
2cent:
Like so:
Cheers, I guess it does make sense to count down since it would always begin with the latest open order.
Yes, otherwise it will skip orders.

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
So I have an active trade which was opened fine through the following code (ignore a, b, and c, because those conditions have been met)
and it is now time to close the trade according to the conditions d and e, except I don't want to close because the trade is in negative equity, so I added in
to the 2nd line here of the closing part
Except it doesn't work, trades are still closing according to d and e, while ignoring the iClose bit. Can anybody see where I went wrong?