/*[[ Name := ... Author := Copyright © 2004, MetaQuotes Software Corp. Link := http://www.metaquotes.net/ Lots := 0.10 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ defines: Slippage(3); defines: BeginHour(7),FinalHour(17),CloseHour(22); defines: ReversPoint(61), maxLossTrades(3),useGraphics(0); defines: delaySeconds(30); var: curBalance(0),prevBalance(0),lossCounter(0),cnt(0),StopTradeOut(false); var: buyStopLoss(0),sellStopLoss(0); var: OpenedTrades(0),PendingOrders(0),ExpertTotal(0); var: buyExist(false),sellExist(false); var: newBuyStop(0),newSellStop(0); ExpertTotal=0; For cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol then ExpertTotal=ExpertTotal+1; } if (ExpertTotal=0 and lossCounter>=maxLossTrades and StopTradeOut=false) then { Comment("Работа прекращена после "+maxLossTrades+" убыточных сделок"); StopTradeOut=true; } if (StopTradeOut=true and TimeHour(CurTime)>CloseHour and TimeHour(CurTime)>CloseHour) then { StopTradeOut=false; lossCounter=0; Comment("Начался новый день"); } if (TimeHour(CurTime)=FinalHour) then exit; if ( ( ((TimeHour(CurTime)=CloseHour)) and ExpertTotal>0 and (CurTime-LastTradeTime>delaySeconds))or (lossCounter>=maxLossTrades)and ExpertTotal>0) then // закрываем открытый ордер и снимаем отложенный Begin Print("Закрываем открытый ордер и снимаем отложенный"); for cnt=TotalTrades DownTo 1 { If OrderValue(cnt,VAL_TYPE)=OP_BUY and OrderValue(cnt,VAL_SYMBOL)=Symbol then // открыта длинная позиция { Print("Цена закрытия=",Bid,". Ордер в покупку №",cnt,". Его номер=",OrderValue(cnt,VAL_TICKET),". Bid=",Bid,". Ask=",Ask); CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Green) ; Exit; } If OrderValue(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol then // открыта длинная позиция { Print("Цена закрытия=",Ask,". Ордер в покупку №",cnt,". Его номер=",OrderValue(cnt,VAL_TICKET),". Bid=",Bid,". Ask=",Ask); CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Green) ; Exit; } If (OrderValue(cnt,VAL_TYPE)=OP_SELLSTOP or OrderValue(cnt,VAL_TYPE)=OP_BUYSTOP) and OrderValue(cnt,VAL_SYMBOL)=Symbol then // отложенный ордер { //Print("Цена закрытия=",Ask,". Ордер в покупку №",cnt,". Его номер=",OrderValue(cnt,VAL_TICKET),". Bid=",Bid,". Ask=",Ask); DeleteOrder(OrderValue(cnt,VAL_TICKET),White) ; Exit; } } End; if TimeHour(CurTime)>=BeginHour and TimeHour(CurTime)delaySeconds and ExpertTotal>0 and lossCountercurBalance then { if (curBalanceOrderValue(cnt,VAL_STOPLOSS)or OrderValue(cnt,VAL_STOPLOSS)=0) then { newSellStop=Bid-ReversPoint*Point; //Print("Цена закрытия=",Bid,". Ордер в покупку №",cnt,". Его номер=",OrderValue(cnt,VAL_TICKET),". Bid=",Bid,". Ask=",Ask); ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),buyStopLoss,OrderValue(cnt,VAL_TAKEPROFIT),Yellow) ; Exit; } } If OrderValue(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol then // открыта длинная позиция { OpenedTrades=OpenedTrades+1; sellStopLoss=Ask+ReversPoint*Point; sellExist=true; newBuyStop=OrderValue(cnt,VAL_STOPLOSS); if (Ask+ReversPoint*Point