//+------------------------------------------------------------------+ //| mrmon-exp.mq4 | //| Nick Bilak, beluck[AT]gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Nick Bilak" #property link "http://www.mql4.info/" #include extern int expertId = 1; extern int TakeProfit = 17; extern int StopLoss = 60; extern int TrailingStop = 10; extern double Lots = 0.1; //fixed lot size extern double MinLot = 0.1; //minimum lot size extern double MaximumRisk = 5; //% risk. lot size will be calculated so that stoploss was equal to risk% of balance extern bool FixedLot = true; //trigger to use MM extern int TimeStart=0700; extern int TimeStop=2400; extern int EmaPeriod=10; extern int SmaPeriod=40; extern int slippage=2; //slippage for market order processing extern int shift=1; //shift to current bar, extern int OrderTriesNumber=2; //to repeate sending orders when got some error extern string EAName="mrmon"; bool buysig,sellsig,closebuy,closesell; int lastsig,tries,x,y,co,lastdir=999,lastc; double xp,xpc; void start() { //if (TimeCurrent()>1168560000) { Alert("1040-exp version expired"); return; } //---- check for history and trading if(Bars<100 || IsTradeAllowed()==false) return; CheckForSignals(); CheckForOpen(); TrailStop(); } double LotsRisk(int StopLoss) { //MM lot size calculation double lot=Lots; //---- select lot size if (!FixedLot) lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk*0.001/StopLoss,1); else lot=Lots; //---- return lot size if(lotsma1) { if (lastdir==999) { lastdir=1; return; } closesell=true; buysig=true; } if (ema1=TimeStart && ct0) CheckForClose(); co=CalculateCurrentOrders(Symbol()); if(sellsig && lastdir>0) { if (co==0) { res = OpenAtMarket(OP_SELL,LotsRisk(StopLoss)); } if (res>0) { lastdir=-1; lastsig=Time[0]; } return; } //---- buy conditions if(buysig && lastdir<0) { if (co==0) { res = OpenAtMarket(OP_BUY,LotsRisk(StopLoss)); } if (res>0) { lastdir=1; lastsig=Time[0]; } return; } } //+------------------------------------------------------------------+ //| Check for close order conditions | //+------------------------------------------------------------------+ void CheckForClose() { bool bres; int tr; for(int i=0;i 2 ) { for (int i = 0; i < OrdersTotal(); i++) { if ( OrderSelect (i, SELECT_BY_POS) == false ) continue; if ( OrderSymbol() != Symbol() || OrderMagicNumber() != expertId ) continue; if ( OrderType() == OP_BUY ) { if ( Bid < OrderOpenPrice()+TrailingStop*Point ) return; StopLoss = Bid-TrailingStop*Point; if ( StopLoss > OrderStopLoss() ) { bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, White); if (!bres) Print("Error Modifying BUY order : ",ErrorDescription(GetLastError())); } } if ( OrderType() == OP_SELL ) { if ( Ask > OrderOpenPrice()-TrailingStop*Point ) return; StopLoss = Ask+TrailingStop*Point; if ( StopLoss < OrderStopLoss() ) { bres=OrderModify (OrderTicket(), OrderOpenPrice(), StopLoss, OrderTakeProfit(), 0, Gold); if (!bres) Print("Error Modifying SELL order : ",ErrorDescription(GetLastError())); } } } } return; }