//+------------------------------------------------------------------+ //| Egy_Cross_2_Ma_V1.mq4 | //| Copyright 2018, EgyTrading | //| EgyTrading@ymail.com | //+------------------------------------------------------------------+ //|Modified by Kira-h --+ //|hassan.mb@hotmail.com| //|www.fxprg.com | //+---------------------+ #property copyright "Copyright 2018, EgyTrading" #property link "EgyTrading@ymail.com" #property version "3.20" #property strict input string s0 = "Filter Ma"; input int period_0 = 200; input int shift_0 = 0; input ENUM_MA_METHOD MODE_0 = 0; input ENUM_APPLIED_PRICE apply_0 = 0; input string s1 = "Fast Ma"; input int period_1 = 5; input int shift_1 = 0; input ENUM_MA_METHOD MODE_1 = 0; input ENUM_APPLIED_PRICE apply_1 = 0; input string s2 = "Slow Ma"; input int period_2 = 75; input int shift_2 = 0; input ENUM_MA_METHOD MODE_2 = 0; input ENUM_APPLIED_PRICE apply_2 = 0; input int MaxBuy = 0, MaxSell = 0; input double Lot = 0.01; input int TakeProfit = 50; input int StopLoss = 50; input int MinStep = 10; input int TrailingStop = 0; input int TrailingStep = 0; input bool Close_At_Next = true; input int MAGIC = 2018; int dig; double pt; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Comment("Modified by Kira-h"); if(Digits==5||Digits==4){pt=0.0001;dig=4;}else{pt=0.01;dig=2;} //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- Comment(""); } int Ma() { int ma=0; double ma0=iMA(Symbol(),0,period_0,shift_0,MODE_0,apply_0,1), ma1=iMA(Symbol(),0,period_1,shift_1,MODE_1,apply_1,1), ma11=iMA(Symbol(),0,period_1,shift_1,MODE_1,apply_1,2), ma2=iMA(Symbol(),0,period_2,shift_2,MODE_2,apply_2,1), ma22=iMA(Symbol(),0,period_2,shift_2,MODE_2,apply_2,2); if(ma22>ma11&&ma2ma0)ma=1; else if(ma22ma1&&ma1ma1)ma=-2; return(ma); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- int b=0,s=0; double BuyMax = 0, BuyMin = 0, SellMax = 0, SellMin = 0, ma=iMA(Symbol(),0,period_1,shift_1,MODE_1,apply_1,1), m0=iMA(Symbol(),0,period_0,shift_0,MODE_0,apply_0,1); int up=0,dn=0; double ma0=0,ma1=0,ma11=0,ma2=0,ma22=0; for(int i=1;ima11&&ma2ma0)up++; if(ma22ma1&&ma1=0; i--) if(OrderSelect(i,SELECT_BY_POS)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==MAGIC) { if(OrderType()==OP_BUY&&OrderComment()==upcom) { b++; if(OrderOpenPrice()>BuyMax || BuyMax==0) { BuyMax=OrderOpenPrice(); } if(OrderOpenPrice()SellMax || SellMax==0) { SellMax=OrderOpenPrice(); } } } Comment("Segnal = "+(string)Ma(),"\nUP = "+(string)up,"\nDN = "+(string)dn, "\nTotalBuyProfit = "+(string)profit(OP_BUY), "\nTotalSellProfit = "+(string)profit(OP_SELL), "\nTotalProfitt = "+(string)profit(-1) ); double Dist = NormalizeDouble(MinStep*pt,Digits()); double TP=0,SL=0; if((Ma()==1&&((b==0)||(b>0&&(Ask-BuyMax)>=Dist)))||(Ma()==2&&b>0&&(Ask-BuyMax)>=Dist)) { if((MaxBuy>0&&b0&&(SellMin-Bid)>=Dist)))||(Ma()==-2&&s>0&&(SellMin-Bid)>=Dist)) { if((MaxSell>0&&s0)CloseOrder(); else if(profit(-1)<0&&profit(OP_SELL)>0)CloseOrder(OP_SELL); else if(profit(-1)<0&&profit(OP_SELL)<0)Closeprofit(OP_SELL); } if(Ma()==-1) { if(profit()>0)CloseOrder(); else if(profit(-1)<0&&profit(OP_BUY)>0)CloseOrder(OP_BUY); else if(profit(-1)<0&&profit(OP_BUY)<0)Closeprofit(OP_BUY); } if(TrailingStop>0)MoveTrailingStop(); } //+------------------------------------------------------------------+ double profit(int type=-1){ double c=0; for(int i=0;i=0 ; cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MAGIC&&(OrderType()==type||type==-1)) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0,Violet)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),0,Violet)) return(false); }break; } } } } return (true); } //+------------------------------------------------------------------+ bool Closeprofit(int type) { int total = OrdersTotal(); for (int cnt = total-1 ; cnt >=0 ; cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MAGIC&&OrderType()==type&&OrderProfit()>0) { switch(OrderType()) { case OP_BUY : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),0,Violet)) return(false); }break; case OP_SELL : { if(!OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),0,Violet)) return(false); }break; } } } } return (true); } //+------------------------------------------------------------------+ void MoveTrailingStop() { int cnt,total=OrdersTotal(); for(cnt=0;cnt0&&NormalizeDouble(Ask-TrailingStep*pt,dig)>NormalizeDouble(OrderOpenPrice()+TrailingStop*pt,dig)) { if((NormalizeDouble(OrderStopLoss(),dig)0&&NormalizeDouble(Bid+TrailingStep*pt,dig)(NormalizeDouble(Ask+TrailingStop*pt,dig)))||(OrderStopLoss()==0)) { int mod=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+TrailingStop*pt,dig),OrderTakeProfit(),0,Red); return; } } } } } }