Closing out half lots. - page 6

 
You mean if I put "if(FirstTarget_Buy == Bid)" ? (Obviously not that as it doesnt work.)
 
DomGilberto:
You mean if I put "if(FirstTarget_Buy == Bid)" ? (Obviously not that as it doesnt work.)

Or something like . . .

if(Bid >= FirstTarget_Buy + (Point / 2) )
   {
   //  close the Order
   }

. . . bearing in mind the problems of comparing doubles ( Can price != price ? )

You also need to think about the spread and if your target is inclusive or exclusive of the spread.

 

(sigh) ok - Thanks for your help Raptor! This is becoming frustrating. I swear it just doesn't need to be this time consuming... That If statement above, will not work.

I am honestly at wits end...

It will close several halves (half of a half of a half etc.) if I do not include that "if" statement above (in which case nothing happens), and just put the closeorder to "Bid" - I can't work out how it is knowing when to close this half though...

Any more suggestions will be greatly appreciated, thanks for your help!

 
DomGilberto:

(sigh) ok - Thanks for your help Raptor! This is becoming frustrating. I swear it just doesn't need to be this time consuming... That If statement above, will not work.

I am honestly at wits end...

It will close several halves (half of a half of a half etc.) if I do not include that "if" statement above (in which case nothing happens), and just put the closeorder to "Bid" - I can't work out how it is knowing when to close this half though...

If you don't specify a price condition that must be met then it will just close half the Order as soon as it can, Bid is always Bid and is valid to close a OP_BUY.

The if statement will work . . . if it doesn't find out why, add a Print() before it . . . and after it.

Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );

if(Bid >= FirstTarget_Buy + (Point / 2) )
   {
   Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );

   //  close the Order
   }

Don't worry, it gets more frustrating . . . when you have your code working just as you want and you run it in the Strategy Tester and find it is about as good as a Coin Toss

 
Ok thanks! Can you also enlighten me why sometimes I run ST, then stop it and nothing is printed out within the Journal...?

" when you have your code working just as you want and you run it in the Strategy Tester and find it is about as good as a Coin Toss "

Yea I can only imagine! I have actually managed to write 6 pages (not sure how many lines that is) approx. of code - I am adding in these crucial parts... one of which is closing 50% at 1:1 and moving to break even... BUT NOOOooo the lot closing happens to be counter intuitive (as far as I am concerned)
 
DomGilberto:
Ok thanks! Can you also enlighten me why sometimes I run ST, then stop it and nothing is printed out within the Journal...?

You are looking at the correct journal tab ? there are two . . . the one you should be looking at in the Strategy tester window and the one you should look at next to the experts tab. The best way is to look at the log file saved to tester\logs

 
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.37931
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.18
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 10
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.09000
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.08.01 13:44:27     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000
   if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy +(Point / 2)){
                  Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                  bool Close_Half_Order_Buy = OrderClose(OrderTicket(),half,Bid,3,CLR_NONE);
                  if(Close_Half_Order_Buy!=TRUE)Print("Close_Half_Order_Buy Last Error = ", GetLastError());
                  }
That is perfect - The firsttarget_buy is exactly right. The number of lots to close, is exactly right. This all prints out on a pending order - However, it does not close at that price, even though I have it calculated correctly? I am selecting it when it is a "OP_BUY"... I'm sorry for asking all these questions, but I don't understand why this won't work?
 
DomGilberto:
That is perfect - The firsttarget_buy is exactly right. The number of lots to close, is exactly right. This all prints out on a pending order - However, it does not close at that price, even though I have it calculated correctly? I am selecting it when it is a "OP_BUY"... I'm sorry for asking all these questions, but I don't understand why this won't work?

You didn't add the print before the if( . . . .

Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );   //  add this line too . . .

if(Bid >= FirstTarget_Buy + (Point / 2) )
   {
   Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );

   //  close the Order
   }

. . . without it how do you know that Bid was greater or equal to FirstTarget_buy ? if it wasn't then the if() is not true and the Order is not partially closed . . . and if it's still a Pending order then it's not an OP_BUY.

 
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Current Bid: 1.35972 FirstTarget_Buy: 1.37931
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: FirstTarget_Buy: 1.37931
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Lots Open = 0.18
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: Order Ticker Number = 9
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lots to close is: 0.09000
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The Lotstep is: 0.01000
2013.08.01 14:19:36     2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: The minimum lots are: 0.01000

I can see when the Bid is equal to or greater than "FirstTarget_buy"? I test on a trade that runs all the way to the 2:1 reward ratio takeprofit target... So I know it goes 1:1 reward - Which is where the lots should be halved... All the print functions print out on pending orders (i.e. if there is a pending order and I stop the test, all the prints show up - however, if I stop the test after one of the pending orders has triggered, there is nothing printed out in terms of "Print", in the journal?)

I can't believe I am hung up on this - this is becoming the biggest challenge so far - yet I feel I have other things that are way more complex...

(update: I am assuming I need to monitor Bid on a tick by tick basis to pull price through and into my "for" loop?

For the "IF()" statement to be true, the Bid will eventually equal to my "FirstTarget_buy"?

 
DomGilberto:

I can see when the Bid is equal to or greater than "FirstTarget_buy"? I test on a trade that runs all the way to the 2:1 reward ratio takeprofit target... So I know it goes 1:1 reward - Which is where the lots should be halved... All the print functions print out on pending orders (i.e. if there is a pending order and I stop the test, all the prints show up - however, if I stop the test after one of the pending orders has triggered, there is nothing printed out in terms of "Print", in the journal?)

OK, now you are making progress . . . you just need to find out why a OP_BUY is not triggering your code that prints all the variables in the same way that a pending Order is . . . if you want to post that code I'll look.