废了半天劲,就是不执行,实在晕菜了,大神们帮忙看看吧,谢谢了。
//+------------------------------------------------------------------+
// Copyright , myEAtrade
// http://www.myEAtrade.com
// System Name: 999
// Automatically generated by the myEAtrade.com
// at Friday 03rd of April 2015 10:24:46 AM
//+------------------------------------------------------------------+
#property copyright "myEAtrade , www.myeatrade.com"
#property link "http://www.myeatrade.com/"
///////////////////////////Model1////////////////////////////
extern string Model1_tip="999";
string M1_Symbol;double M1_Point;int M1_Mt;datetime Model1_lastOpenOrderTime;
extern string M1S1_tip="Strategy Group1";
extern string M1S1_Filter_tip="Filter Conditions";
extern string M1S1C1_Filter_tip="Filter Condition 1";
extern string M1S1_Exec_tip="Execution Conditions";
extern string M1S1C1_Exec_tip="Execution Condition 1";
extern string M1S1_Shift_tip="Shift Conditions";
///////////////////////////Model2////////////////////////////
extern string Model2_tip="999";
string M2_Symbol;double M2_Point;int M2_Mt;datetime Model2_lastOpenOrderTime;
extern string M2S1_tip="Strategy Group1";
extern string M2S1_Filter_tip="Filter Conditions";
extern string M2S1C1_Filter_tip="Filter Condition 1";
extern string M2S1_Exec_tip="Execution Conditions";
extern string M2S1C1_Exec_tip="Execution Condition 1";
extern string M2S1_Shift_tip="Shift Conditions";
///////////////////////////Model3////////////////////////////
extern string Model3_tip="999";
string M3_Symbol;double M3_Point;int M3_Mt;datetime Model3_lastOpenOrderTime;
extern string M3S1_tip="Strategy Group1";
extern string M3S1_Filter_tip="Filter Conditions";
extern string M3S1_Exec_tip="Execution Conditions";
extern string M3S1C1_Exec_tip="Execution Condition 1";
extern string M3S1_Shift_tip="Shift Conditions";
///////////////////////////Model4////////////////////////////
extern string Model4_tip="999";
string M4_Symbol;double M4_Point;int M4_Mt;datetime Model4_lastOpenOrderTime;
extern string M4S1_tip="Strategy Group1";
extern string M4S1_Filter_tip="Filter Conditions";
extern string M4S1_Exec_tip="Execution Conditions";
extern string M4S1C1_Exec_tip="Execution Condition 1";
extern string M4S1_Shift_tip="Shift Conditions";
double m1s1filter1_A_val[2];
double m1s1exec1_A_val[3];double m1s1exec1_B_val[3];
double m2s1filter1_A_val[2];
double m2s1exec1_A_val[3];double m2s1exec1_B_val[3];
double m3s1exec1_A_val[3];double m3s1exec1_B_val[3];
double m4s1exec1_A_val[3];double m4s1exec1_B_val[3];
datetime lastBarTime[5];
int modelMagic[5];
bool canClose31=true;
bool closeOneTime31=1;
bool canClose41=true;
bool closeOneTime41=1;
int maxtry=10;
bool printLog=true;
int sleepTime=2000;
int init{
M1_Symbol=Symbol; double m1_point = MarketInfo; int m1_digits = MarketInfo; if{
M1_Point=m1_point*10;
M1_Mt=10;
}else{
M1_Point=m1_point;
M1_Mt=1;
}
modelMagic[1]=51255;
M2_Symbol=Symbol; double m2_point = MarketInfo; int m2_digits = MarketInfo; if{
M2_Point=m2_point*10;
M2_Mt=10;
}else{
M2_Point=m2_point;
M2_Mt=1;
}
modelMagic[2]=51256;
M3_Symbol=Symbol; double m3_point = MarketInfo; int m3_digits = MarketInfo; if{
M3_Point=m3_point*10;
M3_Mt=10;
}else{
M3_Point=m3_point;
M3_Mt=1;
}
modelMagic[3]=51257;
M4_Symbol=Symbol; double m4_point = MarketInfo; int m4_digits = MarketInfo; if{
M4_Point=m4_point*10;
M4_Mt=10;
}else{
M4_Point=m4_point;
M4_Mt=1;
}
modelMagic[4]=51258;
}
int start{
runModel1;runModel2;runModel3;runModel4;
return ;
}
void runModel1{
int totalPosition = countPositionByMagicSymbol;
if-MarketInfo)>10*M1_Point )return;
if&&)) return;
bool canRunCheck=false;
int maxOrder=5;
ifmaxOrder=1;
ifcanRunCheck=true;
if{
if10*M2_Point )return;
if&&)) return;
bool canRunCheck=false;
int maxOrder=5;
ifmaxOrder=1;
ifcanRunCheck=true;
if{
if10*M1_Point )spread31=false;
if{
if){
bool allClose;
if{
allClose=closeModelPosition;
ifcanClose31=false;
if){ifcanClose31=true;}
}
}
}
}
void runModel4{
if&&)) return;
bool canRunCheck=false;
if){canRunCheck=true;}else{ifcanClose41=true;}
bool spread41=true; if-MarketInfo)>10*M2_Point )spread41=false;
if{
if){
bool allClose;
if{
allClose=closeModelPosition;
ifcanClose41=false;
if){ifcanClose41=true;}
}
}
}
}
bool checkM1S1{
int i;
int limit = 100; bool reValue=false;
int preBar=0;
ifpreBar=1;
bool filter12=true;
bool filter34=true;
if{
int f34cBar111=3; iff34cBar111=2;
for{
m1s1filter1_A_val[i]=iSAR,5,0.02,0.2,i);
}
for{
if{filter34=false;break;}
}
}
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if{
int e12cBar111=2; ife12cBar111=2;
for{
m1s1exec1_A_val[i]=iStochastic,1,5,3,3,0,0,0,i);
}
for{
m1s1exec1_B_val[i]=iStochastic,1,5,3,3,0,0,1,i);
}
exec12_temp=true;
if)){exec12_temp=false;}
if{
for{
if){exec12_temp=false;}
}
}
ifexec12_b=false;
if{
if{exec12_temp=false;}
}
ifexec12_a=true;
}
ifexec12=true;
bool bshift=true;
ifreValue=true;
return ;
}
bool checkM2S1{
int i;
int limit = 100; bool reValue=false;
int preBar=0;
ifpreBar=1;
bool filter12=true;
bool filter34=true;
if{
int f34cBar211=3; iff34cBar211=2;
for{
m2s1filter1_A_val[i]=iSAR,5,0.02,0.2,i);
}
for{
if{filter34=false;break;}
}
}
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if{
int e12cBar211=2; ife12cBar211=2;
for{
m2s1exec1_A_val[i]=iStochastic,1,5,3,3,0,0,0,i);
}
for{
m2s1exec1_B_val[i]=iStochastic,1,5,3,3,0,0,1,i);
}
exec12_temp=true;
if)){exec12_temp=false;}
if{
for{
if){exec12_temp=false;}
}
}
ifexec12_b=false;
if{
if{exec12_temp=false;}
}
ifexec12_a=true;
}
ifexec12=true;
bool bshift=true;
ifreValue=true;
return ;
}
bool checkM3S1{
int i;
int limit = 100; bool reValue=false;
int preBar=0;
ifpreBar=1;
bool filter12=true;
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if{
int e12cBar311=2; ife12cBar311=2;
for{
m3s1exec1_A_val[i]=iStochastic,1,5,3,3,0,0,0,i);
}
for{
m3s1exec1_B_val[i]=iStochastic,1,5,3,3,0,0,1,i);
}
exec12_temp=true;
if)){exec12_temp=false;}
if{
for{
if){exec12_temp=false;}
}
}
ifexec12_b=false;
if{
if{exec12_temp=false;}
}
ifexec12_a=true;
}
ifexec12=true;
bool bshift=true;
ifreValue=true;
return ;
}
bool checkM4S1{
int i;
int limit = 100; bool reValue=false;
int preBar=0;
ifpreBar=1;
bool filter12=true;
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if{
int e12cBar411=2; ife12cBar411=2;
for{
m4s1exec1_A_val[i]=iStochastic,1,5,3,3,0,0,0,i);
}
for{
m4s1exec1_B_val[i]=iStochastic,1,5,3,3,0,0,1,i);
}
exec12_temp=true;
if)){exec12_temp=false;}
if{
for{
if){exec12_temp=false;}
}
}
ifexec12_b=false;
if{
if{exec12_temp=false;}
}
ifexec12_a=true;
}
ifexec12=true;
bool bshift=true;
ifreValue=true;
return ;
}
bool isNewBar{
datetime currentBarTime = iTime;
if{
lastBarTime[model] = currentBarTime;
return ;
}else{
return ;
}
}
bool checkCanOpenMaxOrder{
bool result=true;int i,count=0;double profitPip;
switch{
case 0: result=true;break;
case 1:
for;i>=0;i--){
OrderSelect;
if==symbol&&OrderMagicNumber==magic){
count++;
if>0)){result=false;break;}
if{
if==OP_BUY)profitPip = ,MODE_BID) - OrderOpenPrice)/point;
if==OP_SELL)profitPip = - MarketInfo,MODE_ASK))/point;
if){result=false;break;}
}
}
}
break;
case 2:
for;i>=0;i--){
OrderSelect;
if==symbol&&OrderMagicNumber==magic){
count++;
ifpip)){result=false;break;}
}
}
}
break;
}
return ;
}
double getlots{
double lot;
if{
int LotDigits=0;
if==0.1)LotDigits=1;
else if==0.01)LotDigits=2;
else if==0.001)LotDigits=3;
iflot=NormalizeDouble*)/*mt*StopLoss ),LotDigits);
else lot= NormalizeDouble/10000*Risk,LotDigits);
iflot=MinLots;
iflot=MaxLots;
}else lot=DefaultLots;
return;
}
int openposition{
int ticket=0;int expire=0;int try=0;
ififexpire=TimeCurrent+;
double ask=MarketInfo;double bid=MarketInfo;
if{//buy
if{
if{
while{
RefreshRates;
ticket=open;
if{try++;ifPrint)," retry "+try+" times");Sleep;}
if{ecnsltpLong;}
}
}
if{
RefreshRates;
ticket=open;
if{ecnsltpLong;}
}
if{
RefreshRates;
ticket=open;
if{ecnsltpLong;}
}
}else{
if{
while{
RefreshRates;
ticket=open;
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
if{RefreshRates;ticket=open;}
if{RefreshRates;ticket=open;}
}
}else if{ // Sell
if{
if{
while{
RefreshRates;
ticket=open;
if{try++;ifPrint)," retry "+try+" times");Sleep;}
if{ecnsltpShort;}
}
}
if{
RefreshRates;
ticket=open;
if{ecnsltpShort;}
}
if{
RefreshRates;
ticket=open;
if{ecnsltpShort;}
}
}else{
if{
while{
RefreshRates;
ticket=open;
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
if{RefreshRates;ticket=open;}
if{RefreshRates;ticket=open;}
}
}
return ;
}
int open{
int ticket=0;
double sl,tp;
if{
if{sl=price-stoploss*point;}else{sl=0;}
if{tp=price+takeprofit*point;}else{tp=0;}
}
if{
if{sl=price+stoploss*point;}else{sl=0;}
if{tp=price-takeprofit*point;}else{tp=0;}
}
ticket=OrderSend),Slippage*mt,sl,tp,"Prower by myeatrade.com",magic,expire,clr);
return;
}
datetime getOrderOpenTime{
OrderSelect;
return );
}
void ecnsltpLong{
OrderSelect;
bool succeed;int try;
succeed=false;try=0;
if==0&&StopLoss>0){
while{
RefreshRates;
succeed = OrderModify,OrderOpenPrice,NormalizeDouble-StopLoss*point,MarketInfo,MODE_DIGITS)),OrderTakeProfit,0,Blue);
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
RefreshRates;
succeed=false;try=0;
OrderSelect;
if==0&&TakeProfit>0){
while{
RefreshRates;
succeed = OrderModify,OrderOpenPrice,OrderStopLoss,NormalizeDouble+TakeProfit*point,MarketInfo,MODE_DIGITS)),0,Blue);
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
}
void ecnsltpShort{
OrderSelect;
bool succeed;int try;
succeed=false;try=0;
if==0&&StopLoss>0){
while{
RefreshRates;
succeed = OrderModify,OrderOpenPrice,NormalizeDouble+StopLoss*point,MarketInfo,MODE_DIGITS)),OrderTakeProfit,0,Blue);
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
RefreshRates;
succeed=false;try=0;
OrderSelect;
if==0&&TakeProfit>0){
while{
RefreshRates;
succeed = OrderModify,OrderOpenPrice,OrderStopLoss,NormalizeDouble-TakeProfit*point,MarketInfo,MODE_DIGITS)),0,Blue);
if{try++;ifPrint)," retry "+try+" times");Sleep;}
}
}
}
int countPositionByMagicSymbol{
int count=0;
if>0){
for;i>=0;i--){
OrderSelect;
if==magic&&OrderSymbol==symbol){
count++;
if>OrderOpenTime+hardCloseTime*60)){
if==OP_BUY)OrderClose,OrderLots,MarketInfo,0);
else if==OP_SELL)OrderClose,OrderLots,MarketInfo,0);
}
}
}
return;
}
}
void breakEven{
RefreshRates;
if>0){
for;i++){
OrderSelect;
if=NormalizeDouble)){
if-OrderOpenPrice)=NormalizeDouble)){
if-OrderStopLoss)0){
for;i++){
OrderSelect;
if=NormalizeDouble){
if{
if,digits)=NormalizeDouble){
if{
if,digits) > NormalizeDouble) || OrderStopLoss==0 ){
OrderModify,OrderOpenPrice,NormalizeDouble,OrderTakeProfit,0,Red);
}
}
if{
if-TrailStop*point) || OrderStopLoss==0 ){
OrderModify,OrderOpenPrice,NormalizeDouble,OrderTakeProfit,0,Blue);
}
}
}
}
}
}
}
}
string errordescription{
string error;
switch{
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 ";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 ";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 src";break;
case 4100:error="some src error";break;
case 4101:error="wrong src name";break;
case 4102:error="too many opened srcs";break;
case 4103:error="cannot open src";break;
case 4104:error="incompatible access to a src";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;
}
bool checkHasPosition{
if>0){
for;i>=0;i--){
OrderSelect;
if==magic&&OrderSymbol==symbol) return;
}
}
return ;
}
bool closeModelPosition{
double closeLots=0;
bool AllClose=true;
bool succeed;int try;
if>0){
for;i>=0;i--){
OrderSelect;
if==magic&&OrderSymbol==symbol){
if-OrderOpenTime<m*60){AllClose=false;continue;}
closeLots=OrderLots*percent;
if,MODE_MINLOT))closeLots=MarketInfo,MODE_MINLOT);
if==OP_BUY){
succeed=0;try=0;
while{
RefreshRates;
succeed = OrderClose,closeLots,MarketInfo,Slippage*mt);
if{try++;ifPrint,"! ",errordescription)," retry "+try+" times");Sleep;}
}
if{AllClose=false;}
}
if==OP_SELL){
succeed=0;try=0;
while{
RefreshRates;
succeed = OrderClose,closeLots,MarketInfo,Slippage*mt);
if{try++;ifPrint,"! ",errordescription)," retry "+try+" times");Sleep;}
}
if{AllClose=false;}
}
if==OP_BUYLIMIT||OrderType==OP_BUYSTOP||OrderType==OP_SELLLIMIT||OrderType==OP_SELLSTOP){
RefreshRates;
if)){AllClose=false;}
}
}
}
}
return ;
} |