//+------------------------------------------------------------------+ extern double Lots = 100; extern int StopLoss = 30; extern int TakeProfit = 11; extern int TrailingStop = 5; extern double minLots = 0; extern bool UseMG = true; int LastTotal; datetime LastTime; //+------------------------------------------------------------------+ int init() { return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int i,cnt; double pos1pre,pos2cur,SLoss,ord_lot; pos1pre = iBullsPower(NULL,0,13,PRICE_WEIGHTED,1); pos2cur = iBullsPower(NULL,0,13,PRICE_WEIGHTED,0); if(pos1pre>pos2cur) //ÃÞÉÏØÁÞÅË ÄÊÕÌÌÑ× ÎÍÃÕÆÕ× { for(cnt=0; cnt<OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY) // ÍÐÉÏØÐÞ ÄÊÕÌÌÞÚ ÎÍÃÕÆÕÚ { if(Bid>(OrderOpenPrice())+TrailingStop*Point) { OrderClose(OrderTicket(),OrderLots(),Bid,3); // ÃÞÉÏØÁÞÅË ÎÍÃÕÆÕ× return(0); // ÁØÓÍÄÕË } } } } if(pos2cur<0) //ÃÞÉÏØÁÞÅË ÉÍÏÍÐÉÑ× ÎÍÃÕÆÕ× { for(cnt=0; cnt<OrdersTotal(); cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(Ask<OrderOpenPrice()-TrailingStop*Point) { if(OrderType()==OP_SELL) // ÍÐÉÏØÐÞ ÉÍÏÍÐÉÞÚ ÎÍÃÕÆÕÚ { OrderClose(OrderTicket(),OrderLots(),Ask,3); // ÃÞÉÏØÁÞÅË ÎÍÃÕÆÕ× return(0); // ÁØÓÍÄÕË } } } } if(OrdersTotal()<LastTotal) LastTime=Time[0]+Period()*60; LastTotal=OrdersTotal(); if(CurTime()<LastTime) return(0); ord_lot = Lots; if(minLots!=0) Lots=minLots; else { if(UseMG) { for(i=HistoryTotal()-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) { ord_lot = NormalizeDouble(OrderLots()/2,1); if(ord_lot<10) ord_lot=10; break; } if(OrderProfit()<0 && OrderClosePrice() == OrderStopLoss()) { ord_lot = OrderLots()*MathRound(StopLoss/TakeProfit); if(ord_lot < Lots) ord_lot=Lots; if(ord_lot > NormalizeDouble(AccountFreeMargin()/1000.0,1)) ord_lot = NormalizeDouble(AccountFreeMargin()/1000.0,1); break; } } } if (StringSubstr(Symbol(),3,3) == "USD") { if (ord_lot > NormalizeDouble(AccountFreeMargin()/1000.0/Bid,1)) ord_lot = NormalizeDouble(AccountFreeMargin()/1000.0/Bid,1); } } SLoss=0; if(OrdersTotal()<1) // ÌÅÐ ÌÕ ÍÄÌÍÖÍ ÍÐÉÏØÐÍÖÍ ÍÏÄÅÏÞ ÎÏÍÁÅÏÚÅË ÌÞ ÁÍÃËÍÔÌÍßÐÝ ÁßÐÞÐÝ Á ÉÍÏÍÐÉÑ× ÎÍÃÕÆÕ× (SELL) { if(pos1pre>pos2cur && pos2cur>0) { if(StopLoss!=0) SLoss=Ask+StopLoss*Point; OrderSend(Symbol(),OP_SELL,ord_lot,Bid,3,SLoss,Bid-TakeProfit*Point,0,0,CLR_NONE); // íÐÉÏØÁÞÅË ÉÍÏÍÐÉÑ× if(!IsDemo()) Sleep(15000); return(0); // ÁØÓÍÄÕË } if(pos2cur<0) { if(StopLoss!=0) SLoss=Bid-StopLoss*Point; OrderSend(Symbol(),OP_BUY,ord_lot,Ask,3,SLoss,Ask+TakeProfit*Point,0,0,CLR_NONE); // íÐÉÏØÁÞÅË ÉÍÏÍÐÉÑ× return(0); // ÁØÓÍÄÕË } } return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Bulls Power indicator
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It Closes Orders by itself
It automatically opens orders when conditions are reached
Other Features: