止损EA在编写时出错,请大神帮改一下。
这是在网上收集到的源码,在复制到MT4后,编写会出现一个错误,不知错在哪里?请帮改一下。/*
算法如下:
1、检测所下单子(不包括挂单,不检查货币对),若单子未设置止损和止盈,则根据默认输入参数设置止损和止盈。
2、若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入移动止损状态。
3、当盈利大于移动止损值的10倍时,移动止损的值为总盈利的1/10。
函数参数如下:
double g_initstop;//初始止损
double g_initprofit;//初始止盈
double g_linestop;//移动止损触发线
double g_yd;//移动止损值
void comment;//不是此标识的不处理,0表示关闭这个判断
*/
//+------------------------------------------------------------------+
#property copyright "Dagan"
#property link ""
#include <stdlib.mqh>
/*
double g_initstop;//初始止损
double g_initprofit;//初始止盈
double g_linestop;//移动止损触发线
double g_yd;//移动止损值
void comment;//不是此标识的不处理,0表示关闭这个判断
*/
int ydstop(double g_initstop,double g_initprofit,double g_linestop,double g_yd,string comment)
{
int total=OrdersTotal(); //所有单量
for(int i=0;i<total;i++)
{
if(OrderSelect(i,SELECT_BY_POS))
{
double flag=0 ;
double price=0 ;
double realProfit=0 ;//目前真实赢利值
double takeProfit=OrderTakeProfit(); //赢利设置值
double stopLoss=OrderStopLoss();//止损设置值
if(OrderComment()!=comment && comment !="0") {continue;} //不是此标识的不处理,0表示关闭这个判断
if(OrderType()==OP_BUY) //判断买卖单后赋上目前市价
{
flag=1 ;
price=Bid ;
}
else if(OrderType()==OP_SELL)
{
flag=-1 ;
price=Ask ;
}
else
{
continue ;
}
/*----------------------------------------
1、检测所下单子(不包括挂单,不检查货币对),若单子未设置止损和止盈,则根据默认输入参数设置止损和止盈,注意止损止盈是以当前价算的,而不是入市价。
----------------------------------------*/
//Print("a"+takeProfit);
if(takeProfit<=0) //如果没有设置止盈值
{
takeProfit=OrderClosePrice()+flag*g_initprofit*Point ;
}
if(stopLoss<=0) //如果没有设置止损值
{
stopLoss=OrderClosePrice()-flag*g_initstop*Point ;
}
/*----------------------------------------
1、检测所下单子(不包括挂单,不检查货币对),若单子未设置止损和止盈,则根据默认输入参数设置止损和止盈。
end
----------------------------------------*/
/*----------------------------------------
2、若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入移动止损状态。
3、当盈利大于移动止损值的10倍时,移动止损的值为总盈利的1/10。
----------------------------------------*/
realProfit=flag*(price-OrderOpenPrice())/Point;//目前真实赢利值
if(realProfit>=g_linestop && realProfit<=g_yd*5)
{
takeProfit=price+2*flag*g_yd*Point;
stopLoss=price-flag*g_yd*Point;
}
if(realProfit>=g_linestop && realProfit>g_yd*5)
{
takeProfit=price+4*flag*g_yd*Point;
stopLoss=price-flag*0.1*realProfit*Point;
}
takeProfit=NormalizeDouble(takeProfit,Digits);
stopLoss=NormalizeDouble(stopLoss,Digits);
/*----------------------------------------
2、若单子发生盈利,并达到移动止损触发线,则动态提高原有止损线,进入移动止损状态。
3、当盈利大于移动止损值的10倍时,移动止损的值为总盈利的1/10。
end
----------------------------------------*/
//止损止赢下达操作
//Print("b"+takeProfit);
//Print("c"+OrderStopLoss());
if((flag==1 && (stopLoss>OrderStopLoss() || takeProfit>OrderTakeProfit())) ||
(flag==-1 && (stopLoss<OrderStopLoss() || takeProfit<OrderTakeProfit())) ||
OrderStopLoss()==0 || OrderTakeProfit()==0
)
{
RefreshRates();
Print("w_order before modify: tk("+OrderTicket()+"), sl("+DoubleToStr(OrderStopLoss(),Digits)+"), tp("+DoubleToStr(OrderTakeProfit(),Digits)+"),stopLoss:"+stopLoss+",takeProfit:"+takeProfit);
OrderModify(OrderTicket(),OrderOpenPrice(),stopLoss,takeProfit,0);
w_error ();
}
}
}
return(0);
}
//--------------以下为函数--------------------------
double w_error ()
{
int error=GetLastError();
if (error!=0)
{
if (!(error == 4/* SERVER_BUSY */ || error == 137/* BROKER_BUSY */ || error == 146/* TRADE_CONTEXT_BUSY */ || error == 136/* OFF_QUOTES */)) Print("w_ticket_ErrorCode = "+error+",Description = "+ErrorDescription(error));
else
{
Print("w_ticket_ErrorCode = "+error+",Description = "+ErrorDescription(error));
Sleep(1000);
}
}
return(error);
}
各位大神,请指点一下。 请懂得的老师指点一下,谢谢! 错误代码是什么?我也不是太懂
偏安一隅的菜鸟 发表于 2015-10-31 21:20
错误代码是什么?我也不是太懂
你试自制到MT4,编写一下,就知道了。
结构错误
ea 没有主程式
只有子程式 柒侠伍义 发表于 2015-11-1 00:23
结构错误
ea 没有主程式
只有子程式
要怎么改,可以帮忙吗?
回复有真情,积分算目标,赚钱是唯一,学习更努力 先顶。顶多了 先顶。顶多了
回复含真情,学习有目标,赚钱是唯一,一起来努力。
页:
[1]