myeatrade

社区

求助

jia1919 jia1919 2013-03-14 10:29
一个简单的模型。 buystop 开盘价+N个点数 sellstop开盘价-N点数 我已经很努力了 ,还没做出来呢


myeatrade myeatrade 2013-03-14 17:25
不清楚你的交易条件是什么,需要设置好交易条件才能开仓
jia1919 jia1919 2013-03-14 17:59
你好管理员 ,条件是时间 设置一下ea 运行时间 比如17点59分开始运行 那么就以17点59分的一分钟k线开盘价为参照价位挂单 ,buystop 开盘价+N个点数 sellstop开盘价-N点数 可以做到吗?
myeatrade myeatrade 2013-03-14 23:15
不支持这样的设置,必须根据指标或价格的相互关系设置条件
ZY007589 ZY007589 2013-03-17 16:43
请教版主,执行条件中金叉死叉 和后面的特定值是什么关系?比如说想根据80附近的死叉进场做空怎么设置?
ZY007589 ZY007589 2013-03-17 16:49
ZY007589 写道:请教版主,执行条件中金叉死叉 和后面的特定值是什么关系?比如说想根据80附近的死叉进场做空怎么设置?
myeatrade myeatrade 2013-03-17 17:50
如果设置 特定值 值为80,就是80水平线

ZY007589 ZY007589 2013-03-19 17:53
老大 我写的EA 怎么用不了
代码: 全选

//+------------------------------------------------------------------+
// Copyright , myEAtrade
// http://www.myEAtrade.com
// System Name: EA2013
// Automatically generated by the myEAtrade.com
// at Tuesday 19th of March 2013 09:49:40 AM
//+------------------------------------------------------------------+
#property copyright "myEAtrade , www.myeatrade.com"
#property link "http://www.myeatrade.com/"




///////////////////////////Model1////////////////////////////
extern string Model1_tip="做多";
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 M1S1C2_Filter_tip="Filter Condition 2";
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="做空";
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 M2S1C2_Filter_tip="Filter Condition 2";
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="多单平仓";
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 M3S1C1_Filter_tip="Filter Condition 1";
extern string M3S1C2_Filter_tip="Filter Condition 2";
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="空头平仓";
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 M4S1C1_Filter_tip="Filter Condition 1";
extern string M4S1C2_Filter_tip="Filter Condition 2";
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 m1s1filter1_B_val[2];
double m1s1filter2_A_val[2];double m1s1filter2_B_val[2];
double m1s1exec1_A_val[3];double m1s1exec1_B_val[3];
double m2s1filter1_A_val[2];double m2s1filter1_B_val[2];
double m2s1filter2_A_val[2];double m2s1filter2_B_val[2];
double m2s1exec1_A_val[3];double m2s1exec1_B_val[3];
double m3s1filter1_A_val[2];double m3s1filter1_B_val[2];
double m3s1filter2_A_val[2];double m3s1filter2_B_val[2];
double m3s1exec1_A_val[3];double m3s1exec1_B_val[3];
double m4s1filter1_A_val[2];double m4s1filter1_B_val[2];
double m4s1filter2_A_val[2];double m4s1filter2_B_val[2];
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="AUDUSD"; double m1_point = MarketInfo(M1_Symbol,MODE_POINT); int m1_digits = MarketInfo(M1_Symbol,MODE_DIGITS); if(m1_digits==3 || m1_digits==5){
M1_Point=m1_point*10;
M1_Mt=10;
}else{
M1_Point=m1_point;
M1_Mt=1;
}
modelMagic[1]=10671;
M2_Symbol="AUDUSD"; double m2_point = MarketInfo(M2_Symbol,MODE_POINT); int m2_digits = MarketInfo(M2_Symbol,MODE_DIGITS); if(m2_digits==3 || m2_digits==5){
M2_Point=m2_point*10;
M2_Mt=10;
}else{
M2_Point=m2_point;
M2_Mt=1;
}
modelMagic[2]=10673;
M3_Symbol=Symbol(); double m3_point = MarketInfo(M3_Symbol,MODE_POINT); int m3_digits = MarketInfo(M3_Symbol,MODE_DIGITS); if(m3_digits==3 || m3_digits==5){
M3_Point=m3_point*10;
M3_Mt=10;
}else{
M3_Point=m3_point;
M3_Mt=1;
}
modelMagic[3]=10674;
M4_Symbol=Symbol(); double m4_point = MarketInfo(M4_Symbol,MODE_POINT); int m4_digits = MarketInfo(M4_Symbol,MODE_DIGITS); if(m4_digits==3 || m4_digits==5){
M4_Point=m4_point*10;
M4_Mt=10;
}else{
M4_Point=m4_point;
M4_Mt=1;
}
modelMagic[4]=10675;

}

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


void runModel1(){
int totalPosition = countPositionByMagicSymbol(10671,M1_Symbol,0);
if( 0>0 && (MarketInfo(M1_Symbol,MODE_ASK)-MarketInfo(M1_Symbol,MODE_BID))>0*M1_Point )return;
if((0!=0)&&(!isNewBar(M1_Symbol,5,1))) return;
bool canRunCheck=false;
int maxOrder=5;
if(!0)maxOrder=1;
if(totalPosition<maxOrder)canRunCheck=true;
if(maxOrder>1&&totalPosition>=1){
if(TimeCurrent()<(Model1_lastOpenOrderTime+5*60))canRunCheck=false;
if(!checkCanOpenMaxOrder(0,0,M1_Symbol,10671,M1_Point))canRunCheck=false;
}
if(0>0&&totalPosition>0)breakEven(10671,M1_Symbol,0,M1_Point);
if(1>0&&1<=2&&totalPosition>0)trailStop(10671,M1_Symbol,1,20,10,M1_Point);
if(canRunCheck){
if(checkM1S1()){
int orderType=OP_BUY;if(0>0)orderType=OP_SELL;
if(1>0){
double lots = getlots(0.05,0,2,0,M1_Symbol,M1_Mt,1,0.1,100);
int sl= 0;
int tp = 0;
int ticket = openposition(
M1_Symbol,
orderType,
lots,
sl,
tp,
10671,
1,
1,
0,
0,
20,
720,
M1_Point,
M1_Mt,
0);
Model1_lastOpenOrderTime = getOrderOpenTime(ticket);}
}
}
}
void runModel2(){
int totalPosition = countPositionByMagicSymbol(10673,M2_Symbol,0);
if( 0>0 && (MarketInfo(M2_Symbol,MODE_ASK)-MarketInfo(M2_Symbol,MODE_BID))>0*M2_Point )return;
if((0!=0)&&(!isNewBar(M2_Symbol,5,2))) return;
bool canRunCheck=false;
int maxOrder=5;
if(!0)maxOrder=1;
if(totalPosition<maxOrder)canRunCheck=true;
if(maxOrder>1&&totalPosition>=1){
if(TimeCurrent()<(Model2_lastOpenOrderTime+5*60))canRunCheck=false;
if(!checkCanOpenMaxOrder(0,0,M2_Symbol,10673,M2_Point))canRunCheck=false;
}
if(0>0&&totalPosition>0)breakEven(10673,M2_Symbol,0,M2_Point);
if(1>0&&1<=2&&totalPosition>0)trailStop(10673,M2_Symbol,1,20,10,M2_Point);
if(canRunCheck){
if(checkM2S1()){
int orderType=OP_SELL;if(0>0)orderType=OP_BUY;
if(1>0){
double lots = getlots(1,0,2,0,M2_Symbol,M2_Mt,1,0.1,100);
int sl= 0;
int tp = 0;
int ticket = openposition(
M2_Symbol,
orderType,
lots,
sl,
tp,
10673,
1,
1,
0,
0,
20,
720,
M2_Point,
M2_Mt,
0);
Model2_lastOpenOrderTime = getOrderOpenTime(ticket);}
}
}
}
void runModel3(){
if((0!=0)&&(!isNewBar(M3_Symbol,5,3))) return;
bool canRunCheck=false;
if(checkHasPosition(10671,M1_Symbol)){canRunCheck=true;}else{if(closeOneTime31)canClose31=true;}
bool spread31=true; if( 0>0 && (MarketInfo(M1_Symbol,MODE_ASK)-MarketInfo(M1_Symbol,MODE_BID))>0*M1_Point )spread31=false;
if(canRunCheck){
if(checkM3S1()){
bool allClose;
if(canClose31&&spread31){
allClose=closeModelPosition(10671,M1_Symbol,1,0,M1_Mt,0);
if(closeOneTime31&&allClose)canClose31=false;
if(!checkHasPosition(10671,M1_Symbol)){if(closeOneTime31)canClose31=true;}
}
}
}
}
void runModel4(){
if((0!=0)&&(!isNewBar(M4_Symbol,5,4))) return;
bool canRunCheck=false;
if(checkHasPosition(10673,M2_Symbol)){canRunCheck=true;}else{if(closeOneTime41)canClose41=true;}
bool spread41=true; if( 0>0 && (MarketInfo(M2_Symbol,MODE_ASK)-MarketInfo(M2_Symbol,MODE_BID))>0*M2_Point )spread41=false;
if(canRunCheck){
if(checkM4S1()){
bool allClose;
if(canClose41&&spread41){
allClose=closeModelPosition(10673,M2_Symbol,1,0,M2_Mt,0);
if(closeOneTime41&&allClose)canClose41=false;
if(!checkHasPosition(10673,M2_Symbol)){if(closeOneTime41)canClose41=true;}
}
}
}
}
bool checkM1S1(){
int i;
int limit = 100; bool reValue=false;
int preBar=0;
if(0==2)preBar=1;

bool filter12=true;
if(filter12){
int f12cBar111=1; if(preBar==1&&f12cBar111==0)f12cBar111=1;
for(i=preBar;i<=f12cBar111;i++){
m1s1filter1_A_val=iStochastic(Symbol(),15,14,3,3,0,0,0,i);
}
for(i=preBar;i<=f12cBar111;i++){
m1s1filter1_B_val=20;
}
for(i=preBar;i<=f12cBar111;i++){
if(!(m1s1filter1_A_val<(m1s1filter1_B_val-0))){filter12=false;break;}
}
}
if(filter12){
int f12cBar112=1; if(preBar==1&&f12cBar112==0)f12cBar112=1;
for(i=preBar;i<=f12cBar112;i++){
m1s1filter2_A_val=iStochastic(Symbol(),5,14,3,3,0,0,0,i);
}
for(i=preBar;i<=f12cBar112;i++){
m1s1filter2_B_val=20;
}
for(i=preBar;i<=f12cBar112;i++){
if(!(m1s1filter2_A_val<(m1s1filter2_B_val-0))){filter12=false;break;}
}
}
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if(exec12_b){
int e12cBar111=2; if(preBar==1&&e12cBar111==1)e12cBar111=2;
for(i=preBar;i<=e12cBar111;i++){
m1s1exec1_A_val=iStochastic(Symbol(),1,14,3,3,0,0,0,i);
}
for(i=preBar;i<=e12cBar111;i++){
m1s1exec1_B_val=0;
}
exec12_temp=true;
if(!(m1s1exec1_A_val[preBar]>(m1s1exec1_B_val[preBar]+0))){exec12_temp=false;}
if(exec12_temp){
for(i=preBar+1;i<e12cBar111;i++){
if(!(m1s1exec1_A_val>m1s1exec1_B_val)){exec12_temp=false;}
}
}
if(!exec12_temp)exec12_b=false;
if(exec12_temp){
if(m1s1exec1_A_val[e12cBar111]>m1s1exec1_B_val[e12cBar111]){exec12_temp=false;}
}
if(exec12_temp)exec12_a=true;
}
if(exec12_a&&exec12_b)exec12=true;
bool bshift=true;
if(filter12&&filter34&&exec12&&bshift)reValue=true;
return (reValue);
}
bool checkM2S1(){
int i;
int limit = 100; bool reValue=false;
int preBar=0;
if(0==2)preBar=1;

bool filter12=true;
if(filter12){
int f12cBar211=1; if(preBar==1&&f12cBar211==0)f12cBar211=1;
for(i=preBar;i<=f12cBar211;i++){
m2s1filter1_A_val=iStochastic(Symbol(),15,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar211;i++){
m2s1filter1_B_val=80;
}
for(i=preBar;i<=f12cBar211;i++){
if(!(m2s1filter1_A_val>(m2s1filter1_B_val+0))){filter12=false;break;}
}
}
if(filter12){
int f12cBar212=1; if(preBar==1&&f12cBar212==0)f12cBar212=1;
for(i=preBar;i<=f12cBar212;i++){
m2s1filter2_A_val=iStochastic(Symbol(),5,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar212;i++){
m2s1filter2_B_val=80;
}
for(i=preBar;i<=f12cBar212;i++){
if(!(m2s1filter2_A_val>(m2s1filter2_B_val+0))){filter12=false;break;}
}
}
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if(exec12_b){
int e12cBar211=2; if(preBar==1&&e12cBar211==1)e12cBar211=2;
for(i=preBar;i<=e12cBar211;i++){
m2s1exec1_A_val=iStochastic(Symbol(),0,14,3,3,0,1,0,i);
}
for(i=preBar;i<=e12cBar211;i++){
m2s1exec1_B_val=100;
}
exec12_temp=true;
if(!(m2s1exec1_A_val[preBar]<(m2s1exec1_B_val[preBar]-0))){exec12_temp=false;}
if(exec12_temp){
for(i=preBar+1;i<e12cBar211;i++){
if(!(m2s1exec1_A_val<m2s1exec1_B_val)){exec12_temp=false;}
}
}
if(!exec12_temp)exec12_b=false;
if(exec12_temp){
if(m2s1exec1_A_val[e12cBar211]<m2s1exec1_B_val[e12cBar211]){exec12_temp=false;}
}
if(exec12_temp)exec12_a=true;
}
if(exec12_a&&exec12_b)exec12=true;
bool bshift=true;
if(filter12&&filter34&&exec12&&bshift)reValue=true;
return (reValue);
}
bool checkM3S1(){
int i;
int limit = 100; bool reValue=false;
int preBar=0;
if(0==2)preBar=1;

bool filter12=true;
if(filter12){
int f12cBar311=1; if(preBar==1&&f12cBar311==0)f12cBar311=1;
for(i=preBar;i<=f12cBar311;i++){
m3s1filter1_A_val=iStochastic(Symbol(),15,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar311;i++){
m3s1filter1_B_val=80;
}
for(i=preBar;i<=f12cBar311;i++){
if(!(m3s1filter1_A_val>(m3s1filter1_B_val+0))){filter12=false;break;}
}
}
if(filter12){
int f12cBar312=1; if(preBar==1&&f12cBar312==0)f12cBar312=1;
for(i=preBar;i<=f12cBar312;i++){
m3s1filter2_A_val=iStochastic(Symbol(),5,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar312;i++){
m3s1filter2_B_val=80;
}
for(i=preBar;i<=f12cBar312;i++){
if(!(m3s1filter2_A_val>(m3s1filter2_B_val+0))){filter12=false;break;}
}
}
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if(exec12_b){
int e12cBar311=2; if(preBar==1&&e12cBar311==1)e12cBar311=2;
for(i=preBar;i<=e12cBar311;i++){
m3s1exec1_A_val=iStochastic(Symbol(),0,14,3,3,0,1,0,i);
}
for(i=preBar;i<=e12cBar311;i++){
m3s1exec1_B_val=100;
}
exec12_temp=true;
if(!(m3s1exec1_A_val[preBar]<(m3s1exec1_B_val[preBar]-0))){exec12_temp=false;}
if(exec12_temp){
for(i=preBar+1;i<e12cBar311;i++){
if(!(m3s1exec1_A_val<m3s1exec1_B_val)){exec12_temp=false;}
}
}
if(!exec12_temp)exec12_b=false;
if(exec12_temp){
if(m3s1exec1_A_val[e12cBar311]<m3s1exec1_B_val[e12cBar311]){exec12_temp=false;}
}
if(exec12_temp)exec12_a=true;
}
if(exec12_a&&exec12_b)exec12=true;
bool bshift=true;
if(filter12&&filter34&&exec12&&bshift)reValue=true;
return (reValue);
}
bool checkM4S1(){
int i;
int limit = 100; bool reValue=false;
int preBar=0;
if(0==2)preBar=1;

bool filter12=true;
if(filter12){
int f12cBar411=1; if(preBar==1&&f12cBar411==0)f12cBar411=1;
for(i=preBar;i<=f12cBar411;i++){
m4s1filter1_A_val=iStochastic(Symbol(),15,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar411;i++){
m4s1filter1_B_val=20;
}
for(i=preBar;i<=f12cBar411;i++){
if(!(m4s1filter1_A_val<(m4s1filter1_B_val-0))){filter12=false;break;}
}
}
if(filter12){
int f12cBar412=1; if(preBar==1&&f12cBar412==0)f12cBar412=1;
for(i=preBar;i<=f12cBar412;i++){
m4s1filter2_A_val=iStochastic(Symbol(),5,14,3,3,0,1,0,i);
}
for(i=preBar;i<=f12cBar412;i++){
m4s1filter2_B_val=20;
}
for(i=preBar;i<=f12cBar412;i++){
if(!(m4s1filter2_A_val<(m4s1filter2_B_val-0))){filter12=false;break;}
}
}
bool filter34=true;
bool exec12_temp=true, exec12_a=false, exec12_b=true,exec12=false;
if(exec12_b){
int e12cBar411=2; if(preBar==1&&e12cBar411==1)e12cBar411=2;
for(i=preBar;i<=e12cBar411;i++){
m4s1exec1_A_val=iStochastic(Symbol(),1,14,3,3,0,1,0,i);
}
for(i=preBar;i<=e12cBar411;i++){
m4s1exec1_B_val=0;
}
exec12_temp=true;
if(!(m4s1exec1_A_val[preBar]>(m4s1exec1_B_val[preBar]+0))){exec12_temp=false;}
if(exec12_temp){
for(i=preBar+1;i<e12cBar411;i++){
if(!(m4s1exec1_A_val>m4s1exec1_B_val)){exec12_temp=false;}
}
}
if(!exec12_temp)exec12_b=false;
if(exec12_temp){
if(m4s1exec1_A_val[e12cBar411]>m4s1exec1_B_val[e12cBar411]){exec12_temp=false;}
}
if(exec12_temp)exec12_a=true;
}
if(exec12_a&&exec12_b)exec12=true;
bool bshift=true;
if(filter12&&filter34&&exec12&&bshift)reValue=true;
return (reValue);
}


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);
}
}

bool checkCanOpenMaxOrder(int mode,int pip,string symbol,int magic,double point){
bool result=true;int i,count=0;double profitPip;
switch(mode){
case 0: result=true;break;
case 1:
for(i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==symbol&&OrderMagicNumber()==magic){
count++;
if(!(OrderProfit()>0)){result=false;break;}
if(count==1){
if(OrderType()==OP_BUY)profitPip = (MarketInfo(OrderSymbol(),MODE_BID) - OrderOpenPrice())/point;
if(OrderType()==OP_SELL)profitPip = (OrderOpenPrice() - MarketInfo(OrderSymbol(),MODE_ASK))/point;
if(!(profitPip>pip)){result=false;break;}
}
}
}
break;
case 2:
for(i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==symbol&&OrderMagicNumber()==magic){
count++;
if(!(OrderProfit()<0)){result=false;break;}
if(count==1){
if(OrderType()==OP_BUY)profitPip = (MarketInfo(OrderSymbol(),MODE_BID) - OrderOpenPrice())/point;
if(OrderType()==OP_SELL)profitPip = (OrderOpenPrice() - MarketInfo(OrderSymbol(),MODE_ASK))/point;
if(!((-1*profitPip)>pip)){result=false;break;}
}
}
}
break;
}
return (result);
}


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*Risk,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);
double ask=MarketInfo(symbol,MODE_ASK);double bid=MarketInfo(symbol,MODE_BID);
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");Sleep(sleepTime);}
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");Sleep(sleepTime);}
}
}
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");Sleep(sleepTime);}
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");Sleep(sleepTime);}
}
}
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,MarketInfo(symbol,MODE_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);
bool succeed;int try;
succeed=false;try=0;
if(OrderStopLoss()==0&&StopLoss>0){
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-StopLoss*point,MarketInfo(OrderSymbol(),MODE_DIGITS)),OrderTakeProfit(),0,Blue);
if(!succeed){try++;if(printLog)Print("Error modify long order stoploss!",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
}
RefreshRates();
succeed=false;try=0;
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderTakeProfit()==0&&TakeProfit>0){
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()+TakeProfit*point,MarketInfo(OrderSymbol(),MODE_DIGITS)),0,Blue);
if(!succeed){try++;if(printLog)Print("Error modify long order takeprofit!",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
}
}

void ecnsltpShort(int ticket,double StopLoss,double TakeProfit,double point){
OrderSelect(ticket,SELECT_BY_TICKET);
bool succeed;int try;
succeed=false;try=0;
if(OrderStopLoss()==0&&StopLoss>0){
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+StopLoss*point,MarketInfo(OrderSymbol(),MODE_DIGITS)),OrderTakeProfit(),0,Blue);
if(!succeed){try++;if(printLog)Print("Error modify short order stoploss!",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
}
RefreshRates();
succeed=false;try=0;
OrderSelect(ticket,SELECT_BY_TICKET);
if(OrderTakeProfit()==0&&TakeProfit>0){
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(OrderOpenPrice()-TakeProfit*point,MarketInfo(OrderSymbol(),MODE_DIGITS)),0,Blue);
if(!succeed){try++;if(printLog)Print("Error modify short order takeprofit!",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
}
}


int countPositionByMagicSymbol(int magic,string symbol,int hardCloseTime){
int count=0;
if(OrdersTotal()>0){
for(int i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic&&OrderSymbol()==symbol){
count++;
if(hardCloseTime>0&&(TimeCurrent()>OrderOpenTime()+hardCloseTime*60)){
if(OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),MarketInfo(symbol,MODE_BID),0);
else if(OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),MarketInfo(symbol,MODE_ASK),0);
}
}
}
return(count);
}
}



