李易鸿原创
MT4 EA 智能交易制作速成班
版权所有 请勿翻版
MT4 EA 制作速成班-战场策略篇2
版权所有 请勿转翻
作者:李沂鸿(马来西亚)
网站:mt4ea.com
疫苗:jh7x51@hotmail.com
第二章:十面埋伏源码
以下是不完整的源码
少了三个子程式
关闭买上();关闭卖下();关闭全部();
我还在等速成班学员交功课
哈哈和。。。
或者有哪一位高手要帮他们补上去?
//+------------------------------------------------------------------+
//| MT4_EA_制作速成班模板.mq4 |
//| Copyright 2008, MT4_EA_制作速成班模板. |
//| http://www.MT4_EA_制作速成班模板.net |
//+------------------------------------------------------------------+
#property copyright \"2008年5月31日\"
#property link \"http://www.MT4_EA_制作速成班模板.net\"
//#define MagicNumber 20080400; //int MagicNumber = 200601182020; // allows multiple experts to trade on same account
int MagicNumber = 20080531; // MAGICMA allows multiple experts to trade on same account
////////////////////////
extern string _资金管理_ =\"任选一个\";
extern bool zijiguanli1= true;//false true、、
extern bool zijiguanli2= false;//false true、、
extern bool zijiguanli3= false;//false true、、
///////////////////////////////////
string EAname =\"五线谱\";
extern double cheng=1;
double aa=0;
int s=0,b=0,i=0,panduan=0;
double CurrentBasket=0;
double LotMM=0;
double lotstart=0;
double LotsMax=100;
double LotsMin=0.1;
extern double lotab=0.1;
extern double Stoploss=0,no60=60;
double lots=0;
double TP=0,TPP=0,SL=0,SLL=0,SLauto;
int slip=6;
//////////////////////////////////
double mode=0;
double LastOrderType;
double LastPricesell;
double LastPricebuy;
double LastPrice;
double OpenSells;
double OpenSellStops;
double OpenBuys;
double OpenBuyStops;
///////////////////////////////
int cnt;
extern int TrailingStop=0;
///////////////////////////////
string text=\"\";
////////////////////////
extern double macd12_1=12, macd12_2=26, macd12_3=9;
double macd12now;
extern double ma1=1,ma2=2,ma3=3,ma4=4,ma5=5;
extern double ma6=6,ma7=7,ma8=8,ma9=9,ma10=10;
double ma1now,ma2now,ma3now,ma4now,ma5now;
double ma6now,ma7now,ma8now,ma9now,ma10now;
extern double adx14=14;
double adx14now,kxian,no2=2;
////////////////////////////
double BaoZhenJing;
//////////////////////////////
int 判断=0,buy1=1,buy2=1,buy3=1,buy4=1,sell1=1,sell2=1,sell3=1,sell4=1;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//保护EA
if(IsDemo()){
text=\"==DEMO版,关闭MT4,关闭网络连接,从开MT4就可以测试了== \";
string name_18 = \"xianshi2\";
ObjectDelete(name_18);
ObjectCreate(name_18, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_18, \"\"+text+\"\", 15, \"Arial\", Red);
ObjectSet(name_18, OBJPROP_CORNER, 1);
ObjectSet(name_18, OBJPROP_XDISTANCE, 15);
ObjectSet(name_18, OBJPROP_YDISTANCE, 5);
return(0);}
//----
//保护EA
if(!IsTesting()){
text=\"==测试版,不是正式使用版!== \";
name_18 = \"xianshi2\";
ObjectDelete(name_18);
ObjectCreate(name_18, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_18, \"\"+text+\"\", 15, \"Arial\", Red);
ObjectSet(name_18, OBJPROP_CORNER, 1);
ObjectSet(name_18, OBJPROP_XDISTANCE, 15);
ObjectSet(name_18, OBJPROP_YDISTANCE, 5);
return(0);}
//----
//保护EA
if(!IsConnected()){
text=\"==测试版,关闭MT4,关闭网络连接,从开MT4就可以测试了== \";
name_18 = \"xianshi2\";
ObjectDelete(name_18);
ObjectCreate(name_18, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_18, \"\"+text+\"\", 15, \"Arial\", Red);
ObjectSet(name_18, OBJPROP_CORNER, 1);
ObjectSet(name_18, OBJPROP_XDISTANCE, 15);
ObjectSet(name_18, OBJPROP_YDISTANCE, 5);
return(0);}
///----
//主程式
检查判断();
资金管理();
macd指标管理();
ma指标管理();
adx指标管理();
战场管理();
显示管理();
移动止赢();
//----
return(0);
}
//+------------------------------------------------------------------+
void 检查判断()
{
b=0;s=0;
for (int cnt=0; cnt= 1 ) { return(0); }
//---------------------------------------------------------------------
//这个(if(s+b==111)。。。)下面的在编写策略后要用//去掉。
if(s+b==1111){卖下();买上();关闭买上();关闭卖下();关闭全部();}
//这边编写策略
//第一步 买上()策略
if(b==0
&& (ma1now-ma2now)/Point > no2
&& (ma3now-ma4now)/Point > no2
&& (ma5now-ma6now)/Point > no2
&& (ma7now-ma8now)/Point > no2
&& (ma9now-ma10now)/Point > no2
){判断=1;买上();}
//第2步 卖下() 策略
if(s==0
&& (ma2now-ma1now)/Point > no2
&& (ma4now-ma3now)/Point > no2
&& (ma6now-ma5now)/Point > no2
&& (ma8now-ma7now)/Point > no2
&& (ma10now-ma9now)/Point > no2
){判断=2;卖下();}
//第3步关闭买上()策略
if(判断==2
&& b==1
){关闭买上();}
//第4步关闭卖下()策略
if(判断==1
&& s==1
){关闭卖下();}
}//end 战场管理
//+------------------------------------------------------------------+
void 买上(){
if (TP==0) { TPP=0; } if(TP>0) { TPP=Ask+TP*Point; }
if (SL==0) { SLL=0; } if(SL>0) { SLL=Ask-SL*Point; }
OrderSend(Symbol(),OP_BUY,LotMM,Ask,slip,SLL,TPP,\"M\"+Period()+\"\"+EAname+\"\",MagicNumber,0,Violet);
//Alert(\"Order MagicNumber==\",MagicNumber,\"\");
return(0); }
//+------------------------------------------------------------------+
void 卖下(){
if (TP==0) { TPP=0; } if(TP>0) { TPP=Bid-(TP*Point); }
if (SL==0) { SLL=0; } if(SL>0) { SLL=Bid+(SL*Point); }
//Alert(\"Order MagicNumber==\",MagicNumber,\" sell1=\",sell1,\" sell2=\",sell2,\" sell3=\",sell3,\" sell4=\",sell4,\"\");
OrderSend(Symbol(),OP_SELL,LotMM,Bid,slip,SLL,TPP,\"M\"+Period()+\"\"+EAname+\"\",MagicNumber,0,GreenYellow);
return(0); }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void 显示管理()
{
string name_8 = \"xianshi1\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, \"伺服器时间::\"+TimeToStr(CurTime( ))+\"\", 13, \"Arial\", White);
ObjectSet(name_8, OBJPROP_CORNER, 0);
ObjectSet(name_8, OBJPROP_XDISTANCE, 200);
ObjectSet(name_8, OBJPROP_YDISTANCE, 5);
text=\"MT4 EA 制作策略编写_十面埋伏-编写:柒侠伍义 \";
name_8 = \"xianshi2\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, \"\"+text+\"\", 14, \"Arial\", Yellow);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 5);
name_8 = \"Lableyeddrice1\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, \"M\"+Period()+\" 货币 \"+Symbol()+\"\", 10, \"Arial\", Silver);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 130);
ObjectSet(name_8, OBJPROP_YDISTANCE, 32);
//////这个显示上方
name_8 = \"LableCurPrice2\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr(Ask, Digits)+\"::买上\", 15, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 30);
//////这个显示下方
name_8 = \"Lab345rPrice3\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr(Bid, Digits)+\"::卖下\", 15, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 50);
name_8 = \"Acc87lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( AccountBalance(), 2)+\"::账面资金\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 70);
name_8 = \"LableC5rice6\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( AccountEquity(), 2)+\"::净值资金\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 90);
name_8 = \"Labl456rice6\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( AccountMargin(), 2)+\"::保证资金\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 110);
name_8 = \"Labl4hcjce6\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( AccountFreeMargin(), 2)+\"::可用资金\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 130);
name_8 = \"Accvf7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( AccountProfit(), 2)+\"::账面盈亏\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 150);
aa=s+b;
name_8 = \"Accvfee7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( aa, 0)+\"::s+b\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 170);
aa=adx14now;
name_8 = \"Acccvfee7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+b+\"::buy\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 190);
name_8 = \"Acccwvfee7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+s+\"::sell\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 210);
aa=判断;
name_8 = \"Accc我vfee7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( aa, 0)+\"::判断\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 230);
if(ma10now>ma9now){aa=(ma10now-ma9now)/Point;}
if(ma9now>ma10now){aa=(ma9now-ma10now)/Point;}
name_8 = \"Accc我vfeffe7lance\";
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8,\"\"+DoubleToStr( aa, 2)+\"::ma10ma9\", 13, \"Arial\", Lime);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 250);
//我们可以无限的加
}//end 显示管理()
//+------------------------------------------------------------------+
///////////////////////
void 移动止赢()
{
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() ) //&& OrderMagicNumber()==MAGICMA)
{
if (OrderType()==OP_SELL)
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
if (OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>oint*TrailingStop)
{
if(OrderStopLoss() |
|