Open Forex4you Account

Server รัน EA 1000 / ปี

สั่งชื้อคู่มือการโปรแรกม MQL4

Author Topic: ขอโค้ดหยุดเทรดเมื่อค่าสเปรดเกินที่เรากำหนด  (Read 34825 times)

D_Diamond

  • Hero Member
  • *****
  • Posts: 673
    • Expert Forex Trading
ลองดูโค้ดจากอีเอตัวนี้ครับ

มันมีให้ตั้งค่าแบบนี้  น่าจะตรงตามต้องการ

 Balance_Start = 0.01;
 Balance_Step = 50.0;
 Lot_Start = 0.01;
 Lot_Step = 0.01;

อีเอตัวนี้ผลงานใช้ได้เลย  แต่ไม่รู้ตั้งค่ายังไง 
http://www.myfxbook.com/members/Richart/greenbuxprofit-new/296326
http://www.myfxbook.com/members/Richart/green-norm/348759

ขอบคุณคับ คำนวนไม่เหมือนกันสักตัว เลือกใส่มะถูกเลย
« Last Edit: ตุลาคม 18, 2012, 11:42:26 am by คุยจนลิงหลับ(-.-) »

ผมนำอีเอไปทดสอบ demo ปรากฏว่าโดนเเบน ผมไม่เก่งภาษาอังกฤษ ช่วยด้วยคับ  ???
Hello!

Your account was banned. Check your EA parametrs - they are wrong and
your EA makes a lot of errors. Your EA try to modify pending order,
but this order has been executed already.

now unbanned. You may continue trading.
« Last Edit: ตุลาคม 18, 2012, 08:25:17 pm by คุยจนลิงหลับ(-.-) »

/*
   2012-09-18 by Capella at http://www.worldwide-invest.org
   - Cleaned program code
   - Adapted to 5-digit brokers
   - Moved some internals to externals
*/

#property copyright "Copyright ฉ 2009, INVESTIVA"
#property link      "www.investiva.net"

extern double TakeProfit = 50;
extern double StopLoss = 29;
extern double AddPriceGap = 20;
extern int ImaPeriod = 16;
extern double PriceToClose = 2;
extern int TradeVolume = 1;
extern bool UseHourTrade = TRUE;
extern int FromHourTrade = 0;
extern int ToHourTrade = 22;
extern bool UseMaxspread = TRUE;
extern int Maxspread = 6;

int orderticket1;
int orderticket2;
int totalorders;
int buylimits = 0;
int selllimits = 0;
int buyclose = 0;
int sellclose = 0;
double orderprice;
double stoplevel;
double buymodifyprice;
double sellmodifyprice;
double ima;
double spread;
double lotsize;
double maxSlippage;

void init()
{
   stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
   stoplevel = (stoplevel + 1.0) * Point;
   StopLoss = StopLoss * Point;
   TakeProfit = TakeProfit * Point;
   AddPriceGap = AddPriceGap * Point;
   PriceToClose = PriceToClose * Point;
   spread = Ask - Bid;
}