void breakEven(int magic,string symbol,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 && OrderSymbol()==symbol){
if(OrderType()==OP_BUY){
if( NormalizeDouble((MarketInfo(symbol,MODE_BID)-OrderOpenPrice()),MarketInfo(symbol,MODE_DIGITS))>=NormalizeDouble(BreakEven*point,MarketInfo(symbol,MODE_DIGITS))){
if( (OrderStopLoss()-OrderOpenPrice())<0)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue);
}
}else{
if( NormalizeDouble((OrderOpenPrice()-MarketInfo(symbol,MODE_ASK)),MarketInfo(symbol,MODE_DIGITS))>=NormalizeDouble(BreakEven*point,MarketInfo(symbol,MODE_DIGITS))){
if(((OrderOpenPrice()-OrderStopLoss())<0)||(OrderStopLoss()==0))
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Red);
}
}
}
}
}
}


void trailStop(int magic,string symbol,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 && OrderSymbol()==symbol){
int digits=MarketInfo(symbol,MODE_DIGITS);
double ask = MarketInfo(symbol,MODE_ASK);double bid = MarketInfo(symbol,MODE_BID);
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);
}



bool checkHasPosition(int magic,string symbol){
if(OrdersTotal()>0){
for(int i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic&&OrderSymbol()==symbol) return(true);
}
}
return (false);
}

