vps and open orders

 

what kind of code can close all open orders automatically when synchronization is done?

Is the following code responsible for closing open orders during synchronization?

I need help please. I have been banking my head for the last few days without success.

I need to keep my orders open during and after synchronization. Something to do with GlobalVariableSet,

GlobalVariableGet or HISTORY orders?


   double balance=0;

   for(i=0; i<OrdersHistoryTotal(); i++)

   {

     if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) break ;

      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

      balance+=OrderProfit();

   }

//----

   if(t_cnt==0) GlobalVariableSet("bal_2"+Symbol()+magic,balance); // t_cnt is the count of open orders

   bal_2=GlobalVariableGet("bal_2"+Symbol()+magic);

//+------------------------------------------------------------------+

   if(balance+profit>=bal_2+p_targ) closeall=true; // p_targ is target profit

   if(closeall || deleteall)

   {

      for(i=OrdersTotal()-1; i>=0; i--)

      {

      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;

         if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;

         if(closeall) deleteall=true;

         if(cmd()>1 && deleteall) closeorder2 = OrderDelete(OrderTicket());

         if(cmd()<2 && closeall)  closeorder = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,CLR_NONE);

      }

   }

//+------------------------------------------------------------------+
 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

Thank you.

 
Sergey Golubev:

done

thanks