Closing out half lots. - page 5

 
DomGilberto:

I put in a pending order "OP_BUYSTOP" but I was under the impression that this would change when triggered to an "OP_BUY"?

I thought the order type would be "OP_BUY" if it had been triggered?

Afterall, I am only interested ONCE the order has been triggered?

Why are those braces confusing? Do you mean in terms of where the left parenthesis is? If so, it seems that is an individual thing, as I have been corrected on this multiple times?

The braces are not needed, so the fact they are there can cause confusion for other trying to read your code (me).


If you only have a BUYSTOP then your code will not do anything because it is not an OP_BUY . . .

DomGilberto:
Hmmm, still does not want to close @ "Close_Half_Order" ? Not getting any error message either?

so this make sense while the Order is still pending . . .

Does your Order have the correct Magic Number ?

 
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Close_Half_Order Last Error = 4108
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: OrderClose error 4108
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: pending order #9 cannot be closed
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.18
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 9
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.09000
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.37931
I removed the line "if(OrderType()==OP_BUY)" - This is the new print outs within the journal after the test? Invalid Ticket... (sorry for asking 101 questions about this!)
 
DomGilberto:
I removed the line "if(OrderType()==OP_BUY)" - This is the new print outs within the journal after the test? Invalid Ticket... (sorry for asking 101 questions about this!)

RaptorUK:

You don't close a pending Order, what did your error reporting tell you ?

2013.07.31 17:45:46     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: pending order #9 cannot be closed

You can't close a pending order, they get deleted.

 
But I am not trying to close a pending order? I am trying to close half of the lots on an "OP_BUY" which is not pending...? I'm obviously missing something here...
 
DomGilberto:
But I am not trying to close a pending order? I am trying to close half of the lots on an "OP_BUY" which is not pending...? I'm obviously missing something here...
DomGilberto:

I put in a pending order "OP_BUYSTOP" but I was under the impression that this would change when triggered to an "OP_BUY"?

If you have a OP_BUYSTOP your code does not doing anything, which is OK. When the OP_BUYSTOP is triggered it turns into an OP_BUY and your code should close half of it's position size . . . as long as it has the correct symbol and Magic Number, did it ? I guess it must have otherwise the code would not have tried to close the pending order . . . what about OpenOrdersThisPair(Symbol()) == 1 ?
 
If I remove "OpenOrdersThisPair(Symbol()) == 1" from the code, the messages are exactly the same within the journal... I'm baffled...?
 
DomGilberto:
If I remove "OpenOrdersThisPair(Symbol()) == 1" from the code, the messages are exactly the same within the journal... I'm baffled...?

Time to add some more Print() statements, check everything you haven't already checked . . . you are only baffled because you don't know why, find out why and you will no longer be baffled.

When you have found out why and you have all these Print() statements that you no longer want printing to the Journal/Experts tab have a look at this which will allow a nice way of turning them on and off: https://www.mql5.com/en/forum/135168/page2

 

Ah, by the way, you can't do this . . .

bool Close_Half_Order = OrderClose(OrderTicket(), half, FirstTarget_Buy, 3, CLR_NONE);

. . . unless FirstTarget_Buy happens to == Bid To remove the possibility that it isn't just use Bid. A Buy is closed with a Sell, a Sell is executed at Bid.

 
Ok, so if I put "Bid" there, the lots are now being closed out, but not at the correct price, and it seems to close out several halves during any one position. (more toward the top 2/3rds of the 100% target price area... not all the same price that they're closing at...)

How am I supposed to close the position out at "FirstTarget_Buy"?
 
DomGilberto:
Ok, so if I put "Bid" there, the lots are now being closed out, but not at the correct price, and it seems to close out several halves during any one position. (more toward the top 2/3rds of the 100% target price area... not all the same price that they're closing at...)

How am I supposed to close the position out at "FirstTarget_Buy"?

You can't OrderClose() at any price other than Bid and Ask (Buy and Sell) . . . it's that simple, you cannot.

What you can do:

open two trades for half the position each and give each a different TP

or

monitor Bid/Ask price and when it has reached or passed "FirstTarget_Buy" close half the trade at Bid/Ask

Reason: