下载MetaTrader 5
要添加评论,请登录注册
您想知道如何使用小工具吗?阅读该文章!
PengSheng_Lin
34
PengSheng_Lin 2008.08.20 12:13 

会出现130及4109错误。更换过服务器也会出现。但用历史数据测试可以工作。

//+------------------------------------------------------------------+
//| lps_TrackProfit.mq4 |
//| Copyright ?2008, JSJ Group. |
//| http://www.PRP365.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, JSJ Group."
#property link "http://www.PRP365.com"

#define MAGICMA 20080808518
//+------------------------------------------------------------------+
//| 注意没有指标文件那些property |
//+------------------------------------------------------------------+
extern int bb = 1; //非零就允许跟踪止赢
extern double TakeProfit = 15; //止赢点数
extern double StopLoss = 20; //止损点数
extern double TrailingStop = 10; //跟踪止赢点数设置

bool flag=true;
int res;

int init() //初始化
{

return (0);
}

int deinit()
{
return (0);
} //反初始化
//主程序
int start()
{

if (flag)
{
res=OrderSend(Symbol(), OP_BUY, 0.2, Ask, 3, 0, 0, "5555555",
123, 0, Blue);
if(res<0)
{
Print("OrderSend 错误 #",GetLastError());
}

flag=false;
}


if (bb > 0)
CTP();
//跟踪止赢
return (0);
}

void CTP() //跟踪止赢
{
bool bs = false;


for (int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;

if (OrderTakeProfit()==0 || OrderStopLoss()==0)
{
if (OrderType() == OP_BUY)
bs = OrderModify(OrderTicket(), OrderOpenPrice(),
OrderOpenPrice() - StopLoss*MarketInfo(OrderSymbol(),MODE_POINT),
OrderOpenPrice() + TakeProfit*MarketInfo(OrderSymbol(),MODE_POINT),
0,Yellow);
if (OrderType() == OP_SELL)
bs = OrderModify(OrderTicket(), OrderOpenPrice(),
OrderOpenPrice() + StopLoss*MarketInfo(OrderSymbol(),MODE_POINT),
OrderOpenPrice() - TakeProfit*MarketInfo(OrderSymbol(), MODE_POINT),
0,Yellow);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}


if (OrderType() == OP_BUY)
{
Comment("止损价:",OrderStopLoss(),",","买价:",Bid,",","移动止损:",TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"买价-移动止损:",Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"赢利(买价-开仓价):",(Bid - OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
if ((Bid - OrderOpenPrice()) > (TrailingStop *MarketInfo(OrderSymbol(),MODE_POINT)))
//开仓价格 当前止损和当前价格比较判断是否要修改跟踪止赢设置
{
if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT))
{
bs = OrderModify(OrderTicket(), OrderOpenPrice(), Bid -
TrailingStop*MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit
(), 0, Green);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}
}
}
else if (OrderType() == OP_SELL)
{
Comment("止损价:",OrderStopLoss(),",","卖价:",Ask,",","移动止损:",TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"卖价+移动止损:",Ask + TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"赢利(开仓价-卖价):",(OrderOpenPrice() - Ask)/MarketInfo(OrderSymbol(),MODE_POINT));
if ((OrderOpenPrice() - Ask) > (TrailingStop *MarketInfo(OrderSymbol(),
MODE_POINT)))
//开仓价格 当前止损和当前价格比较判断是否要修改跟踪止赢设置
{
if ((OrderStopLoss()) > (Ask + TrailingStop * MarketInfo(OrderSymbol(),
MODE_POINT)))
{
bs = OrderModify(OrderTicket(), OrderOpenPrice(), Ask +
TrailingStop*MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit
(), 0, Tan);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}
}
}
}
}

loh yoke wah
33
loh yoke wah 2008.08.21 06:17  
xishuiyunkong >>

会出现130及4109错误。更换过服务器也会出现。但用历史数据测试可以工作。

