EA Programing => ปัญหาที่พบในการเขียน EA => Topic started by: jack on กุมภาพันธ์ 28, 2018, 06:11:33 am

Title: EA matingel ปิด order หลายคู่อยากให้ปิดแค่คู่เดียว
Post by: jack on กุมภาพันธ์ 28, 2018, 06:11:33 am
รบกวนช่วยดู code หน่อย ว่าผมทำผิดตรงไหนครับ คือ ผมเขียน ea แล้วใส่ matingel เข้าไป ผลที่ได้คือ ถ้าราคาผิดทางจะเปิดไม้แก้ให้ จากนั้นถ้า กำไร กลับมาเป็นบวก จะสั่งปิด order แต่กลายเป็นว่า มันปิด order ของทุกคู่เลยครับ อยากให้ปิดแค่คู่เดียว  คือเวลาเล่นจะเปิดกราฟหลายคู่ครับ


//+------------------------------------------------------------------+
//--Martingale
//+------------------------------------------------------------------+

void Martin()
{
  if(Martingale)
  {
  if(CountBuy ()>0 && PriceAsk-Ask > Distance*Point && CountBuy()  < Maxorder) OpenBuy();
  if(CountSell()>0 && Bid-PriceBid > Distance*Point && CountSell() < Maxorder) OpenSell();
  }

}

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

int CountBuy()
{
  int Count=0;
  for(int i =OrdersTotal()-1;i>=0;i--)
  {
    bool res = OrderSelect(i,SELECT_BY_POS);
    if(OrderType()==OP_BUY)
    {
      Count++;
   
    }
    }
   return Count;
}

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

int CountSell()
{
  int Count=0;
  for(int i =OrdersTotal()-1;i>=0;i--)
  {
    bool res = OrderSelect(i,SELECT_BY_POS);
    if(OrderType()==OP_SELL)
    {
      Count++;
   
    }
    }
   return Count;
}

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

double NewLots()
{
  double NewLots=Lotsize;
  for(int i = OrdersTotal()-1;i>=0;i--)
  {
    bool res = OrderSelect(i,SELECT_BY_POS);
    NewLots=NewLots*Multiple;
   }
   return NewLots;
   }
   
//+------------------------------------------------------------------+   
   
   
void CloseByProfit()   
  {
  int ticket;
 
   if(AccountProfit() >= profit)
   {
      for(int i = OrdersTotal()-1;i>=0;i--)
      {
       bool res = OrderSelect(i,SELECT_BY_POS);
         ticket = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),50,clrBlack);
       
     
      }
   
   
   }
   
  }
Title: Re: EA matingel ปิด order หลายคู่อยากให้ปิดแค่คู่เดียว
Post by: mece50 on พฤศจิกายน 27, 2019, 12:56:54 am
ถ้าทำได้แล้วช่วยแชร์หน่อยได้ไหมครับ อยากรู้ด้วยครับ
Title: Re: EA matingel ปิด order หลายคู่อยากให้ปิดแค่คู่เดียว
Post by: D_Diamond on มีนาคม 25, 2020, 04:47:38 pm
ก็ต้องกำหนดให้มันสนใจแค่คู่เดียวที่อยู่บนกราฟครับ


OrderSymbol() == Symbol()
Title: Re: EA matingel ปิด order หลายคู่อยากให้ปิดแค่คู่เดียว
Post by: ufa959s on พฤษภาคม 25, 2020, 05:15:30 pm
ขอบคุณสำหรับแนวทางครับ