有您的持续关注
我们会做得更好

FastSlow MA RSI MACD EA (TS ok) EA



FastSlow MA RSI MACD EA (TS ok) EA结合均线、RSI、MACD信号开发。系统带有盈利、止损、移动止损功能。如何搭配合理的盈亏比及交易周期乃是该款EA盈利周期长短的关键所在。

本网收集整理智能交易EA仅为MQL4编程爱好者提供语法及相关编程技巧的学习研究之用,智能交易存在极高的风险测试请用模拟盘,请勿用于实盘。FastSlow MA RSI MACD EA (TS ok) EA源码:

//+------------------------------------------------------------------+
//|                              FastSlow MA RSI MACD EA (TS ok).mq4 |
//|                                     Copyright 2014, QQ:125808047 |
//+------------------------------------------------------------------+
#property copyright "Copyright @2014, 125808047"
#property link      "www.125808047.com"

extern string separator1="---------------- Entry Settings";
extern int FastEMA=5;
extern int SlowEMA=15;
extern int MACDSMA=1;
extern int FastMAPeriod=10;
extern int FastMAMethod=1;
extern int SlowMAPeriod=20;
extern int SlowMAMethod=1;
extern int RSIPeriod=21;
extern int RSIUpLevel=50;
extern int RSIDnLevel=50;
extern string separator2="---------------- Lot Management";
extern double Lots=0.1;
extern bool RiskManagement=false; //money management
extern double RiskPercent=10; //risk in percentage
extern bool Martingale=false; //martingale
extern double Multiplier=1.5; //multiplier
extern double MinProfit=0; //minimum profit to apply the martingale
extern string separator3="---------------- TP SL TS BE";
bool EnableHiddenSL=false;
int HiddenSL=50; 
bool EnableHiddenTP=false;
int HiddenTP=100; 
extern int StopLoss=200; //stop loss
extern int TakeProfit=500; //take profit
extern int TrailingStop=0; //trailing stop
int TSStep=1; //trailing step
extern int BreakEven=0; //breakeven
extern string separator4="---------------- Extras";
extern bool Reverse=false;
extern bool AddPositions=false; //positions cumulated
extern int MaxOrders=100; //maximum number of orders
extern bool MAFilter=false; //moving average filter
extern int MAPeriod=20;
extern int MAMethod=1;
extern int MAPrice=0;
extern bool TimeFilter=false; //time filter
extern int StartHour=8;
extern int EndHour=21;
extern int Magic=0;
bool cg = false;

int Slip=3;static int TL=0;double Balance=0.0;int err=0;int TK;


void deinit() {
  Comment("www.125808047.com");
}

//start function
int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;if(CntO(OP_BUY,Magic)>0)TL=1;if(CntO(OP_SELL,Magic)>0)TL=-1;
for(int i=1;i<=limit;i++){

//time filter
string TIFI="false";string CLTIFI="false";
if(TimeFilter==false||(TimeFilter&&((EndHour>StartHour&&(Hour()>=StartHour&&Hour()<=EndHour))||(StartHour>EndHour&&!(Hour()>=EndHour&&Hour()<=StartHour))))){TIFI="true";}
if(TimeFilter&&((EndHour>StartHour&&!(Hour()>=StartHour&&Hour()<=EndHour))||(StartHour>EndHour&&(Hour()>=EndHour&&Hour()<=StartHour)))){CLTIFI="true";}

//ma filter
double MAF=iMA(Symbol(),0,MAPeriod,0,MAMethod,MAPrice,i);string MAFIB="false";string MAFIS="false";
if((MAFilter==false)||(MAFilter&&Bid>MAF))MAFIB="true";if((MAFilter==false)||(MAFilter&&Ask<MAF))MAFIS="true";

//main signal
double FMA2=iMA(NULL,0,FastMAPeriod,0,FastMAMethod,PRICE_CLOSE,i);
double FMA1=iMA(NULL,0,FastMAPeriod,0,FastMAMethod,PRICE_CLOSE,i);
double SMA2=iMA(NULL,0,SlowMAPeriod,0,SlowMAMethod,PRICE_CLOSE,i);
double SMA1=iMA(NULL,0,SlowMAPeriod,0,SlowMAMethod,PRICE_CLOSE,i);
double RSI2=iRSI(0,0,RSIPeriod,0,i+1);
double RSI1=iRSI(0,0,RSIPeriod,0,i);
double MAC2=iMACD(NULL,0,FastEMA,SlowEMA,MACDSMA,PRICE_CLOSE,MODE_SIGNAL,i+1);
double MAC1=iMACD(NULL,0,FastEMA,SlowEMA,MACDSMA,PRICE_CLOSE,MODE_SIGNAL,i);
string SBUY="false";string SSEL="false";
if((FMA1-SMA1)>0&&RSI1>RSIUpLevel&&MAC2<0&&MAC1>0)SBUY="true";if((FMA1-SMA1)<0&&RSI1<RSIDnLevel&&MAC2>0&&MAC1<0)SSEL="true";

//entry conditions
if(MAFIB=="true"&&SBUY=="true"&&TIFI=="true"){if(Reverse)SV=1;else BV=1;break;}
if(MAFIS=="true"&&SSEL=="true"&&TIFI=="true"){if(Reverse)BV=1;else SV=1;break;}}

//risk management
bool MM=RiskManagement;
if(MM){if(RiskPercent<0.1||RiskPercent>100){Comment("Invalid Risk Value.");return(0);}
else{Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*RiskPercent*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*
MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);}}
if(MM==false){Lots=Lots;}

//martingale
if(Balance!=0.0&&Martingale==True){if(Balance>AccountBalance())Lots=Multiplier*Lots;else if((Balance+MinProfit)<AccountBalance())Lots=Lots/Multiplier;
else if((Balance+MinProfit)>=AccountBalance()&&Balance<=AccountBalance())Lots=Lots;}Balance=AccountBalance();if(Lots<0.01)Lots=0.01;if(Lots>100)Lots=100;

//positions initialization
int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0;cnt<OrdersTotal();cnt++){cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if((OrderType()==OP_SELL||OrderType()==OP_BUY)&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0))OP=OP+1;}
if(OP>=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0;int SL=StopLoss;int TP=TakeProfit;

//entry conditions verification
if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;}

//conditions to close position
if((SV>0)||(CLTIFI=="true")||(EnableHiddenSL&&(OrderOpenPrice()-Bid)/Point>=HiddenSL)||(EnableHiddenTP&&(Ask-OrderOpenPrice())/Point>=HiddenTP)){CB=1;}
if((BV>0)||(CLTIFI=="true")||(EnableHiddenSL&&(Ask-OrderOpenPrice())/Point>=HiddenSL)||(EnableHiddenTP&&(OrderOpenPrice()-Bid)/Point>=HiddenTP)){CS=1;}
for(cnt=0;cnt<OrdersTotal();cnt++){cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CB==1){cg = OrderClose(OrderTicket(),OrderLots(),Bid,Slip,Red);return(0);}}
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){if(CS==1){cg = OrderClose(OrderTicket(),OrderLots(),Ask,Slip,Red);return(0);}}}
double SLI=0,TPI=0;TK=0;

//open position
if((AddP()&&AddPositions&&OP<=MaxOrders)||(OP==0&&!AddPositions)){
if(OS==1){if(TP==0)TPI=0;else TPI=Bid-TP*Point;if(SL==0)SLI=0;else SLI=Bid+SL*Point;
TK=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slip,SLI,TPI,Magic,0,Red);OS=0;return(0);}    
if(OB==1){if(TP==0)TPI=0;else TPI=Ask+TP*Point;if(SL==0)SLI=0;else SLI=Ask-SL*Point;
TK=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,SLI,TPI,Magic,0,Lime);OB=0;return(0);}}
for(j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)){if(OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)||Magic==0)){TrP();}}}return(0);}

//number of orders
int CntO(int Type,int Magic){int _CntO;_CntO=0;
for(int j=0;j<OrdersTotal();j++){cg = OrderSelect(j,SELECT_BY_POS,MODE_TRADES);if(OrderSymbol()==Symbol()){
if((OrderType()==Type&&(OrderMagicNumber()==Magic ||Magic==0)))_CntO++;}}return(_CntO);}

//trailing stop and breakeven
void TrP(){int BE=BreakEven;int TS=TrailingStop;double pb,pa,pp;pp=MarketInfo(OrderSymbol(),MODE_POINT);if(OrderType()==OP_BUY){pb=MarketInfo(OrderSymbol(),MODE_BID);if(BE>0){
if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}}if(TS>0){if((pb-OrderOpenPrice())>TS*pp){
if(OrderStopLoss()<pb-(TS+TSStep-1)*pp){ModSL(pb-TS*pp);return;}}}}if(OrderType()==OP_SELL){pa=MarketInfo(OrderSymbol(),MODE_ASK);
if(BE>0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}}if(TS>0){if(OrderOpenPrice()-pa>TS*pp){
if(OrderStopLoss()>pa+(TS+TSStep-1)*pp||OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}}

//stop loss modification function
void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);}

//add positions function
bool AddP(){int _num=0; int _ot=0;
for (int j=0;j<OrdersTotal();j++){if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol()&&OrderType()<3&&((OrderMagicNumber()==Magic)||Magic==0)){    
_num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();}}if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);

//not enough money message to continue the martingale
if(TK<0){if (GetLastError()==134){err=1;Print("NOT ENOGUGHT MONEY!!");}return (-1);}return (0);}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » FastSlow MA RSI MACD EA (TS ok) EA
上一篇:
下一篇:
分享到:更多 ()