//+------------------------------------------------------------------+ //| FastSlow MA RSI MACD EA.mq4 | //| Copyright © 2008, TradingSytemForex | //| http://www.tradingsystemforex.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, TradingSytemForex" #property link "http://www.tradingsystemforex.com" #define eaN "FastSlow MA RSI MACD EA" 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 Risk=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 EnableRealSL=false; int RealSL=5; //stop loss under 15 pīps bool EnableRealTP=false; int RealTP=10; //take profit under 10 pīps extern int StopLoss=0; //stop loss extern int TakeProfit=0; //take profit extern int TrailingStop=0; //trailing stop extern int TrailingProfit=0; //trailing stop int TrailingStep=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; extern int MaxTradePerBar=1; datetime Time0;int TradePerBar=0;int BarCount=-1; int Slip=3;static int TL=0;double Balance=0.0;int err=0;int TK; int init(){Time0=Time[0];return(0);} int deinit(){return(0);} //start function int start(){ //|---------trailing stop if(TrailingStop>0)MoveTrailingStop(); //|---------break even if(BreakEven>0)MoveBreakEven(); 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";if(TimeFilter){if(!(Hour()>=StartHour && Hour()<=EndHour)){TIFI="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&&Ask0&&RSI1>RSIUpLevel&&MAC2<0&&MAC1>0)SBUY="true";if((FMA1-SMA1)<0&&RSI10&&MAC1<0)SSEL="true"; //entry conditions if(MAFIB=="true"&&SBUY=="true"&&TIFI=="false"&&(TradePerBar<=MaxTradePerBar)){if(Reverse)SV=1;else BV=1;break;} if(MAFIS=="true"&&SSEL=="true"&&TIFI=="false"&&(TradePerBar<=MaxTradePerBar)){if(Reverse)BV=1;else SV=1;break;}} if(BarCount!=Bars){TradePerBar=0;BarCount=Bars;} //risk management bool MM=RiskManagement; if(MM){if(Risk<0.1||Risk>100){Comment("Invalid Risk Value.");return(0);} else{Lots=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*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()&&Balance<=AccountBalance())Lots=Lots;}Balance=AccountBalance(); //positions initialization int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0;cnt=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)||(TIFI=="true")||(EnableRealSL&&(OrderOpenPrice()-Bid)/Point>=RealSL)||(EnableRealTP&&(Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;} if((BV>0)||(TIFI=="true")||(EnableRealSL&&(Ask-OrderOpenPrice())/Point>=RealSL)||(EnableRealTP&&(OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;} for(cnt=0;cnt0)TradePerBar++;}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; if(Time0!=Time[0]){TK=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slip,SLI,TPI,eaN,Magic,0,Lime);OB=0;Comment("buy order opened","\n","magic number : ",Magic);Time0=Time[0];if(TK>0)TradePerBar++;}return(0);}} return(0);} //number of orders int CntO(int Type,int Magic){int _CntO;_CntO=0; for(int j=0;j_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);}} //|---------trailing stop void MoveTrailingStop() { int cnt,total=OrdersTotal(); for(cnt=0;cnt0&&Ask>NormalizeDouble(OrderOpenPrice()+TrailingProfit*Point,Digits)) { if((NormalizeDouble(OrderStopLoss(),Digits)0&&Bid(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red); return(0); } } } } } } //|---------break even void MoveBreakEven() { int cnt,total=OrdersTotal(); for(cnt=0;cnt0) { if(NormalizeDouble((Bid-OrderOpenPrice()),Digits)>BreakEven*Point) { if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits)<0) { OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+0*Point,Digits),OrderTakeProfit(),0,Blue); return(0); } } } } else { if(BreakEven>0) { if(NormalizeDouble((OrderOpenPrice()-Ask),Digits)>BreakEven*Point) { if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits)<0) { OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-0*Point,Digits),OrderTakeProfit(),0,Red); return(0); } } } } } } }