// Steping Stop & Reverse.mq4 // Советник #property copyright "mandorr@gmail.com" #include extern int TakeProfit=70; extern int StepStop=10; extern double Lots=0.1; extern bool MoneyManagement=false; extern int MarginPercent=20; int level_sell_stop; int level_buy_stop; void init() { int minstop=MarketInfo(Symbol(),MODE_STOPLEVEL); Print("Уровень стопов: "+minstop); } void start() { if (!IsTradeAllowed()) return; level_buy_stop=0; level_sell_stop=0; StepingStop(); StepingPendings(); if (TotalBuy ()==0 && TotalBuyStop ()==0) SetBuyStop (); if (TotalSell()==0 && TotalSellStop()==0) SetSellStop(); Comment("Level Buy Stop=",level_buy_stop*Point,"\n","Level Sell Stop=",level_sell_stop*Point); } void StepingStop() { if (StepStop<1) return; int ask, bid, open, stop, x; double loss; for (int i=0; i=open+x) continue; loss=(open+x)*Point; OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE); } if (OrderType()==OP_SELL) { ask=MathRound(Ask/Point); open=MathRound(OrderOpenPrice()/Point); stop=MathRound(OrderStopLoss()/Point); x=(open-ask)/StepStop; x--; x*=StepStop; level_buy_stop=open-x; if (stop>0 && stop<=open-x) continue; loss=(open-x)*Point; OrderModify(OrderTicket(),OrderOpenPrice(),loss,OrderTakeProfit(),0,CLR_NONE); } } } void StepingPendings() { int ask, bid, open; double price, loss, profit; for (int i=0; i0) profit=price+TakeProfit*Point; OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE); } if (OrderType()==OP_SELLSTOP) { if (level_sell_stop==0) continue; open=MathRound(OrderOpenPrice()/Point); if (open>=level_sell_stop) continue; price=level_sell_stop*Point; loss=price+StepStop*Point; profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point; OrderModify(OrderTicket(),price,loss,profit,0,CLR_NONE); } } } void SetBuyStop() { double lots=LotsCounting(); double price=Bid+StepStop*Point; double loss=price-StepStop*Point; double profit=0; if (TakeProfit>0) profit=price+TakeProfit*Point; int ticket=OrderSend(Symbol(),OP_BUYSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE); if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",ErrorDescription(GetLastError())); } void SetSellStop() { double lots=LotsCounting(); double price=Ask-StepStop*Point; double loss=price+StepStop*Point; double profit=0; if (TakeProfit>0) profit=price-TakeProfit*Point; int ticket=OrderSend(Symbol(),OP_SELLSTOP,lots,price,0,loss,profit,"",0,0,CLR_NONE); if (ticket<1) Print("Set a pending order failed with error #",GetLastError()," ",ErrorDescription(GetLastError())); } int TotalBuy() { int count=0; for (int i=0; i0) lots=NormalizeDouble((MarginPercent*freemargin/lotsize),1); } if (lots>10) lots=NormalizeDouble(lots,0); if (lots<0.1) lots=0.1; return (lots); } // End