#property copyright "Åâãåíèé Ë. Leus79@yandex.ru" extern int tp=1400; extern int sl=900; extern double Lots =0.08; extern double Lotmax =0.3; extern double DecreaseFactor=3; int Ust=70; int pma1=5; int pma2=8; int sst=3; int mma1=1; int mma2=1; int Us1=70; int Us2=30; int Ur1=75; int Ur2=25; int pst=5; int prsi=5; extern double SARstep=0.02; extern double SARmax=0.2; extern bool Tral=true; extern int TrailingStep=900; //--------------------------------------------------------------------- //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } bool New_Bar; int tick,tick2; double LoOp() { double lot=Lots; int orders= OrdersHistoryTotal() ; // history orders total int losses=0; // number of losses orders without a break //---- calcuulate number of losses orders without a break if(DecreaseFactor>0) { for(int l=orders-1;l>=0;l--) { if(OrderSelect(l,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; } if(OrderSymbol()==Symbol() && OrderMagicNumber()==5903442){ //---- if(OrderProfit()>0) break; if(OrderProfit()<0) losses++; } } if(losses>=DecreaseFactor) lot=Lots*losses; } //---- return lot size return(lot); } //------------------------------------------------------------------------------------------------------ int start() { if ( Period()!=240){ Print("îøèáêà-ïåðèîä íå H4!"); Comment("îøèáêà-ïåðèîä íå H4!"); return;} if (Symbol()!="EURUSD"){ Print("îøèáêà-íå EURUSD!"); Comment("îøèáêà-íå EURUSD!"); return;} if(AccountBalance()/50001<Lots){ Comment("íåäîñòàòî÷íî ñðåäñòâ!"); Print("íåäîñòàòî÷íî ñðåäñòâ!"); return;} New_Bar=false ; Fun_New_Bar(); if ( New_Bar==true){ tick=0; tick2=0;} HideTestIndicators(true); double slb,sls,tpb,tps; double m1=iMA(NULL,0,pma1,0,mma1,0,0); double m2=iMA(NULL,0,pma2,0,mma2,0,0); //--------------------------------- double m11=iMA(NULL,0,pma1,0,mma1,0,1); double m22=iMA(NULL,0,pma2,0,mma2,0,1); //--------------------------------- double r=iRSI(NULL,0,prsi,0,0); double s=iStochastic(NULL,0,pst,3,sst,0,0,0,0); double s1=iStochastic(NULL,0,pst,3,sst,0,0,0,1); if (OrderSelect(tick,SELECT_BY_TICKET)==false ){ if (m1>=m2 && m11<m22 && s>s1 && s<Us1 && r>50 && r<Ur1 && High[1]<Close[0] && High[2]<Close[0]) { double Lot, lotsel=0; for (int t=0; t<OrdersTotal(); t++) { if (OrderSelect(t,SELECT_BY_POS,MODE_TRADES) && OrderCloseTime()==0){ if (OrderSymbol()==Symbol() && OrderType()==OP_SELL && OrderMagicNumber()==5903442 && OrderProfit()<0 && OrderCloseTime()==0) { lotsel=lotsel+OrderLots();} } } Lot=lotsel+LoOp(); if (Lot>Lotmax){Lot=Lotmax;} if (m1>=m2 && m11<m22 && s>s1 && s<Us1 && r>50 && r<Ur1 && High[1]<Close[0] && High[2]<Close[0]) { slb=Ask-sl*Point ; tpb=Ask+tp*Point; while(tick<=0){ tick=OrderSend ( Symbol(),OP_BUY,Lot, Ask, 5,slb,tpb,"buy",5903442); } } } } if (OrderSelect(tick2,SELECT_BY_TICKET)==false ){ //-------------------- if (m1<=m2 && m11>m22 && s<s1 && s>Us2 && r<50 && r>Ur2 && Low[1]>Close[0] && Low[2]>Close[0]) { double lotbuy=0; for (int å=0; å<OrdersTotal(); å++) { if (OrderSelect(å,SELECT_BY_POS,MODE_TRADES) && OrderCloseTime()==0){ if (OrderSymbol()==Symbol() && OrderType()==OP_BUY && OrderMagicNumber()==5903442 && OrderProfit()<0 && OrderCloseTime()==0){ lotbuy=lotbuy+OrderLots();} } } Lot=lotbuy+LoOp(); if (Lot>Lotmax){Lot=Lotmax;} if (m1<=m2 && m11>m22 && s<s1 && s>Us2 && r<50 && r>Ur2 && Low[1]>Close[0] && Low[2]>Close[0]) { sls=Bid+sl*Point; tps=Bid-tp*Point; while(tick2<=0){ tick2=OrderSend ( Symbol(),OP_SELL,Lot, Bid, 5,sls,tps,"sel",5903442); } } } } SarTrailingStop(); close(); //----------------------------------------------------------------------------------------------- return(0); } void Fun_New_Bar() { static datetime New_Time=0; New_Bar=false; if(New_Time!=Time[0]) { New_Time=Time[0]; New_Bar=true; } } //Òðåéäèíã ñòîï================================================================================ int SarTrailingStop() { double sar=iSAR(NULL,0,SARstep,SARmax,1); for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS)==true) { if(Tral==true && OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==5903442) { if(sar>OrderStopLoss()) { if((sar-OrderStopLoss())>=TrailingStep*Point && (Bid-sar)>MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),sar,OrderTakeProfit(),0); } } } } if(OrderSelect(i-1,SELECT_BY_POS)==true) { if(Tral==true && OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==5903442) { if(OrderStopLoss()>sar) { if((OrderStopLoss()-sar)>TrailingStep*Point && (sar-Ask)>MarketInfo(Symbol(),MODE_STOPLEVEL)*Point) { OrderModify(OrderTicket(),OrderOpenPrice(),sar,OrderTakeProfit(),0); } } } } } return(0); } //çàêðûòèå=========================================================================== int close() { double M1=iMA(NULL,0,5,0,1,0,0); double M2=iMA(NULL,0,5,0,1,1,0); double M11=iMA(NULL,0,5,0,1,0,1); double M21=iMA(NULL,0,5,0,1,1,1); for(int y=0; y<OrdersTotal(); y++) { if(OrderSelect(y,SELECT_BY_POS,MODE_TRADES)==true && OrderMagicNumber()==5903442){ if (OrderType()==OP_BUY && M1<M2-(Ust*Point) && M11>M2 && Bid<Low[1] && OrderProfit()>0){ OrderClose(OrderTicket(),OrderLots(),Bid,5);} if (OrderType()==OP_SELL && M1>M2+(Ust*Point) && M11<M2 && Ask>High[1] && OrderProfit()>0){ OrderClose(OrderTicket(),OrderLots(),Ask,5);} } } }
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Moving average indicator
Relative strength index
Stochastic oscillator
Parabolic Stop and Reverse system
Custom Indicators Used:
Order Management characteristics:
Checks for the total of closed orders
Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It Closes Orders by itself
Other Features: