วันศุกร์ที่ 28 เมษายน พ.ศ. 2560

function Close Order สำหรับ MQL4

ส่วนของ Close Buy Order หรือ ปิด Order ฝั่ง Buy ทั้งหมด

------------------------------------------------------------------------------------------------------------
void CloseBuyOrder()

  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();
    bool result = false;
  
    switch(type)
    {
      //Close opened long positions
      case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
                          break;
      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );
    }
  
    if(result == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    } 
  }
}
--------------------------------------------------------------------------------------------------------------------

ส่วนของ Close Sell Order หรือปิดการซื้อขายฝั่ง Sell 
--------------------------------------------------------------------------------------------------------------------
void CloseSellOrder()
{
  int total = OrdersTotal();
  for(int i=total-1;i>=0;i--)
  {
    OrderSelect(i, SELECT_BY_POS);
    int type   = OrderType();
    bool result = false;
  
    switch(type)
    {   
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                          break;
      //Close pending orders
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
  
    if(result == false)
    {
      Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      Sleep(3000);
    } 
  }
}
-------------------------------------------------------------------------------------------------------------------------

วิธีขายจากกลุ่มสิงค์โปร

  BUY USDJPY 115.14   SL: 114.84 TP1: 115.34 TP2: 115.54 TP3: 115.74 SL 50 จุด tp 1 :20 tp 2 :40 tp 3 :60 ถ้าซื้อ 3 order ไป TP 1,2,3 profit...