int start()
{
  if ( Ask - Bid <= Maxspread * Point )
  {   
   Comment("");
  }
   if (UseHourTrade)
   {
      if (!(Hour() >= FromHourTrade && Hour() <= ToHourTrade))
      {
      CloseDeleteAll();
      CloseDeleteAllNonPending();
      CloseDeleteAllCurrent();
      CloseDeleteAllCurrentNonPending();
       return (0);
      }
   }
   
   if (UseMaxspread)
   {
      if ( Ask - Bid > Maxspread * Point )
      {     
      Comment("\n Spread Over! NO Close All");
       return (0);
      }
   }

   totalorders = OrdersTotal();
   buylimits = FALSE;
   selllimits = FALSE;
   buyclose = FALSE;
   sellclose = FALSE;
   for (int l_ord_total_12 = totalorders; l_ord_total_12 >= 0; l_ord_total_12--)
   {
      if (OrderSelect(l_ord_total_12, SELECT_BY_POS) == TRUE && OrderSymbol() == Symbol())
      {
         if (OrderType() == OP_BUY)
         {
            buyclose = TRUE;
            Close_B(OrderTicket(), OrderLots());
         }
         if (OrderType() == OP_SELL)
         {
            sellclose = TRUE;
            Close_S(OrderTicket(), OrderLots());
         }
         if (OrderType() == OP_BUYLIMIT)
         {
            buymodifyprice = NormalizeDouble(OrderOpenPrice(), Digits);
            orderticket1 = OrderTicket();
            buylimits = TRUE;
         }
         if (OrderType() == OP_SELLLIMIT)
         {
            sellmodifyprice = NormalizeDouble(OrderOpenPrice(), Digits);
            orderticket2 = OrderTicket();
            selllimits = TRUE;
         }
      }
   }
   ima = iMA(NULL, 0, ImaPeriod, 0, MODE_LWMA, PRICE_TYPICAL, 0);
   Modify_order();
   Open_order();
   return/*(WARN)*/;
}

void Close_B(int a_ticket_0, double a_lots_4)
{
   if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= PriceToClose + ( Ask - Bid ))
   {
      OrderClose(a_ticket_0, a_lots_4, Bid, 1, Yellow);
      buyclose = FALSE;
   }
}

void Close_S(int a_ticket_0, double a_lots_4)
{
   if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= PriceToClose + ( Ask - Bid ))
   {
      OrderClose(a_ticket_0, a_lots_4, Ask, 1, Yellow);
      sellclose = FALSE;
   }
}

void Modify_order()
{
   if (buylimits == TRUE)
   {
      orderprice = ima - AddPriceGap;
      if (MathAbs(buymodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket1, orderprice, orderprice - StopLoss, orderprice + TakeProfit, 0, CLR_NONE);
   }
   if (selllimits == TRUE)
   {
      orderprice = ima + spread + AddPriceGap;
      if (MathAbs(sellmodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket2, orderprice, orderprice + StopLoss, orderprice - TakeProfit, 0, CLR_NONE);
   }
}

void Open_order()
{
   if (buyclose == FALSE && buylimits == FALSE)
   {
      orderprice = ima - AddPriceGap;
      if (orderprice > Ask - stoplevel)
         orderprice = Ask - stoplevel;
      orderprice = NormalizeDouble(orderprice, Digits);
      OrderSend(Symbol(), OP_BUYLIMIT, Lots(), orderprice, 3, orderprice - StopLoss, orderprice + TakeProfit, "", 0, 0, CLR_NONE);
      buylimits = TRUE;
   }
   if (sellclose == FALSE && selllimits == FALSE)
   {
      orderprice = ima + spread + AddPriceGap;
      if (orderprice < Bid + stoplevel)
         orderprice = Bid + stoplevel;
      orderprice = NormalizeDouble(orderprice, Digits);
      OrderSend(Symbol(), OP_SELLLIMIT, Lots(), orderprice, 3, orderprice + StopLoss, orderprice - TakeProfit, "", 0, 0, CLR_NONE);
      selllimits = TRUE;
   }
}

double Lots()
{
   lotsize = NormalizeDouble(AccountEquity() * TradeVolume / 100.0 / 1000.0, 1);
   double l_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT);
   if (lotsize == 0.0)
      lotsize = l_minlot_0;
   return (lotsize);
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CloseDeleteAll()
{
    int total  = OrdersTotal();
      for (int cnt = total-1 ; cnt >=0 ; cnt--)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         {
            switch(OrderType())
            {
               case OP_BUY       :
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),maxSlippage,Violet))
                     return(false);
               }break;                 
               case OP_SELL      :
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),maxSlippage,Violet))
                     return(false);
               }break;
            }             
         
           
            if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT)
               if(!OrderDelete(OrderTicket()))
               {
                  Print("Error deleting " + OrderType() + " order : ",GetLastError());
                  return (false);
               }
          }
      }
      return (true);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
