Closing out half lots. - page 9

 
DomGilberto:
Yea - I literally just figured that out when I removed the for loop. Am I right in saying that if I track the OrderTicket number from when it is first selected, once the OrderClose has done its thing and it returns true, then I could verify this with the OrderTicket number as they will be different - thus breaking the loop and wait until another new order comes through?

Not entirely sure how to write that, but is that roughly on the right lines?


You don't need to exit the loop . . . unless the remaining part of the Order has a new ticket number ? do you know if it does ?

The issue with saving this information in a variable or array is that if the EA stops by design or MT4 crashes you have lost your information and you can't pick up from where you left off. You might be able to do something with magic numbers . . otherwise you will have to get messy and start saving info to files . . .

 

Hmmm... Ok well I just printed out the order details after the OrderClose==true.... The OrderTicket numbers are identical, from when I first put the trade on to after I have closed half out... Any idea why it won't close half off as soon as Bid is >= to exit price as well? It seems to go far enough, but it only seem to close it on a pull back (I am quickly running a test on a known set-up repeatedly.)

2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: Half Closed Order Details:- Lots Remaining Open: 0.17 Closing Price was: 1.3557 Magic Number is: 1234 Order Ticket Number: 7
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: close #7 buy 0.17 EURUSD at 1.34916 sl: 1.35128 tp: 1.36117 at price 1.35566
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: Bid >= FirstTarget_Buy - Current Bid: 1.35566 FirstTarget_Buy: 1.35517
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35566 FirstTarget_Buy: 1.35517
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.35517
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.33
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 7
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.17000
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.08.02 15:50:27     2013.01.31 07:00  trendfishing_play_ground EURUSD,H1:  Checking Buy Order:- Lots to open: 0.33 Entry Price: 1.3492 Buy Stop Loss: 1.3513 Buy Take Profit: 1.3612 Magic Number is: 1234 Order Ticket Number: 7

If they're all the same ticket number, how can I work with that to stop trying to continuously close halves consecutively? Just wanting it to close half once...

 
DomGilberto:

Hmmm... Ok well I just printed out the order details after the OrderClose==true.... The OrderTicket numbers are identical, from when I first put the trade on to after I have closed half out... Any idea why it won't close half off as soon as Bid is >= to exit price as well? It seems to go far enough, but it only seem to close it on a pull back (I am quickly running a test on a known set-up repeatedly.)

Can you show a little more of the log/journal, what is the Bid the tick before half the Order is going to closed ? All we can see from what you have printed is what Bid was when half the Order was about to be closed. What Strategy Tester mode are you using ? every tick or Opening prices ?

 
DomGilberto:


If they're all the same ticket number, how can I work with that to stop trying to continuously close halves consecutively? Just wanting it to close half once...

Not sure, it's not something I have ever had to think about. Perhaps something with Magic Numbers, a bsse Magic Number related to the EA and then a extra 3 digits for the orders placed that day, then look in the Order History to see if there is a closed trade with a matching MN, or maybe look at OrderOpenTime() of the closed trade and match it to an open trade in which case it has already been part closed . . . not sure, you will need to do some thinking and experimentation . . . unless someone else already has a proven method ?
 

Ok - well, the only other option is to put two orders in with two different exit prices... the only problem I have with that is this:

"if(OpenOrdersThisPair(Symbol())==0)"

It will only let me put 1 order in at a time... If I remove that, then there will be an unlimited number of trades being put into the market on any one set-up... I'm hoping you have experience with how I can allow 2-3-4 orders in on any ONE isolated set-up idea?

I can have up to a maximum of 4 exits per trade set-up

 
DomGilberto:
Ok - well, the only other option is to put two orders in with two different exit prices... the only problem I have with that is this:

"if(OpenOrdersThisPair(Symbol())==0)"

It will only let me put 1 order in at a time... If I remove that, then there will be an unlimited number of trades being put into the market on any one set-up... I'm hoping you have experience with how I can allow 2-3-4 orders in on any ONE isolated set-up idea?
if(OpenOrdersThisPair(Symbol()) < 2)
would allow a maximum of 2 orders . . .
 
