//+------------------------------------------------------------------+ //| RSI_SAR_MACD.mq4 | //| Copyright © 2011, Evgeny Evstegneev | //+---- | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011 Evgeny Evstegneev" #property link " OCENute" #define magic 020281 double Lots = 0.1;//начальный лот extern double MaximumRisk = 0.02; extern double DecreaseFactor = 3.0; extern double balans = 500.0; //шаг баланса //---- input parameters extern int period=25; extern int period_1=20; extern int tp=250; extern int sl=27; //extern double lot = 0.1; double LotsOptimized() { double minlot = MarketInfo(Symbol(), MODE_MINLOT); double maxlot = MarketInfo(Symbol(), MODE_MAXLOT); double lot = Lots; int orders = OrdersHistoryTotal(); int losses = 0; lot = NormalizeDouble(AccountFreeMargin() * MaximumRisk / balans, 2); if (DecreaseFactor > 0.0) { for (int i = orders - 1; 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.0) break; if (OrderProfit() < 0.0) losses++; } if (losses > 1) lot = NormalizeDouble(lot - lot * losses / DecreaseFactor, 2); } if(lot < minlot) lot = minlot; if(lot > maxlot) lot = maxlot; return (lot);} int start() { //---- double sar = iSAR(NULL,0,0.02,0.2,0); double rsi=iRSI(NULL ,0,period_1,PRICE_CLOSE,0); double macd=iMACD(NULL,0,9,19,19,PRICE_CLOSE,0,0); int ticket, cnt, total=OrdersTotal(); if(total<1) { if(sar50.0 && macd>0.0 ) { ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized() ,Ask,3,Bid-sl*Point,Ask+tp*Point,"RSI_SAR_MACD",magic,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else { Print("Error opening BUY order : ",GetLastError()); return(0); } } else if(sar>Close[0] && rsi<50.0 && macd<0.0) { ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized() ,Bid,3,Ask+sl*Point,Bid-tp*Point,"CCI_TRADER",magic,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else { Print("Error opening SELL order : ",GetLastError()); return(0); } } } for(cnt=0;cntClose[0] && rsi<50.0 && macd<0.0) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position return(0); // exit } } else // go to short position { // should it be closed? if(sar50.0 && macd>0.0) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position return(0); // exit } } } } //---- return(0); } //+------------------------------------------------------------------+