Open Forex4you Account

Server รัน EA 1000 / ปี

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

Author Topic: มีปัญหาเกี่ยวกับ OrderDelete ครับ  (Read 7228 times)

suttisak

  • Newbie
  • *
  • Posts: 9
มีปัญหาเกี่ยวกับ OrderDelete ครับ
« on: พฤษภาคม 29, 2015, 12:03:46 pm »
ผมให้ EA pending order เมื่อเข้าเงื่อนไข แต่ถ้าหากว่า iAO เปลี่ยน ให้Delete pending ทิ้ง
แต่ที่ผมเจอคือพอขึ้นแท่งใหม่ EA ผมจะ Delete ทิ้งหมดเลย โดยที่ iAO ยังไม่เข้าเงื่อนไขครับ
ผมเป็นมือใหม่เพิ่งหัดเขียน
รบกวนท่านผู้รู้แนะนำทีครับ ผิดพลาดตรงไหน ขอบคุณครับ


void OnTick()
  {
//---
double first_price = Open[0];
double mabig = iMA(NULL,15,120,0,MODE_SMA,PRICE_CLOSE,0);
double AObig = iAO(NULL,15,0);
double ma = iMA(NULL,0,120,0,MODE_SMA,PRICE_CLOSE,0);
double AO =iAO(NULL,0,0);
int total =OrdersTotal();

PreLots = MathFloor((AccountBalance()/pos_per_lot));//Calculate lots++++++++++++
  Lots   = PreLots *0.01;
  double minlot=0.01;
    if (Lots < 0.01){Lots = 0.01;}
    if (Lots > maxlot){Lots = maxlot;}
    if (Lots < minlot){Lots= minlot;}  
    
   string now=TimeToStr(TimeCurrent(),TIME_SECONDS);
   datetime server_time=StrToTime(now);
     datetime TimeStart = StrToTime(StartTrade);
    
      if(Volume[0]<4)
      if(total < 50 )
      if(first_price > mabig && first_price > ma)
      if(AObig > 0 && AO >0)
     if(server_time = TimeStart){
     {
     OrderSend(Symbol(), OP_BUYSTOP, Lots, first_price+Distance*Point, 3, (first_price+Distance*Point)-StopLoss*Point, (first_price+Distance*Point)+TakeProfit*Point,ordercomment, MAGICMA, 2, Blue);
    
     }}
     if(Volume[0]<4)
     if(total < 50 )
     if(first_price < mabig && first_price < ma)
      if(AObig < 0 && AO < 0)
     if(server_time = TimeStart){{
     OrderSend(Symbol(), OP_SELLSTOP, Lots, first_price-Distance*Point, 3, (first_price-Distance*Point)+StopLoss*Point, (first_price-Distance*Point)-TakeProfit*Point, ordercomment, MAGICMA, 2, Red);
     }}
    
     trailingstop();
     DeleteBuyStop();
     DeleteSellStop();
    
  }
//+------------------------------------------------------------------+
 void trailingstop() {    
         for(int count=0;count<OrdersTotal();count++)      
            {OrderSelect(count,SELECT_BY_POS,MODE_TRADES);    
               if(OrderType() == OP_BUY)    
                   {if(TrailingStop > 0){      
                       if(Bid - OrderOpenPrice() > TrailingStop*Point)          
                           {if(OrderStopLoss()==0 || (Bid - OrderStopLoss()> TrailingStop*Point))      
                                {OrderModify(OrderTicket(), OrderOpenPrice(),Bid - TrailingStop*Point, OrderTakeProfit(), 0, Blue);                                  }
                           }
                      }
                  }  
                if(OrderType() == OP_SELL)
                  { if(TrailingStop > 0)
                       {if(OrderOpenPrice() - Ask > TrailingStop*Point)
                            {  
                          if(OrderStopLoss() == 0 || ( OrderStopLoss()-Ask > TrailingStop*Point ) )  
                              {OrderModify(OrderTicket(), OrderOpenPrice(),Ask + TrailingStop*Point, OrderTakeProfit(), 0, Red);                                   }
                         }
                      }
                 }  
              }
          }
          
          //====================================================//
    
    void DeleteBuyStop()
    {
    double AO =iAO(NULL,0,0);
    
    
    
    for(int i=0; i<OrdersTotal(); i++)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUYSTOP)
            if(AO < 0)
            {
            
            OrderDelete(OrderType(),clrGold);
            
            }
         }
        
       }
       //=================================================//
      
       void DeleteSellStop()
       {
    double AO =iAO(NULL,0,0);
    
  
    for(int i=0; i<OrdersTotal(); i++)
         {
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_SELLSTOP)
            if(AO > 0)
            {
            
            OrderDelete(OrderType(),clrGold);
            
            }
         }
        
       }
 //======================================================//
« Last Edit: พฤษภาคม 29, 2015, 12:31:42 pm by suttisak »

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
Re: มีปัญหาเกี่ยวกับ OrderDelete ครับ
« Reply #1 on: พฤษภาคม 29, 2015, 07:04:28 pm »
IAO อาจเข้าเงื่อนไขแล้วครับมันเลย delete ทั้งหมดครับแต่อาจจะเกิดจากสภาพตลาดที่ทำเรากลับมาดูทำให้เห็นภาพว่า IAO ยังไม่เข้าเงื่อนไข แนะนให้ใช้คำสั่ง print เพิ่มเก็บค่า Log IAO ครับแล้วเมื่อ EA มัน Delete ทั้งหมดแล้วให้กลับไปดูที่ Log ของ EA ว่า IAO เคยเข้าเงื่อนไขหรือยังครับ

suttisak

  • Newbie
  • *
  • Posts: 9
Re: มีปัญหาเกี่ยวกับ OrderDelete ครับ
« Reply #2 on: มิถุนายน 05, 2015, 10:16:11 am »
ขอบคุณครับ