Closing out half lots. - page 14

 
Great advice thanks! I'll definitely try and go down that route - I don't have a fixed take profit price in relation to a pip value (i.e. always 100 pips) It's done based upon where the 60 EMA is = stop loss and final fixed TP is 1:2 (so it could be any pip value relative to the 2x pip distance of the stop loss...) It's a little more difficult for me to do it because of that...

Last question, is Normalizing the price doubles actually that crucial... I don't understand the purpose of it...?
 

Yes it can be an issue with doubles, OrderTakeProfit() OrderStopLoss() OrderLots() especially if you do calculations on them. It affected one of my EA's when I was doing something similar to your part closing of orders. Take a look at this thread https://www.mql5.com/en/forum/141034

 
Right - I have got it working perfectly... Problem is, I want to move away from If(OrderOpenPrice() > OrderStoploss())" to filter out a trade being continuously closed out at the same price...

I have tried rattling my brain but I cannot get the logic down to do it via the OrderTicket() on the "OP_BUY" as soon as it is triggered, and to the OrderTicket() number on the remaining position after half is closed?

Once the OP_BUY has been halved at OrderClose() the remaining position has a different ticket number... Can someone please enlighten me how I compare the two so that I can tell the OrderClose() to stop after is has done it once?
 
Pleasssssse - I know have exhausted this thread, but this is the last bit :)?

I have it all mint and set - Just don't understand the logic in comparing what I've written above.

I intend on making a thread to help others after I have completed this - would only be fair!
 
Anyone :(
 

I already told you how to do that, get the OrderOpenTime() of the ticket you are about to part close.. After you part closed it do OrderSelect() again whichever ticket has that same OrderOpenTime() is the remaining part of the part closed order.

 

Ah yea - Sorry, must have missed that the first time!

I've just sat and had a thought about that, and I am finding it hard to understand the logic in it? Could you give me a pointer?

At the moment I have this within the "int Start()" section:

Obviously I need to remove the "OrderOpenPrice() > OrderStopLoss()) part, but what am I replacing it with so that the "CloseHalfOrder();" will NOT be called continously? I can't get the logic down (little slow today!) Am I comparing with the trade closed in history?...

   if(OpenOrdersThisPair(Symbol())>0) //If there is a trade open = do below, which ever is applicable.
      {
      if(OrderType()==OP_BUY && OrderOpenPrice() > OrderStopLoss())
         {
         CloseHalfOrder(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
         }

      if(OrderType()==OP_SELL && OrderStopLoss() > OrderOpenPrice())
         {
         CloseHalfOrder1(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
         }   
      
 
DomGilberto:

Ah yea - Sorry, must have missed that the first time!

I've just sat and had a thought about that, and I am finding it hard to understand the logic in it? Could you give me a pointer?

At the moment I have this within the "int Start()" section:

Obviously I need to remove the "OrderOpenPrice() > OrderStopLoss()) part, but what am I replacing it with so that the "CloseHalfOrder();" will NOT be called continously? I can't get the logic down (little slow today!) Am I comparing with the trade closed in history?...

At the point I have marked in your code what Order do you have selected ?

 if(OpenOrdersThisPair(Symbol())>0) //If there is a trade open = do below, which ever is applicable.
      {

      //  order currently selected is ??
 
      if(OrderType()==OP_BUY && OrderOpenPrice() > OrderStopLoss())
         {
         CloseHalfOrder(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
         }

      if(OrderType()==OP_SELL && OrderStopLoss() > OrderOpenPrice())
         {
         CloseHalfOrder1(); // Closes half at 1:1 - then calls another void to break even on the trade +3.
         }   
      

is it the correct Order ? if it is the correct Order is that by chance or design ?

 
I thought that too - It says I need OrderSelect() before using OrderType, but it works? I only ever have one order open at any given time...

I can't think of how to use OrderOpenTime() to my advantage and stop CloseHalfOrder being called every time...
 
DomGilberto:
I thought that too - It says I need OrderSelect() before using OrderType, but it works? I only ever have one order open at any given time...

If you have the EA running on two symbols you will potentially have two Orders open at once . . . you can't test this in the Strategy Tester though, which Order will be selected then ? the right one or the wrong one ?
Reason: