客服热线:18391752892
顺水的鱼MT4外汇EA趋势对冲马丁延迟套利指标智能交易系统
顺水的鱼MT4外汇EA
商家二维码
手机查看商家
18391752892
首页>金融学院>行业分析>新手快速学会怎样编写外汇EA <上一个 下一个>
交易员学习资料推荐

  • 注册资本|未填写
  • 企业类型|
  • 主营产品|
  • 公司地区|全国
  • 公司荣誉|
金融学院分类
  • 暂无分类
本页信息为顺水的鱼MT4外汇EA为您提供的“新手快速学会怎样编写外汇EA”金融学院,如您想了解更多关于“新手快速学会怎样编写外汇EA”关注顺水外汇网。
品牌新手快速学会怎样编写外汇EA 有效期至长期有效 最后更新2019-01-10 18:45
浏览次数927

新手快速学会怎样编写外汇EA

#property copyright n.com target=_blank >外汇联盟 www.FXunion.com QQ群144033

#property link      

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+

 

#property copyright n.com target=_blank >外汇联盟 www.FXunion.com QQ群144033

#property link      

写与不写都无所谓
我们也不用理他
* //+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//以后可能有用到
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//以后可能有用到
//----
return(0);
}
这两个很少用到。高高手才会用
速成班的话,这个可以不用理他。
放在一边先,以后才学怎样用它。
* //+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//主程式
//----
return(0);
}
//+------------------------------------------------------------------+
这个就是EA开始操作的重要部分
以上的EA的编写形式我们改成如下:

#property copyright n.com target=_blank >外汇联盟 www.FXunion.com QQ群144033

#property link      

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
/以后可能有用到
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
/以后可能有用到
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//主程式
//----
return(0);
}
//+------------------------------------------------------------------+
* 什么是 .mq4 ?
EA制作好了就save成.mq4的文件
这文件是可以修改的
* 什么是 .ex4 ?
EA制作好了
按 编写 就会自动save成.ex4的文件
这文件是不可以被修改的
这文件是加密的
可以出售的文件。
 

 

 
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//主程式
//----
return(0);
}
//+------------------------------------------------------------------+
* 我们要知道EA是由上面往下读的
所以我们在编写方面要有逻辑思考
以下是编写的形式
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
MoneyManagement();
macd();
ma();
zhangchang();
buyme();
sellme();
xianshi();
//----
return(0);
}
//+------------------------------------------------------------------+
void MoneyManagement() {
}
//+------------------------------------------------------------------+
void macd() {
}
//+------------------------------------------------------------------+
void ma() {
}
//+------------------------------------------------------------------+
void zhangchang() {
}
//+------------------------------------------------------------------+
void buyme() {
}
//+------------------------------------------------------------------+
void sellme() {
}
//+------------------------------------------------------------------+
void buyme() {
}
//+------------------------------------------------------------------+
void xianshi() {
}
//+------------------------------------------------------------------+
/////end
* // 这两划代表右边的不要读
也可以说是注解
注意:EA不会读中文符号。比如这个
这个就可以

#property copyright n.com target=_blank >外汇联盟 www.FXunion.com QQ群144033

#property link      

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//以后可能有用到
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//以后可能有用到
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
//主程式
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
buyme();//买上
sellme();//买下
xianshi();//显示管理
//----
return(0);
}
//+------------------------------------------------------------------+
void MoneyManagement() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void macd() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void ma() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void zhangchang() {
///子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void sellme() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
void xianshi() {
//子程式
//这边要写一些东西
}
//+------------------------------------------------------------------+
/////end
* 如果你在上面加这个xianshi2();
下面就加这个
//////////////////////////
void xianshi2() {
//这边要写一些东西
}
////////////////////////////
可以任意无限的加。。。
 

 

第三课::加入指标
* //////////////////////////////
void ma()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma1now2 = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,1);
ma2now = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
ma2now2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,1);
ma1bnow = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_OPEN,0);
ma2bnow = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_OPEN,0);
}
////////////////////////
ma1now是代表的字
你可以写成什么都可以
PRICE_CLOSE是ma最新的参数
PRICE_OPEN是ma开始的参数
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
这个整句是死的。
你只要copy press就可以用了
ma1是ma的参数号码或bar
如果这样写法,他人不能更改参数
double ma1=1,ma2=2;
double ma1now,ma1now2,ma2now,ma2now2,ma1bnow,ma2bnow;
这样写法,他人可以更改参数
extern double ma1=1,ma2=2;
这个是要放在#property上面那边的
* 其它指标的写法
macd1now=iMACD(NULL,0,macd1,macd1*2,1,PRICE_CLOSE, MODE_MAIN,0);
zigzag1now=iCustom(NULL,0, ZigZag ,2,deviation,bac kstep,0,0);
Highest1now=High[iHighest(NULL,0,MODE_HIGH,Highest1,0)];
Lowest1now=Low[iLowest(NULL,0,MODE_LOW,Lowest1,0)];
iTrend1now=iCustom(NULL,0, iTrend ,2,0,0,iTrend1,0 ,iTrend1,0,0,1);
wpr1now = iWPR(Symbol(),0,wpr1,0);
指标写法是不用记住的
网上可以找到很多指标的写法
* 有了指标
我们可以更改我们的EA了
更改如下:
注意看看
刚刚的指标加在什么地方
什么位置

