vps and open orders

To add comments, please log in or register
Tsering Dawa Lama
228
Tsering Dawa Lama  

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);

      }

   }

//+------------------------------------------------------------------+
Sergey Golubev
Moderator
106126
Sergey Golubev  

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.

Tsering Dawa Lama
228
Tsering Dawa Lama  
Sergey Golubev:

done

thanks

To add comments, please log in or register