//+------------------------------------------------------------------+
//| lps_TrackProfit.mq4 |
//| Copyright ?2008, JSJ Group. |
//| http://www.PRP365.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2008, JSJ Group."
#property link "http://www.PRP365.com"

#define MAGICMA 20080808518
//+------------------------------------------------------------------+
//| 注意没有指标文件那些property |
//+------------------------------------------------------------------+
extern int bb = 1; //非零就允许跟踪止赢
extern double TakeProfit = 15; //止赢点数
extern double StopLoss = 20; //止损点数
extern double TrailingStop = 10; //跟踪止赢点数设置

bool flag=true;
int res;

int init() //初始化
{

return (0);
}

int deinit()
{
return (0);
} //反初始化
//主程序
int start()
{

if (flag)
{
res=OrderSend(Symbol(), OP_BUY, 0.2, Ask, 3, 0, 0, "5555555",
123, 0, Blue);
if(res<0)
{
Print("OrderSend 错误 #",GetLastError());
}

flag=false;
}


if (bb > 0)
CTP();
//跟踪止赢
return (0);
}

void CTP() //跟踪止赢
{
bool bs = false;


for (int i = 0; i < OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false)
break;

if (OrderTakeProfit()==0 || OrderStopLoss()==0)
{
if (OrderType() == OP_BUY)
bs = OrderModify(OrderTicket(), OrderOpenPrice(),
OrderOpenPrice() - StopLoss*MarketInfo(OrderSymbol(),MODE_POINT),
OrderOpenPrice() + TakeProfit*MarketInfo(OrderSymbol(),MODE_POINT),
0,Yellow);
if (OrderType() == OP_SELL)
bs = OrderModify(OrderTicket(), OrderOpenPrice(),
OrderOpenPrice() + StopLoss*MarketInfo(OrderSymbol(),MODE_POINT),
OrderOpenPrice() - TakeProfit*MarketInfo(OrderSymbol(), MODE_POINT),
0,Yellow);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}


if (OrderType() == OP_BUY)
{
Comment("止损价:",OrderStopLoss(),",","买价:",Bid,",","移动止损:",TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"买价-移动止损:",Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"赢利(买价-开仓价):",(Bid - OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));
if ((Bid - OrderOpenPrice()) > (TrailingStop *MarketInfo(OrderSymbol(),MODE_POINT)))
//开仓价格 当前止损和当前价格比较判断是否要修改跟踪止赢设置
{
if (OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT))
{
bs = OrderModify(OrderTicket(), OrderOpenPrice(), Bid -
TrailingStop*MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit
(), 0, Green);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}
}
}
else if (OrderType() == OP_SELL)
{
Comment("止损价:",OrderStopLoss(),",","卖价:",Ask,",","移动止损:",TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"卖价+移动止损:",Ask + TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT),",",
"赢利(开仓价-卖价):",(OrderOpenPrice() - Ask)/MarketInfo(OrderSymbol(),MODE_POINT));
if ((OrderOpenPrice() - Ask) > (TrailingStop *MarketInfo(OrderSymbol(),
MODE_POINT)))
//开仓价格 当前止损和当前价格比较判断是否要修改跟踪止赢设置
{
if ((OrderStopLoss()) > (Ask + TrailingStop * MarketInfo(OrderSymbol(),
MODE_POINT)))
{
bs = OrderModify(OrderTicket(), OrderOpenPrice(), Ask +
TrailingStop*MarketInfo(OrderSymbol(), MODE_POINT), OrderTakeProfit
(), 0, Tan);
if(!bs)
Print("OrderModify 失败错误 #",GetLastError());
}
}
}
}
}

你的[extern double TrailingStop = 10; //跟踪止赢点数设置]点数太少,起码要15点以上

loh yoke wah
33
loh yoke wah 2008.08.21 06:33  
还有很多并未完成,就只能开一次仓位而已吗?
loh yoke wah
33
loh yoke wah 2008.08.21 06:38  

而且设定追踪止损毫无意义,因为都已到达止赢价位而成交了。

止赢价位必须放大至50点以上才有意义。

/
要添加评论,请登录注册