#property copyright n.com target=_blank >外汇联盟 www.FXunion.com QQ群144033

#property link      

extern double ma1=1,ma2=2;
double ma1now,ma1now2,ma2now,ma2now2,ma1bnow,ma2bnow;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
buyme();//买上
sellme();//买下
xianshi();//显示管理
//----
return(0);
}
//+------------------------------------------------------------------
+void MoneyManagement() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void macd() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void ma()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma1now2 = iMA(NULL,0,ma10,0,MODE_EMA,PRICE_CLOSE,1);
ma2now = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
ma2now2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,1);
ma1bnow = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_OPEN,0);
ma2bnow = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_OPEN,0);
}
//+------------------------------------------------------------------+
void zhangchang() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void sellme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void xianshi() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
/////end
* 注意这个{},不要糊涂的删除了也不知道
会出错的
注意这个可以写成这样
效果一样
double ma1=1;
double ma2=2;
double ma1now;
double ma1now2;
double ma2now;
double ma2now2;
double ma1bnow;
double ma2bnow;
* extern double ma1=1;
extern double ma2=2;
这样写可以显示在EA开始的修改处
 

 

第四课-资金管理
* 这个将放在#property上面那边
////////////////////////
extern string _资金管理_ = 任选一个
extern bool zijiguanli1 = true;//false true、、
extern bool zijiguanli2= false;//false true、、
extern bool zijiguanli3= false;//false true、、
///////////////////////////////////
true=要
false =不要用
我提供了三个资金管理作为参考
你可以自己增加自己喜欢的资金管理方案
* /////////////////////////////////////
void MoneyManagement() {
lotstart=(AccountBalance()*lotab/10000);
lots=lotstart;
if(cheng==0){cheng=1;}
CurrentBasket=AccountEquity()-AccountBalance();
/////////////////////////////////////////////////////////////////
if(zijiguanli1){ LotMM = lots;}
/////////////////////////////////////////////////////////////////
if(zijiguanli2){
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+ lotstart,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(zijiguanli3){
if(s+b==0){aa=1;}
if(s+b==1){aa=3;}
if(s+b==2){aa=7;}
if(s+b==3){aa=11;}
if(s+b==4){aa=20;}
if(s+b==5){aa=31;}
if(s+b==6){aa=42;}
if(s+b==7){aa=54;}
if(s+b==8){aa=66;}
if(s+b==9){aa=76;}
if(s+b =10){aa=66;}
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lotstart*aa,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(LotMM lots){LotMM=0.01;}
if(LotMM LotsMax){LotMM=LotsMax;}
}//end zijiguanli
//////////////////////////////////////////
注意:这个资金管理加了很多新的词句
所以我们要加上去#property上面那边
不然会出错
* 新的词句:
extern double cheng=1;
double aa=0;
int s=0,b=0;
intdouble CurrentBasket=0;
double LotMM=0;
double lotstart=0;
double LotsMax=100;
extern double lotab=0.1;
double lots=0;
* 注意:
double 是有小数点的
int 是没有小数点的
* 注意:
if(){}
很容易用,比如:
if(LotMM lots){LotMM=0.01;}
意思就是:
如果LotMM小过lots,LotMM就等于0.01。
if(LotMM LotsMax){LotMM=LotsMax;}
意思就是:
如果LotMM大过LotsMax,LotMM就等于LotsMax。
不会的话,不要紧
copy press就可以用了
把void MoneyManagement() { }
copy press到我们EA模板去
结果如下://

#property copyright 外汇联盟 www.FXunion.com QQ群144033

#property link      

extern double ma1=1,ma2=2;
double ma1now,ma1now2,ma2now,ma2now2,ma1bnow,ma2bnow;
////////////////////////
extern string _资金管理_ = 任选一个
extern bool zijiguanli1= true;//false true、、
extern bool zijiguanli2= false;//false true、、
extern bool zijiguanli3= false;//false true、、
///////////////////////////////////
extern double cheng=1;
double aa=0;
int s=0,b=0;
int double CurrentBasket=0;
double LotMM=0;
double lotstart=0;
double LotsMax=100;
extern double lotab=0.1;
double lots=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
buyme();//买上
sellme();//买下
xianshi();//显示管理
//----
return(0);
}
//+------------------------------------------------------------------+
void MoneyManagement() {
lotstart=(AccountBalance()*lotab/10000);
lots=lotstart;
if(cheng==0){cheng=1;}
CurrentBasket=AccountEquity()-AccountBalance();
/////////////////////////////////////////////////////////////////
if(zijiguanli1){ LotMM = lots;}
/////////////////////////////////////////////////////////////////
if(zijiguanli2){
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+ lotstart,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(zijiguanli3){
if(s+b==0){aa=1;}
if(s+b==1){aa=3;}
if(s+b==2){aa=7;}
if(s+b==3){aa=11;}
if(s+b==4){aa=20;}
if(s+b==5){aa=31;}
if(s+b==6){aa=42;}
if(s+b==7){aa=54;}
if(s+b==8){aa=66;}
if(s+b==9){aa=76;}
if(s+b =10){aa=66;}
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lotstart*aa,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(LotMM lots){LotMM=lots;}
if(LotMM LotsMax){LotMM=LotsMax;}
}//end zijiguanli
//+------------------------------------------------------------------+
void macd() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void ma()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma1now2 = iMA(NULL,0,ma10,0,MODE_EMA,PRICE_CLOSE,1);
ma2now = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
ma2now2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,1);
ma1bnow = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_OPEN,0);
ma2bnow = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_OPEN,0);
}
//+------------------------------------------------------------------+
void zhangchang() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void sellme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void buyme() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void xianshi() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
/////end
* 资金管理有三个方案:
资金管理1=平注
资金管理2=1,2,3,4,5...
可以乘,如果你把cheng改成2或3或0.2
资金管理3是固定式,1,3,7,11.。。
 

 

第五课:策略:战场
* 这里是整个EA最重要的地方
这里策略变化无穷
高深莫测就是这里作怪
* 在这里你要想:。。。
你的EA要怎样下注
什么时候买上?
什么时候买下?
怎样买上?
怎样买下?
有买上又买下?
什么时候离场?
条件满足是很重要的
* 在这里我给个简单的策略
-ma1n.com target=_blank >黄金交叉ma2,EA买上
-ma1死亡交叉ma2,EA买下
-有赚25点就出场
-如果亏的时候亏50点就出场
* 是这样编写的:
ma1now ma2now
这样一句是不够条件的
ma1now ma2now
ma1now2 ma2now2
这个就是n.com target=_blank >黄金交叉的编写法
* 反过来
ma1now ma2now
ma1now2 ma2now2
这个就是死亡交叉的编写法
* 但是条件还是不够的
再加
ma1now ma2now
ma1now2 ma2now2
s+b==0
s+b==0 意思就是 买上+买下等于没有
没有下注,如果遇到条件符合就可以下注的意思
的意思就是 再加 什么什么的条件
那么整句是这样编写
if(什么什么){就什么什么}
就是用这个
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){buyme();}
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){sellme();}
* 现在我们就把这两句copy press到战场去
注意:
现在又多了两个新的东西
buyme()和sellme()
你就copy press buyme()和sellme()的编写法就可以了。
* 结果如下:

#property copyright 外汇联盟 www.FXunion.com QQ群144033

#property link      

extern double ma1=1,ma2=2;
double ma1now,ma1now2,ma2now,ma2now2,ma1bnow,ma2bnow;
////////////////////////
extern string _资金管理_ = 任选一个
extern bool zijiguanli1= true;//false true、、
extern bool zijiguanli2= false;//false true、、
extern bool zijiguanli3= false;//false true、、
///////////////////////////////////
extern double cheng=1;
double aa=0;
int s=0,b=0;
intdouble CurrentBasket=0;
double LotMM=0;
double lotstart=0;
double LotsMax=100;
extern double lotab=0.1;
double lots=0;
double TP=0,TPP=0,SL=0,SLL=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
buyme();//买上
sellme();//买下
xianshi();//显示管理
//----
return(0);
}
//+------------------------------------------------------------------+
void MoneyManagement() {
lotstart=(AccountBalance()*lotab/10000);
lots=lotstart;
if(cheng==0){cheng=1;}
CurrentBasket=AccountEquity()-AccountBalance();
/////////////////////////////////////////////////////////////////
if(zijiguanli1){ LotMM = lots;}
/////////////////////////////////////////////////////////////////
if(zijiguanli2){
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+ lotstart,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(zijiguanli3){
if(s+b==0){aa=1;}
if(s+b==1){aa=3;}
if(s+b==2){aa=7;}
if(s+b==3){aa=11;}
if(s+b==4){aa=20;}
if(s+b==5){aa=31;}
if(s+b==6){aa=42;}
if(s+b==7){aa=54;}
if(s+b==8){aa=66;}
if(s+b==9){aa=76;}
if(s+b =10){aa=66;}
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lotstart*aa,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(LotMM lots){LotMM=lots;}
if(LotMM LotsMax){LotMM=LotsMax;}
}//end zijiguanli
//+------------------------------------------------------------------+
void macd() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void ma()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma1now2 = iMA(NULL,0,ma10,0,MODE_EMA,PRICE_CLOSE,1);
ma2now = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
ma2now2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,1);
ma1bnow = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_OPEN,0);
ma2bnow = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_OPEN,0);
}
//+------------------------------------------------------------------+
void zhangchang() {
//这边要写一些东西
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){buyme();}
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){sellme();}
}
//+------------------------------------------------------------------+
void buyme(){
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()+ ,0,0,Violet);
return(0); }
//+------------------------------------------------------------------+
void sellme(){
if (TP==0) { TPP=0; } if(TP 0) { TPP=Bid-(TP*Point); }
if (SL==0) { SLL=0; } if(SL 0) { SLL=Bid+(SL*Point); }
ticket=OrderSend(Symbol(),OP_SELL,LotMM,Bid,2,SLL, TPP, M +Period()+ ,0,0,GreenYellow);
return(0); }
//+------------------------------------------------------------------+
void buyme() {
//这边要写一些东西
}
//+------------------------------------------------------------------
+void xianshi() {
//这边要写一些东西
}
//+------------------------------------------------------------------+/////end
* 在buyme()和sellme()
我们又发现新的词句
TP,TPP,SL,SLL
我们必须在#property上面加上他们
不然会出错
我已经加上去了上面的结果了
你注意到了吗?
* ok,这个EA可以用了
现在你copy press 去你的metaEDITOR
save as 一个新的名字就可以了
* 试一试,用一用
告诉你,它肯定是 垃圾 EA
因为是亏钱的EA
 

 

 
//int 是表示要 整数 比如:1,2,3,4...
//double 表示要有小数点,比如:1.1,7.987.56.897.....
* 之后你在按一下 编写
他告诉你
第二:ma1now2 = iMA(NULL,0,ma10,0,MODE_EMA,PRICE_CLOSE,1);
ma10,意思就是没有ma10这个新词句
其实我们没有用到ma10
是编写错误
不是ma10,是多了个0
应该是ma1
删掉 0 就可以了
* 之后你在按一下 编写
他告诉你
第三:OrderSend(Symbol(),OP_BUY,LotMM,Ask,slip,SLL,TP P, M +Period()+ ,0,0,Violet);
问题是slip
应该是新的词句
slip 是什么?
听他们讲是滑点?管他
因为我们不可以删掉slip
所以在上方加上新的词句吧!
比如:
int slip=6;
就可以了
* 再来。。。
ticket=OrderSend(Symbol(),OP_SELL,LotMM,Bid,2,SLL, TPP, M +Period()+ ,0,0,GreenYellow);
ticket?
我们没有用到ticket
所以可以删掉 ticket= 就可以了
* 再来。。。他告诉你多了这个
void buyme() {
//这边要写一些东西
}
因为已经有了的,哈哈和。。。
是糊涂多了一个
删掉 整句多余的buyme() 就可以了
* 再来。。。
0错误 0警告
哈哈和。。。
成功了
恭喜你已经学会编写EA了
编写EA就是解决问题

 

第七课-填写盈亏
上一回我们讲到
-有赚25点就出场
-如果亏的时候亏50点就出场
这个还没有加上去
编写方法就是
Take Profit=25
Stop Loss=50
我把他们简写成
TP=25;
SL=50;
你想到了什么吗?
对,这字眼很熟吧!
记得吗?
double TP=0,TPP=0,SL=0,SLL=0;
我们改成
double TP=25,TPP=0,SL=50,SLL=0;
你发现吗?
不过下注方面还是有问题!
其实是这EA没有判断
什么是B
什么是S
B是buy
S是sell
速成班不必学会怎样写
你只要copy prss下面的子程式
放进去就可以了
我把它称为检查
//////////////////////////////////////////
void jiancha()
{
b=0;s=0;
for (int cnt=0; cnt =OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() )
{
mode=OrderType();LastOrderType=OrderType();
if (OrderType() == OP_SELL){ s++; LastPricesell=OrderOpenPrice();}
if (OrderType() == OP_BUY ){ b++; LastPricebuy=OrderOpenPrice();}
LastPrice=OrderOpenPrice();
if (OrderType()==OP_SELL) {OpenSells++;}
if (OrderType()==OP_SELLSTOP) {OpenSellStops++;}
if (OrderType()==OP_BUY) {OpenBuys++;}
if (OrderType()==OP_BUYSTOP) {OpenBuyStops++;}
}
}
}//end jiancha
//////////////////////////////////////////////////
要记得:在start那边也加入
jiancha();
这样就可以了。
当我们按 编写
会出错
因为有了新的词句
我们没有加在#property上面那边
新的词句:
mode
LastOrderType
LastPricesell
LastPricebuy
LastPrice
OpenSells
OpenSellStops
OpenBuys
OpenBuyStops
我们更正如下:
double mode=0;
double LastOrderType;
double LastPricesell;
double LastPricebuy;
double LastPrice;
double OpenSells;
double OpenSellStops;
double OpenBuys;
double OpenBuyStops;
按 编写 。。。
0错误 0警告
ok了
按 终端 试一试效果怎样
还是不行
还是buy sell buy sell buy sell
你知道什么事情发生了吗?
跟你讲一个逻辑
什么是主程式
就是主要的程式
什么是子程式
就是不是主要的程式
了解了这些
现在一个问题,这些子程式
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
buyme();//买上
sellme();//买下
xianshi();//显示管理
那些是不需要一直用的就不可以在主程式这里
对啦!
buyme();//买上
sellme();//买下
是有时用到,有时没有用
所以我们删掉它
现在这个EA可以正常的操作了
其编写程式如下:
注意颜色部分的位置

#property copyright 外汇联盟 www.FXunion.com QQ群144033

#property link      