bool closeModelPosition(int magic,string symbol,double percent,int m,int mt,int Slippage){
double closeLots=0;
bool AllClose=true;
bool succeed;int try;
if(OrdersTotal()>0){
for(int i=OrdersTotal();i>=0;i--){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==magic&&OrderSymbol()==symbol){
if(TimeCurrent()-OrderOpenTime()<m*60){AllClose=false;continue;}
closeLots=OrderLots()*percent;
if(closeLots<MarketInfo(OrderSymbol(),MODE_MINLOT))closeLots=MarketInfo(OrderSymbol(),MODE_MINLOT);
if(OrderType()==OP_BUY){
succeed=0;try=0;
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderClose(OrderTicket(),closeLots,MarketInfo(symbol,MODE_BID),Slippage*mt);
if(!succeed){try++;if(printLog)Print("Error close order in CloseModel ",""+OrderTicket(),"! ",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
if(!succeed){AllClose=false;}
}
if(OrderType()==OP_SELL){
succeed=0;try=0;
while(!succeed && try<maxtry){
RefreshRates();
succeed = OrderClose(OrderTicket(),closeLots,MarketInfo(symbol,MODE_ASK),Slippage*mt);
if(!succeed){try++;if(printLog)Print("Error close order in CloseModel ",""+OrderTicket(),"! ",errordescription(GetLastError())," retry "+try+" times");Sleep(sleepTime);}
}
if(!succeed){AllClose=false;}
}
if(OrderType()==OP_BUYLIMIT||OrderType()==OP_BUYSTOP||OrderType()==OP_SELLLIMIT||OrderType()==OP_SELLSTOP){
RefreshRates();
if(!OrderDelete(OrderTicket())){AllClose=false;}
}
}
}
}
return (AllClose);
}


ZY007589 ZY007589 2013-03-19 17:57
老大 帮忙看一下是不是哪里写错了
myeatrade myeatrade 2013-03-20 21:52
你上面提供的代码已经完全被损坏,已经无法使用,请重新生成代码试试
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