ผมลองทำแล้ว แต่ไม่รู้ทำใมมันไม่ตั้ง Pending ครับ แล้วก็ถ้ามันทำ trailingStop มันจะทำงานให้ทุกออเดอร์ รึป่าวครับ
//+------------------------------------------------------------------+
//| haha.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//|
https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link "
https://www.mql5.com"
#property version "1.00"
#property strict
extern double Lot=0.01;
extern int trailingStop =30;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(1);
return(INIT_SUCCEEDED);
}
//---
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
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);
}
}
}
else
{
if(trailingStop > 0)
{
if(OrderOpenPrice() - Ask > trailingStop*Point)
{
if(OrderStopLoss() == 0 || OrderStopLoss()-Ask > trailingStop*Point)
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask + trailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
int result = OrderDelete( OrderTicket() );
int penbuy=OrderSend(Symbol(),OP_BUYLIMIT,Lot,Bid-Point*30,3,0,0,NULL,1,0,Green);
int pensell=OrderSend(Symbol(),OP_SELLLIMIT,Lot,Ask+Point*30,3,0,0,NULL,1,0,Green);
}
//+------------------------------------------------------------------+