RaptorUK:

Can you show a little more of the log/journal,

please . . .
 
RaptorUK:

Can you show a little more of the log/journal, what is the Bid the tick before half the Order is going to closed ? All we can see from what you have printed is what Bid was when half the Order was about to be closed. What Strategy Tester mode are you using ? every tick or Opening prices ?


I am using every tick. The highlighted part above; how do I check that? I don't understand why, but sometimes not everything will print out - Yet the orderclose function works, but the print doesn't... Really frustrating, as it's confusing me. But never mind that, the print out is pretty much everything I pasted above?

The only difference being, is that I also have a relentless amount of "OrderModify error 1" - which I have yet to figure out...
 
DomGilberto:

I am using every tick. The highlighted part above; how do I check that? I don't understand why, but sometimes not everything will print out - Yet the orderclose function works, but the print doesn't... Really frustrating, as it's confusing me. But never mind that, the print out is pretty much everything I pasted above?

Look at the log file not at the journal tab, the tab often misses stuff when there are lots of prints but the log file captures them all . . .
 
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.10000
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 17
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.2
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33594
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35452 FirstTarget_Buy: 1.33594
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: Stop loss value for the order is 1.3555
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: delete #17 sell stop 0.20 EURUSD at 1.34573 sl: 1.35553 tp: 1.32614 ok
16:50:26 2013.02.05 11:00  trendfishing_play_ground EURUSD,H1: open #18 sell stop 0.20 EURUSD at 1.34573 sl: 1.35549 tp: 1.32620 ok
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.10000
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 18
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.2
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33597
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35544 FirstTarget_Buy: 1.33597
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1:  Stop loss value for the order is 1.3555
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: delete #18 sell stop 0.20 EURUSD at 1.34573 sl: 1.35549 tp: 1.32620 ok
16:50:26 2013.02.05 12:00  trendfishing_play_ground EURUSD,H1: open #19 sell stop 0.20 EURUSD at 1.34573 sl: 1.35549 tp: 1.32621 ok
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.10000
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 19
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.2
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33597
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35421 FirstTarget_Buy: 1.33597
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1:  Stop loss value for the order is 1.3555
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: delete #19 sell stop 0.20 EURUSD at 1.34573 sl: 1.35549 tp: 1.32621 ok
16:50:27 2013.02.05 13:00  trendfishing_play_ground EURUSD,H1: open #20 sell stop 0.20 EURUSD at 1.34573 sl: 1.35545 tp: 1.32629 ok
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.10000
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 20
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.2
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33601
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35167 FirstTarget_Buy: 1.33601
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1:  Stop loss value for the order is 1.3555
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: delete #20 sell stop 0.20 EURUSD at 1.34573 sl: 1.35545 tp: 1.32629 ok
16:50:27 2013.02.05 14:00  trendfishing_play_ground EURUSD,H1: open #21 sell stop 0.21 EURUSD at 1.34573 sl: 1.35533 tp: 1.32654 ok
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.11000
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 21
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.21
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33614
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35297 FirstTarget_Buy: 1.33614
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1:  Stop loss value for the order is 1.3553
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: delete #21 sell stop 0.21 EURUSD at 1.34573 sl: 1.35533 tp: 1.32654 ok
16:50:27 2013.02.05 15:00  trendfishing_play_ground EURUSD,H1: open #22 sell stop 0.21 EURUSD at 1.34573 sl: 1.35525 tp: 1.32669 ok
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.11000
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 22
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.21
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.33621
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35273 FirstTarget_Buy: 1.33621
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: Stop loss value for the order is 1.3553
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: delete #22 sell stop 0.21 EURUSD at 1.34573 sl: 1.35525 tp: 1.32669 ok
16:50:27 2013.02.05 16:00  trendfishing_play_ground EURUSD,H1: open #23 sell stop 0.21 EURUSD at 1.34573 sl: 1.35517 tp: 1.32686 ok
16:50:27 2013.02.05 17:00  trendfishing_play_ground EURUSD,H1: delete #23 sell stop 0.21 EURUSD at 1.34573 sl: 1.35517 tp: 1.32686 ok
Reason: