วันอาทิตย์ที่ 21 พฤษภาคม พ.ศ. 2560

ฝึกเขียน EA ตัวอย่างที่ 3 Trailing Stop

จุดประสงค์
เพื่อเรียนรู้วิธีการทำให้ EA มีการ Trailing Stop ติดตาม Order ที่เปิดอยู่ ตลอดเวลา

extern int Trailing =10;
int start()
  {
    if(OrdersTotal()==0)
    {
        
    
     OrderSend(Symbol(),OP_BUY,0.1,Ask,3,0,0,"EX6",0,0,Green);

     OrderSend(Symbol(),OP_SELL,0.1,Bid,3,0,0,"EX6",0,0,Red);
    
    }
    trailingstop();
   
   return(0);
  }
void trailingstop() {    
         for(int count=0;count 0){       
                       if(Bid - OrderOpenPrice() > Trailing*Point)           
                           {if(OrderStopLoss()==0 || (Bid - OrderStopLoss()> Trailing*Point))      
                                {OrderModify(OrderTicket(), OrderOpenPrice(),Bid - Trailing*Point, OrderTakeProfit(), 0, Blue);
                                  }
                           }
                      }
                  }   
                if(OrderType() == OP_SELL )
                  { if(Trailing > 0)
                       {if(OrderOpenPrice() - Ask > Trailing*Point)
                            {   
                          if(OrderStopLoss() == 0 || ( OrderStopLoss()-Ask > Trailing*Point ) )  
                              {OrderModify(OrderTicket(), OrderOpenPrice(),Ask + Trailing*Point, OrderTakeProfit(), 0, Red);
                               } 
                         }
                      }
                 }  
              }
          }

ไม่มีความคิดเห็น:

แสดงความคิดเห็น