|
|
盈利30点将止损提高到盈利15点处。这种操作,有时候也叫平保,为了避免将盈利的单子变亏损了所做的一个保护。这种操作非常有用,很多人都会用到,通过编写ea来实现这种功能,非常简单,短短几十行代码就能实现。下面是这个程序的全部代码,感兴趣可以复制下去保存为EA就可以运行。/
/+------------------------------------------------------------------+
//| 盈利30点将止损提高到盈利15点处.mq4 |
//| 云开 |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "云开"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
input int tratp=300;//盈利多少点
input int tp=150;//止损调高到盈利多少点
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int total=OrdersTotal();
for(int i=0; i<total; i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(OrderStopLoss()<OrderOpenPrice()+tp*Point && OrderClosePrice()-OrderOpenPrice()>tratp*Point)
{
bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()+tp*Point, OrderTakeProfit(), 0);
}
}
if(OrderType()==OP_SELL)
{
if((OrderStopLoss()==0 || OrderStopLoss()>OrderOpenPrice()-tp*Point) && OrderOpenPrice()-OrderClosePrice()>tratp*Point)
{
bool res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice()-tp*Point, OrderTakeProfit(), 0);
}
}
}
}
}
}
//+------------------------------------------------------------------+
复制代码 |
|