//+------------------------------------------------------------------+ //| both directions pips | //| email: evgeny.kalashnikov@gmail.com| //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, evgeny.kalashnikov@gmail.com, posted by dazix" #property link "http://www.forex-tsd.com/suggestions-trading-systems/3843-mt4-30-pips-system.html" extern int timeframe = 5; extern double stopLoss = 1000; extern double lTakeProfit = 30; extern double sTakeProfit = 30; extern color clOpenBuy = Blue; extern color clCloseBuy = Aqua; extern color clOpenSell = Red; extern color clCloseSell = Violet; extern color clModiBuy = Blue; extern color clModiSell = Red; extern string Name_Expert = "30 pips"; extern int Slippage = 2; extern bool UseSound = false; extern string NameFileSound = "shotgun.wav"; extern double MaximumRisk =0.02; extern double DecreaseFactor =3; extern int Lot.Margin =1000; extern int SlippageDif=5; extern double InitialLot=0.05; int init(){return(0);} int deinit(){return(0);} int start(){ int order_type; //if(AccountFreeMargin()<(1000*LotsOptimized())){ //Print("We have no money. Free Margin = ", AccountFreeMargin()); //return(0); } if(ExistPositions()==0) { OpenBuy(); OpenSell(); return(0); } if (ExistPositions()%2==1) { order_type=ModeOfOrder(); if (order_type==OP_BUY) { if (EqualPrice()) {OpenBuy();} else { OpenBuy(); OpenSell(); return (0); } } if (order_type==OP_SELL) { if (EqualPrice()) {OpenSell();} else { OpenBuy(); OpenSell(); return (0); } } } return (0); }//end start // - - - - - - FUNCTIONS - - - - - - - bool EqualPrice() { for(int i=0;i=((Ask+Bid)/2)-SlippageDif*Point ) return (true); } return (false); } int ExistPositions() { int NumofPositions; NumofPositions=0; for(int i=0;iSellOrders) {return (OP_SELL);} else {return (OP_BUY);} } void OpenBuy() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = Ask-Point*stopLoss; ldTake = NormalizeDouble(GetTakeProfitBuy(),Digits); lsComm = GetCommentForOrder(); OrderSend(Symbol(),OP_BUY,ldLot,NormalizeDouble(Ask,Digits),Slippage,0,ldTake,lsComm,0,0,clOpenBuy); } void OpenSell() { double ldLot, ldStop, ldTake; string lsComm; ldLot = GetSizeLot(); ldStop = Bid+Point*stopLoss; ldTake = NormalizeDouble(GetTakeProfitSell(),Digits); lsComm = GetCommentForOrder(); OrderSend(Symbol(),OP_SELL,ldLot,NormalizeDouble(Bid,Digits),Slippage,0,ldTake,lsComm,0,0,clOpenSell); } string GetCommentForOrder() { return(Name_Expert); } double GetSizeLot() { return(LotsOptimized()); } double GetTakeProfitBuy() { return(Ask+lTakeProfit*Point); } double GetTakeProfitSell() { return(Bid-sTakeProfit*Point); } double LotsOptimized() { double lot; // int orders=HistoryTotal(); // int losses=0; // lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/Lot.Margin,2); // if(DecreaseFactor>0) { // for(int i=orders ;i>=0;i--) { // if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; } // if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue; // if(OrderProfit()>0) break; // if(OrderProfit()<0) losses++; } // if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,2); } // if(lot<0.1) lot=0.1; lot=InitialLot*; return(lot); }