// delete all on current chart
bool CloseDeleteAllCurrent()
{
    int total  = OrdersTotal();
      for (int cnt = total-1 ; cnt >=0 ; cnt--)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         {
            if(OrderSymbol()==Symbol())
            {
               switch(OrderType())
               {
                  case OP_BUY       :
                  {
                     if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),maxSlippage,Violet))
                        return(false);
                  }break;
                   
                  case OP_SELL      :
                  {
                     if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),maxSlippage,Violet))
                        return(false);
                  }break;
               }             
           
           
            if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_BUYLIMIT || OrderType()==OP_SELLLIMIT)
               if(!OrderDelete(OrderTicket()))
               {
                  return (false);
               }
            }
         }
      }
      return (true);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
// left pending orders
bool CloseDeleteAllNonPending()
{
    int total  = OrdersTotal();
      for (int cnt = total-1 ; cnt >=0 ; cnt--)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         {
            switch(OrderType())
            {
               case OP_BUY       :
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),maxSlippage,Violet))
                     return(false);
               }break;                 
               case OP_SELL      :
               {
                  if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),maxSlippage,Violet))
                     return(false);
               }break;
            }             
         }
      }
      return (true);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
// delete all on current chart left pending
bool CloseDeleteAllCurrentNonPending()
{
    int total  = OrdersTotal();
      for (int cnt = total-1 ; cnt >=0 ; cnt--)
      {
         OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         {
            if(OrderSymbol()==Symbol())
            {
               switch(OrderType())
               {
                  case OP_BUY       :
                  {
                     if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),maxSlippage,Violet))
                        return(false);
                  }break;
                   
                  case OP_SELL      :
                  {
                     if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),maxSlippage,Violet))
                        return(false);
                  }break;
               }             
            }
         }
      }
      return (true);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ผมจะเเก้ปัญหานี้ยังไงดีคับ อีเอตัวที่มีปัญหาอะ

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
แก้ If ที่เงื่อนไขที่ฟังก์ชั่นนี้ มันเป้นจริงตลอดทำให้ modify บ่อยเกินไปจนโดนแบน

void Modify_order()
{
   if (buylimits == TRUE)
   {
      orderprice = ima - AddPriceGap;
      if (MathAbs(buymodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket1, orderprice, orderprice - StopLoss, orderprice + TakeProfit, 0, CLR_NONE);
   }
   if (selllimits == TRUE)
   {
      orderprice = ima + spread + AddPriceGap;
      if (MathAbs(sellmodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket2, orderprice, orderprice + StopLoss, orderprice - TakeProfit, 0, CLR_NONE);
   }
}

แก้ If ที่เงื่อนไขที่ฟังก์ชั่นนี้ มันเป้นจริงตลอดทำให้ modify บ่อยเกินไปจนโดนแบน

void Modify_order()
{
   if (buylimits == TRUE)
   {
      orderprice = ima - AddPriceGap;
      if (MathAbs(buymodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket1, orderprice, orderprice - StopLoss, orderprice + TakeProfit, 0, CLR_NONE);
   }
   if (selllimits == TRUE)
   {
      orderprice = ima + spread + AddPriceGap;
      if (MathAbs(sellmodifyprice - orderprice) > Point / 2.0)
         OrderModify(orderticket2, orderprice, orderprice + StopLoss, orderprice - TakeProfit, 0, CLR_NONE);
   }
}

 modify บ่อยเกินไปจนโดนแบน กำ จะทำยังไงดีให้มัน   modify น้อยลง
« Last Edit: ตุลาคม 18, 2012, 08:59:54 pm by คุยจนลิงหลับ(-.-) »

the problem is that your EA us trying to modify the order than has  been already executed. So rebuild your code - to not to do it.
 ??? ??? ??? ??? ???