myeatrade

社区

请教各位前辈,谁能帮忙改编这个ea

tmxk201009 tmxk201009 2012-09-12 14:47
请问各位前辈,下面的ea为什么不能开单:
代码: 全选

//+------------------------------------------------------------------+
// Copyright , myEAtrade
// http://www.myEAtrade.com
// System Name: 趋势均线交叉
// Automatically generated by the myEAtrade.com
// at Wednesday 12th of September 2012 02:39:58 PM
//+------------------------------------------------------------------+
#property copyright \"myEAtrade , www.myeatrade.com\"
#property link \"http://www.myeatrade.com/\"




///////////////////////////Model1////////////////////////////
extern string Model1_tip=\"ema5与ema13在ema55之上,金\";
extern int Model1_CalculateModel=2;
extern int Model1_CalculateModelTimeframe=0;
extern double Model1_DefaultLots=0.01;
extern bool Model1_MoneyManagement=0;
extern double Model1_Risk=2;
extern int Model1_LotDigits=2;
extern double Model1_MinLots=0.01;
extern double Model1_MaxLots=0.01;
extern int Model1_StopLoss=0;
extern int Model1_TakeProfit=150;
extern int Model1_BreakEven=0;
extern int Model1_TrailMode=2;
extern int Model1_TrailStart=50;
extern int Model1_TrailStop=20;
extern int Model1_MaxSpread=3;
extern int Model1_Slippage=0;
extern bool Model1_ECN=1;
extern bool Model1_MultiOrder=0;
extern int Model1_MaxOrder=1;
extern int Model1_MultiOrderTimeInterval=60;
extern bool Model1_InstantOrder=1;
extern bool Model1_StopOrder=0;
extern bool Model1_LimitOrder=0;
extern int Model1_PendingGap=20;
extern int Model1_PendingExpiration=720;
bool Model1_AutoTrade=1;string Model1_Symbol;double Model1_Point;int Model1_Mt;datetime Model1_lastOpenOrderTime;

///////////////////////////Model2////////////////////////////
extern string Model2_tip=\"eam5与ema13在ema55之下,死\";
extern int Model2_CalculateModel=1;
extern int Model2_CalculateModelTimeframe=0;
extern double Model2_DefaultLots=0.01;
extern bool Model2_MoneyManagement=0;
extern double Model2_Risk=2;
extern int Model2_LotDigits=2;
extern double Model2_MinLots=0.01;
extern double Model2_MaxLots=0.01;
extern int Model2_StopLoss=0;
extern int Model2_TakeProfit=150;
extern int Model2_BreakEven=0;
extern int Model2_TrailMode=2;
extern int Model2_TrailStart=50;
extern int Model2_TrailStop=20;
extern int Model2_MaxSpread=3;
extern int Model2_Slippage=0;
extern bool Model2_ECN=0;
extern bool Model2_MultiOrder=0;
extern int Model2_MaxOrder=5;
extern int Model2_MultiOrderTimeInterval=5;
extern bool Model2_InstantOrder=1;
extern bool Model2_StopOrder=0;
extern bool Model2_LimitOrder=0;
extern int Model2_PendingGap=20;
extern int Model2_PendingExpiration=720;
bool Model2_AutoTrade=1;string Model2_Symbol;double Model2_Point;int Model2_Mt;datetime Model2_lastOpenOrderTime;

datetime lastBarTime[3];


int maxtry=10;
bool printLog=true;

int init(){
Model1_Symbol=Symbol(); double m1_point = MarketInfo(Model1_Symbol,MODE_POINT); int m1_digits = MarketInfo(Model1_Symbol,MODE_DIGITS); if(m1_digits==3 || m1_digits==5){
Model1_Point=m1_point*10;
Model1_Mt=10;
}else{
Model1_Point=m1_point;
Model1_Mt=1;
}
Model2_Symbol=Symbol(); double m2_point = MarketInfo(Model2_Symbol,MODE_POINT); int m2_digits = MarketInfo(Model2_Symbol,MODE_DIGITS); if(m2_digits==3 || m2_digits==5){
Model2_Point=m2_point*10;
Model2_Mt=10;
}else{
Model2_Point=m2_point;
Model2_Mt=1;
}

}

int start(){
runModel1();runModel2();
return (0);
}


void runModel1(){
int totalPosition = countPositionByMagic(2100);
if( Model1_MaxSpread>0 && (MarketInfo(Model1_Symbol,MODE_ASK)-MarketInfo(Model1_Symbol,MODE_BID))>Model1_MaxSpread*Model1_Point )return;
if((Model1_CalculateModel!=0)&&(!isNewBar(Model1_Symbol,Model1_CalculateModelTimeframe,1))) return;
bool canRunCheck=false;
if(!Model1_MultiOrder)Model1_MaxOrder=1;
if(totalPosition<Model1_MaxOrder)canRunCheck=true;
if(Model1_MaxOrder>1&&totalPosition>=1){
if(TimeCurrent()<(Model1_lastOpenOrderTime+Model1_MultiOrderTimeInterval*60))canRunCheck=false;
}
if(Model1_BreakEven>0&&totalPosition>0)breakEven(2100,Model1_BreakEven,Model1_Point);
if(Model1_TrailMode>0&&Model1_TrailMode<=2&&totalPosition>0)trailStop(2100,Model1_TrailMode,Model1_TrailStart,Model1_TrailStop,Model1_Point);
if(canRunCheck){
}
}
void runModel2(){
int totalPosition = countPositionByMagic(2101);
if( Model2_MaxSpread>0 && (MarketInfo(Model2_Symbol,MODE_ASK)-MarketInfo(Model2_Symbol,MODE_BID))>Model2_MaxSpread*Model2_Point )return;
if((Model2_CalculateModel!=0)&&(!isNewBar(Model2_Symbol,Model2_CalculateModelTimeframe,2))) return;
bool canRunCheck=false;
if(!Model2_MultiOrder)Model2_MaxOrder=1;
if(totalPosition<Model2_MaxOrder)canRunCheck=true;
if(Model2_MaxOrder>1&&totalPosition>=1){
if(TimeCurrent()<(Model2_lastOpenOrderTime+Model2_MultiOrderTimeInterval*60))canRunCheck=false;
}
if(Model2_BreakEven>0&&totalPosition>0)breakEven(2101,Model2_BreakEven,Model2_Point);
if(Model2_TrailMode>0&&Model2_TrailMode<=2&&totalPosition>0)trailStop(2101,Model2_TrailMode,Model2_TrailStart,Model2_TrailStop,Model2_Point);
if(canRunCheck){
}
}


bool isNewBar(string s,int timeframe,int model){
datetime currentBarTime = iTime(s,timeframe,0);
if(lastBarTime[model]!=currentBarTime){
lastBarTime[model] = currentBarTime;
return (true);
}else{
return (false);
}
}


double getlots(double DefaultLots,bool MoneyManage,double Risk,double StopLoss,string symbol,int mt,int LotDigits,double MinLots,double MaxLots){
double lot;
if(MoneyManage){
if(StopLoss>0)lot=NormalizeDouble((AccountEquity()*(Risk/100))/(MarketInfo(symbol,MODE_TICKVALUE)*mt*StopLoss ),LotDigits);
else lot= NormalizeDouble(AccountEquity()/10000,LotDigits);
if(lot<MinLots)lot=MinLots;
if(lot>MaxLots)lot=MaxLots;
}else lot=DefaultLots;
return(lot);
}


int openposition(string symbol,int type,double lots,double StopLoss,double TakeProfit,int magic,bool ECN,bool InstantOrder,bool StopOrder,bool LimitOrder,int Gap,int Expiration,double point,int mt,int Slippage){
int ticket=0;int expire=0;int try=0;
if(StopOrder || LimitOrder)if(Expiration>0)expire=TimeCurrent()+(Expiration*60);
if(type==OP_BUY){//buy
if(ECN){
if(InstantOrder){
while(ticket<=0 && try<maxtry){
RefreshRates();
ticket=open(symbol,OP_BUY,lots,Ask,0,0,magic,expire,point,mt,Slippage,Blue);
if(ticket<0){try++;if(printLog)Print(\"Error opening Instant BUY order!\",errordescription(GetLastError()),\" retry \"+try+\" times\");}
if(ticket>0){ecnsltpLong(ticket,StopLoss,TakeProfit,point);}
}
}
if(StopOrder){
RefreshRates();
ticket=open(symbol,OP_BUYSTOP,lots,Ask+Gap*point,0,0,magic,expire,point,mt,Slippage,Blue);
if(ticket>0){ecnsltpLong(ticket,StopLoss,TakeProfit,point);}
}
if(LimitOrder){
RefreshRates();
ticket=open(symbol,OP_BUYLIMIT,lots,Bid-Gap*point,0,0,magic,expire,point,mt,Slippage,Blue);
if(ticket>0){ecnsltpLong(ticket,StopLoss,TakeProfit,point);}
}
}else{
if(InstantOrder){
while(ticket<=0 && try<maxtry){
RefreshRates();
ticket=open(symbol,OP_BUY,lots,Ask,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Blue);
if(ticket<0){try++;if(printLog)Print(\"Error opening Instant BUY order!\",errordescription(GetLastError()),\" retry \"+try+\" times\");}
}
}
if(StopOrder){RefreshRates();ticket=open(symbol,OP_BUYSTOP,lots,Ask+Gap*point,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Blue);}
if(LimitOrder){RefreshRates();ticket=open(symbol,OP_BUYLIMIT,lots,Bid-Gap*point,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Blue);}
}
}else if(type==OP_SELL){ // Sell
if(ECN){
if(InstantOrder){
while(ticket<=0 && try<maxtry){
RefreshRates();
ticket=open(symbol,OP_SELL,lots,Bid,0,0,magic,expire,point,mt,Slippage,Red);
if(ticket<0){try++;if(printLog)Print(\"Error opening Instant SELL order!\",errordescription(GetLastError()),\" retry \"+try+\" times\");}
if(ticket>0){ecnsltpShort(ticket,StopLoss,TakeProfit,point);}
}
}
if(StopOrder){
RefreshRates();
ticket=open(symbol,OP_SELLSTOP,lots,Bid-Gap*point,0,0,magic,expire,point,mt,Slippage,Red);
if(ticket>0){ecnsltpShort(ticket,StopLoss,TakeProfit,point);}
}
if(LimitOrder){
RefreshRates();
ticket=open(symbol,OP_SELLLIMIT,lots,Ask+Gap*point,0,0,magic,expire,point,mt,Slippage,Red);
if(ticket>0){ecnsltpShort(ticket,StopLoss,TakeProfit,point);}
}
}else{
if(InstantOrder){
while(ticket<=0 && try<maxtry){
RefreshRates();
ticket=open(symbol,OP_SELL,lots,Bid,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Red);
if(ticket<0){try++;if(printLog)Print(\"Error opening Instant SELL order!\",errordescription(GetLastError()),\" retry \"+try+\" times\");}
}
}
if(StopOrder){RefreshRates();ticket=open(symbol,OP_SELLSTOP,lots,Bid-Gap*point,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Red);}
if(LimitOrder){RefreshRates();ticket=open(symbol,OP_SELLLIMIT,lots,Ask+Gap*point,StopLoss,TakeProfit,magic,expire,point,mt,Slippage,Red);}
}
}

return (ticket);
}


int open(string symbol,int type,double lots,double price,double stoploss,double takeprofit,int magic, int expire,double point,int mt,int Slippage,color clr){
int ticket=0;
double sl,tp;
if(type==OP_BUY || type==OP_BUYSTOP || type==OP_BUYLIMIT){
if(stoploss>0){sl=price-stoploss*point;}else{sl=0;}
if(takeprofit>0){tp=price+takeprofit*point;}else{tp=0;}
}
if(type==OP_SELL || type==OP_SELLSTOP || type==OP_SELLLIMIT){
if(stoploss>0){sl=price+stoploss*point;}else{sl=0;}
if(takeprofit>0){tp=price-takeprofit*point;}else{tp=0;}
}
ticket=OrderSend(symbol,type,lots,NormalizeDouble(price,Digits),Slippage*mt,sl,tp,\"Prower by myeatrade.com\",magic,expire,clr);
return(ticket);
}

datetime getOrderOpenTime(int ticket){
OrderSelect(ticket,SELECT_BY_TICKET);
return (OrderOpenTime());
}



void ecnsltpLong(int ticket,double StopLoss,double TakeProfit,double point){
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderStopLoss()==0&&StopLoss>0){
RefreshRates();
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-StopLoss*point,Digits),OrderTakeProfit(),0,Blue);
}
RefreshRates();
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderTakeProfit()==0&&TakeProfit>0){
RefreshRates();
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+TakeProfit*point,Digits),0,Blue);
}
}

void ecnsltpShort(int ticket,double StopLoss,double TakeProfit,double point){
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderStopLoss()==0&&StopLoss>0){
RefreshRates();
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+StopLoss*point,Digits),OrderTakeProfit(),0,Blue);
}
RefreshRates();
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderTakeProfit()==0&&TakeProfit>0){
RefreshRates();
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-TakeProfit*point,Digits),0,Blue);
}
}


int countPositionByMagic(int magic){
int count=0;
if(OrdersTotal()>0){
for(int i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic)count++;
}
return(count);
}
}



void breakEven(int magic,int BreakEven,double point){
RefreshRates();
if(OrdersTotal()>0){
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderMagicNumber()==magic){
if(OrderType()==OP_BUY){
if( NormalizeDouble((Bid-OrderOpenPrice()),Digits)>=NormalizeDouble(BreakEven*point,Digits)){
if( (OrderStopLoss()-OrderOpenPrice())<0)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
}
}else{
if( NormalizeDouble((OrderOpenPrice()-Ask),Digits)>=NormalizeDouble(BreakEven*point,Digits)){
if(((OrderOpenPrice()-OrderStopLoss())<0)||(OrderStopLoss()==0))
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
}
}
}
}
}
}


void trailStop(int magic,int TrailMode,int TrailStart,int TrailStop,double point){
RefreshRates();
if(OrdersTotal()>0){
for(int i=0;i<OrdersTotal();i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && OrderMagicNumber()==magic){
if(OrderType()==OP_BUY){
if( NormalizeDouble((Bid-OrderOpenPrice()),Digits)>=NormalizeDouble(TrailStart*point,Digits)){
if(TrailMode==1){
if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-TrailStop*point,Digits)){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailStop*point,Digits),OrderTakeProfit(),0,Blue);
}
}
if(TrailMode==2){
if(Bid-TrailStop*point >=OrderStopLoss()+TrailStop*point){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-TrailStop*point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}else{
if( NormalizeDouble((OrderOpenPrice()-Ask),Digits)>=NormalizeDouble(TrailStart*point,Digits)){
if(TrailMode==1){
if( (NormalizeDouble(OrderStopLoss(),Digits) > NormalizeDouble(Ask+TrailStop*point,Digits)) || OrderStopLoss()==0 ){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailStop*point,Digits),OrderTakeProfit(),0,Red);
}
}
if(TrailMode==2){
if((Ask+TrailStop*point <=OrderStopLoss()-TrailStop*point) || OrderStopLoss()==0 ){
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailStop*point,Digits),OrderTakeProfit(),0,Blue);
}
}
}
}
}
}
}
}



string errordescription(int code){
string error;
switch(code){
case 0:
case 1:error=\"no error\";break;
case 2:error=\"common error\";break;
case 3:error=\"invalid trade parameters\";break;
case 4:error=\"trade server is busy\";break;
case 5:error=\"old version of the client terminal\";break;
case 6:error=\"no connection with trade server\";break;
case 7:error=\"not enough rights\";break;
case 8:error=\"too frequent requests\";break;
case 9:error=\"malfunctional trade operation\";break;
case 64:error=\"account disabled\";break;
case 65:error=\"invalid account\";break;
case 128:error=\"trade timeout\";break;
case 129:error=\"invalid price\";break;
case 130:error=\"invalid stops\";break;
case 131:error=\"invalid trade volume\";break;
case 132:error=\"market is closed\";break;
case 133:error=\"trade is disabled\";break;
case 134:error=\"not enough money\";break;
case 135:error=\"price changed\";break;
case 136:error=\"off quotes\";break;
case 137:error=\"broker is busy\";break;
case 138:error=\"requote\";break;
case 139:error=\"order is locked\";break;
case 140:error=\"long positions only allowed\";break;
case 141:error=\"too many requests\";break;
case 145:error=\"modification denied because order too close to market\";break;
case 146:error=\"trade context is busy\";break;
case 4000:error=\"no error\";break;
case 4001:error=\"wrong function pointer\";break;
case 4002:error=\"array index is out of range\";break;
case 4003:error=\"no memory for function call stack\";break;
case 4004:error=\"recursive stack overflow\";break;
case 4005:error=\"not enough stack for parameter\";break;
case 4006:error=\"no memory for parameter string\";break;
case 4007:error=\"no memory for temp string\";break;
case 4008:error=\"not initialized string\";break;
case 4009:error=\"not initialized string in array\";break;
case 4010:error=\"no memory for array\\\' string\";break;
case 4011:error=\"too long string\";break;
case 4012:error=\"remainder from zero divide\";break;
case 4013:error=\"zero divide\";break;
case 4014:error=\"unknown command\";break;
case 4015:error=\"wrong jump (never generated error)\";break;
case 4016:error=\"not initialized array\";break;
case 4017:error=\"dll calls are not allowed\";break;
case 4018:error=\"cannot load library\";break;
case 4019:error=\"cannot call function\";break;
case 4020:error=\"expert function calls are not allowed\";break;
case 4021:error=\"not enough memory for temp string returned from function\";break;
case 4022:error=\"system is busy (never generated error)\";break;
case 4050:error=\"invalid function parameters count\";break;
case 4051:error=\"invalid function parameter value\";break;
case 4052:error=\"string function internal error\";break;
case 4053:error=\"some array error\";break;
case 4054:error=\"incorrect series array using\";break;
case 4055:error=\"custom indicator error\";break;
case 4056:error=\"arrays are incompatible\";break;
case 4057:error=\"global variables processing error\";break;
case 4058:error=\"global variable not found\";break;
case 4059:error=\"function is not allowed in testing mode\";break;
case 4060:error=\"function is not confirmed\";break;
case 4061:error=\"send mail error\";break;
case 4062:error=\"string parameter expected\";break;
case 4063:error=\"integer parameter expected\";break;
case 4064:error=\"double parameter expected\";break;
case 4065:error=\"array as parameter expected\";break;
case 4066:error=\"requested history data in update state\";break;
case 4099:error=\"end of file\";break;
case 4100:error=\"some file error\";break;
case 4101:error=\"wrong file name\";break;
case 4102:error=\"too many opened files\";break;
case 4103:error=\"cannot open file\";break;
case 4104:error=\"incompatible access to a file\";break;
case 4105:error=\"no order selected\";break;
case 4106:error=\"unknown symbol\";break;
case 4107:error=\"invalid price parameter for trade function\";break;
case 4108:error=\"invalid ticket\";break;
case 4109:error=\"trade is not allowed\";break;
case 4110:error=\"longs are not allowed\";break;
case 4111:error=\"shorts are not allowed\";break;
case 4200:error=\"object is already exist\";break;
case 4201:error=\"unknown object property\";break;
case 4202:error=\"object is not exist\";break;
case 4203:error=\"unknown object type\";break;
case 4204:error=\"no object name\";break;
case 4205:error=\"object coordinates error\";break;
case 4206:error=\"no specified subwindow\";break;
default:error=\"unknown error\";
}
return(error);
}

有愿意帮忙改编的吗?谢谢!!!


tmxk201009 tmxk201009 2012-09-20 08:48
请问各位,为什么这个网站编的ea都只能测试不能下单呢?我做了10几个了,没有一个能在模拟账户下单的,烦得要命!!!请高人指点,万分感谢!!!!!!!!!!
bfhybfhy bfhybfhy 2012-10-10 11:15
同样的问题。没有管理员吗??
myeatrade myeatrade 2012-10-10 15:27
只能测试,不能在模拟或真实账户下实时交易可以参考以下解决方法:

http://www.myeatrade.com/zh/community/?topic=1214

如果有问题和其他建议在 “意见与反馈” 版块下发表,会及时跟进和回复的。
dfhuihai dfhuihai 2012-10-22 17:06
好复杂的均线交叉
Page 1 of 1 1

请登录后发表回复,如果你还没有账户你可以 免费注册

回到 交易系统 & 指标
menu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loadermenu image pre-loader