#property copyright "AcAoStDv" extern int EA_magic = 20090818; extern double Slippage = 2; extern double minLots = 0.01; extern double maxLots = 100; extern int Risk_percent = 3; extern int EmergencyStop = 200; int numPos; bool TradeBuy; double Lots, myPoint; string IndiName = "acaostdv_sig"; datetime LastSignal; int init() { myPoint = Point; if(Digits == 5 || Digits == 3) myPoint = myPoint * 10; return(0); } void count_position() { int ordticket; numPos = 0; for( int i = 0 ; i < OrdersTotal() ; i++ ){ if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) == false ){ break; } if( OrderMagicNumber() != EA_magic ){ continue; } if( OrderSymbol() != Symbol() ){ continue; } ordticket = OrderTicket(); numPos++; } if(numPos > 0) OrderSelect(ordticket,SELECT_BY_TICKET, MODE_TRADES); } void CheckForClose() { if((iCustom(Symbol(),NULL,IndiName,2,2)!=iCustom(Symbol(),NULL,IndiName,2,1) && LastSignal!=Time[0])) OrderClose(OrderTicket(),OrderLots(),Bid,Slippage+MarketInfo(Symbol(),MODE_SPREAD),CLR_NONE); return(0); } int start() { int ticket; if( IsTradeAllowed() != true ){ return(0); } count_position(); if( numPos > 0) CheckForClose(); else { if( get_signal() == true ) { Call_MM(EmergencyStop); if( TradeBuy == false ) ticket = OrderSend( Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+EmergencyStop*myPoint, 0, "acaostddv", EA_magic, 0, Red ); else ticket = OrderSend( Symbol(), OP_BUY, Lots, Ask, Slippage, Ask-EmergencyStop*myPoint, 0, "acaostddv", EA_magic, 0, Blue ); if( ticket < 0 ) Sleep(5000); LastSignal = Time[0]; } } return(0); } bool get_signal() { bool enable_trade = false; if( Bars >= 100 &&iCustom(Symbol(),NULL,IndiName,2,2)!=iCustom(Symbol(),NULL,IndiName,2,1)) { if(iCustom(Symbol(),NULL,IndiName,2,1)==1) { TradeBuy = true; enable_trade = true; } if(iCustom(Symbol(),NULL,IndiName,2,1)==-1) { TradeBuy = false; enable_trade = true; } } return(enable_trade); } void Call_MM(double slpips) { Lots=((AccountBalance()*Risk_percent/100)/slpips)/MarketInfo(Symbol(),MODE_TICKVALUE); Lots=MathMin(maxLots,MathMax(minLots,Lots)); if(minLots<0.1) Lots=NormalizeDouble(Lots,2); // 1k else { if(minLots<1) Lots=NormalizeDouble(Lots,1); // 10k else Lots=NormalizeDouble(Lots,0); // 100k } return(0); }