extern double ma1=1,ma2=2;
double ma1now,ma1now2,ma2now,ma2now2,ma1bnow,ma2bnow;
////////////////////////
extern string _资金管理_ = 任选一个
extern bool zijiguanli1= true;//false true、、
extern bool zijiguanli2= false;//false true、、
extern bool zijiguanli3= false;//false true、、
///////////////////////////////////
extern double cheng=1;
double aa=0;
int s=0,b=0;
double CurrentBasket=0;
double LotMM=0;
double lotstart=0;
double LotsMax=100;
extern double lotab=0.1;
double lots=0;
double TP=25,TPP=0,SL=50,SLL=0;
int slip=6;
///////////////////////////////////////
double mode=0;
double LastOrderType;
double LastPricesell;
double LastPricebuy;
double LastPrice;
double OpenSells;
double OpenSellStops;
double OpenBuys;
double OpenBuyStops;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
jiancha();//检查判断
MoneyManagement();//资金管理
macd();//指标管理
ma();//指标管理
zhangchang();//战场管理
xianshi();//显示管理
//----
return(0);
}
//+------------------------------------------------------------------+
void jiancha()
{
b=0;s=0;
for (int cnt=0; cnt =OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() )
{
mode=OrderType();LastOrderType=OrderType();
if (OrderType() == OP_SELL){ s++; LastPricesell=OrderOpenPrice();}
if (OrderType() == OP_BUY ){ b++; LastPricebuy=OrderOpenPrice();}
LastPrice=OrderOpenPrice();
if (OrderType()==OP_SELL) {OpenSells++;}
if (OrderType()==OP_SELLSTOP) {OpenSellStops++;}
if (OrderType()==OP_BUY) {OpenBuys++;}
if (OrderType()==OP_BUYSTOP) {OpenBuyStops++;}
}
}
}//end jiancha
//+------------------------------------------------------------------+
void MoneyManagement() {
lotstart=(AccountBalance()*lotab/10000);
lots=lotstart;
if(cheng==0){cheng=1;}
CurrentBasket=AccountEquity()-AccountBalance();
/////////////////////////////////////////////////////////////////
if(zijiguanli1){ LotMM = lots;}
/////////////////////////////////////////////////////////////////
if(zijiguanli2){
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lots*(OrdersTotal()*cheng)+ lotstart,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(zijiguanli3){
if(s+b==0){aa=1;}
if(s+b==1){aa=3;}
if(s+b==2){aa=7;}
if(s+b==3){aa=11;}
if(s+b==4){aa=20;}
if(s+b==5){aa=31;}
if(s+b==6){aa=42;}
if(s+b==7){aa=54;}
if(s+b==8){aa=66;}
if(s+b==9){aa=76;}
if(s+b =10){aa=66;}
if(CurrentBasket 0 ) {LotMM=NormalizeDouble(lotstart*aa,2); }
if(CurrentBasket==0 ) {LotMM=NormalizeDouble(LotMM*0,2); }
}
/////////////////////////////////////////////////////////////////
if(LotMM lots){LotMM=lots;}
if(LotMM LotsMax){LotMM=LotsMax;}
}//end zijiguanli
//+------------------------------------------------------------------+
void macd() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
void ma()
{
ma1now = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,0);
ma1now2 = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_CLOSE,1);
ma2now = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,0);
ma2now2 = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_CLOSE,1);
ma1bnow = iMA(NULL,0,ma1,0,MODE_EMA,PRICE_OPEN,0);
ma2bnow = iMA(NULL,0,ma2,0,MODE_EMA,PRICE_OPEN,0);
}
//+------------------------------------------------------------------+
void zhangchang() {
//这边要写一些东西
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){buyme();}
if(ma1now ma2now
ma1now2 ma2now2
s+b==0
){sellme();}
}
//+------------------------------------------------------------------+
void buyme(){
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()+ ,0,0,Violet);
return(0); }
//+------------------------------------------------------------------+
void sellme(){
if (TP==0) { TPP=0; } if(TP 0) { TPP=Bid-(TP*Point); }
if (SL==0) { SLL=0; } if(SL 0) { SLL=Bid+(SL*Point); }
OrderSend(Symbol(),OP_SELL,LotMM,Bid,2,SLL,TPP, M +Period()+ ,0,0,GreenYellow);
return(0); }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void xianshi() {
//这边要写一些东西
}
//+------------------------------------------------------------------+
///////////////////////////////end
恭喜!恭喜,这EA可以正常操作了!

 

 
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+Poi nt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
if (OrderType()==OP_BUY)
{
if(TrailingStop 0)
{
if(Bid-OrderOpenPrice() Point*TrailingStop)
{
if(OrderStopLoss() Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
}
}
}//end TrailingStop
////////////////////////////////////
这TrailingStop是可以一直用的
所以我们要加在start那边加
TrailingStop();
发现新的词句
cnt
TrailingStop
我们更正如下:
int cnt;
double TrailingStop=0;
按 编写
0错误 0警告
厉害,哈哈和。。。
加入成功
把double TrailingStop=0;
0改成10,就可以操作了
改成这样也可以
extern double TrailingStop=10;
自己试一试看看效果如何?
怎样?容易吗?

 

 

第九课-显示画面
显示的子程式如下
//////////////////////////////////////////////
void xianshi()
{
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, 15);
ObjectSet(name_8, OBJPROP_YDISTANCE, 15);
ObjectDelete(name_8);
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSetText(name_8, +text+ , 15, 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);

联系方式
顺水的鱼MT4外汇EA趋势对冲马丁延迟套利指标智能交易系统
0相关评论

为您推荐

免责声明:
当前页为新手快速学会怎样编写外汇EA价格信息展示,该页所展示的新手快速学会怎样编写外汇EA批发价格、新手快速学会怎样编写外汇EA报价等相关信息均有企业自行提供,新手快速学会怎样编写外汇EA价格真实性、准确性、合法性由店铺所有企业完全负责的。顺水的鱼MT4外汇EA趋势对冲马丁延迟套利指标智能交易系统对此不承担任何保证责任。
友情提醒:
建议您通过拨打新手快速学会怎样编写外汇EA厂家联系方式确认最终价格,并索要新手快速学会怎样编写外汇EA样品确认产品质量。如新手快速学会怎样编写外汇EA报价过低,可能为虚假信息,请确认新手快速学会怎样编写外汇EA报价真实性,谨防上当受骗。