extern double MAGICMA =20050610; extern double Lots = 0.1; extern double MaximumRisk = 0.02; extern double DecreaseFactor = 3; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { double nlots=0.1,order; int dd=0,hh=0,cnt=0,expiration; expiration=CurTime()+PERIOD_D1*60; for(cnt=0 ;cnt< OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderSymbol()==Symbol()) hh=1; if (OrderType() == OP_BUY && OrderSymbol()==Symbol()) dd=1; } if (OrdersTotal() >0) return; int ticket = OrderSend(Symbol(),OP_SELLSTOP,LotsOptimized(),Bid-30*Point,3,Bid+30*Point,Bid-60*Point,"",MAGICMA,expiration,Red); if (OrdersTotal() >1) return; ticket = OrderSend(Symbol(),OP_BUYSTOP,LotsOptimized(),Ask+30*Point,3,Ask-30*Point,Ask+60*Point,"",MAGICMA,expiration,Green); } double LotsOptimized() { double lot=Lots; int orders=HistoryTotal(); // history orders total int losses=0; // number of losses orders without a break //---- select lot size lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1); //---- calcuulate number of losses orders without a break if(DecreaseFactor>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) break; if(OrderProfit()<0) losses++; } if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1); } //---- return lot size if(lot<0.1) lot=0.1; if(lot>10) lot=10; return(lot); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
Other Features: