Closing of Old Nonprofit Orders

 

Hi guys! So I have below code:

bool oldOrder()
  {

   datetime now=TimeCurrent();
   
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      bool select      =       OrderSelect(i,SELECT_BY_POS,MODE_TRADES);int ticket = OrderTicket();

      if(ticket == OrderTicket() && OrderSymbol()==_Symbol && OrderMagicNumber() == MagicNumber && select==true) {}
      if(OrderOpenTime()< Time[h] && OrderProfit() < InpTargetProfit)
        {
         Print(" OT ",OrderTicket());
         return(true);
        }

     }

   return(false);

  }

which is closing a trade if is too much time past since opening and profit is below a certain level...  the issue is that this EA opens a trade and at crtain level, is partialclosing half of the trade...at this point the profit will be smaller and will fall under the ClosingOldTrade function and it will close the trade...what I need is How to start counting the time for the new ticket which is issued after partial close...Not sure if is understandable what I just said...maybe if I catch the initial ticket into a GlobalSetVariable ?? and compare it with the second ticket after Partial Close ??

 
  1. int ticket = OrderTicket();
          if(ticket == OrderTicket() 

    That test will always be true.

  2. Remember the datetime when you do the partial close.
 
William Roeder #:
  1. That test will always be true.

    Yeah… I know… I wanted to see if after partial has been taken, if OrderOpenTime will be different… for the new ticket… sims like is not… it will be always initial opening 

  2. Remember the datetime when you do the partial close. 
Not sure how… I will try to use GlobalVariableTime… I use GVset() as a on/off switch for the partial profit… I try to get the time for switch changing with GVTime()… but I have one more question about GlobalVariables… I use GVset( string name, double AAA) in this EA for one chart… I use the same EA on another chart with the same GVset(string name,double BBB)… the value stored in memory AAA and BBB will be different… but if it is stored under the same name… when I call GVget(string name)… which value do I get… AAA or BBB ? What I mean is… whatever variables I set in chart 1 it will not interfere with the values from another chart? If they have the same name? 

 
William Roeder #:
  1. That test will always be true.

  2. Remember the datetime when you do the partial close.

I have done it...thanks !

Reason: