//+------------------------------------------------------------------+ //| MA.mq4 | //| Copyright © 2010, ZerkMax | //| zma@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, ZerkMax" #property link "zma@mail.ru" extern double Lots = 0; // лот, если 0, то динамический extern double RiskPercentage = 70; // % от депо на лот, если динамический extern int FastPer = 4; extern int SlowPer = 18; extern int magicnumber = 777; extern int TrailingStop = 20; extern bool PolLots = true; int prevtime; int ticket=0; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- if (!IsDemo()) { // Print ("Эта версия только для демо-счетов"); // return(0); } if(Time[0] == prevtime) { return(0); } prevtime = Time[0]; if(!IsTradeAllowed()) { prevtime = Time[1]; return(0); } int Ord=0; double ClLot=0; int LotsCount=0; int i=0; int total = OrdersTotal(); for(i = 0; i <= total; i++) { if(TrailingStop>0) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderMagicNumber() == magicnumber) { ticket=OrderTicket(); ClLot=OrderLots(); if (OrderType()==OP_BUY) { Ord=1; } else { Ord=2; } LotsCount ++; TrailingStairs(OrderTicket(),TrailingStop); } } } /* for(i = 0; i <= OrdersTotal(); i++) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if(OrderMagicNumber() == magicnumber) { ticket=OrderTicket(); ClLot=OrderLots(); if (OrderType()==OP_BUY) { Ord=1; } else { Ord=2; } } } */ bool SellOp=false; bool BuyOp=false; double MAFast1=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,2),Digits); double MAFast2=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,1),Digits); double MAFast3=NormalizeDouble(iMA(NULL,0,FastPer,0,MODE_SMA,PRICE_CLOSE,0),Digits); double MASlow1=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,2),Digits); double MASlow2=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,1),Digits); double MASlow3=NormalizeDouble(iMA(NULL,0,SlowPer,0,MODE_SMA,PRICE_CLOSE,0),Digits); if ((MAFast1MASlow3)) { BuyOp=true; } if ((MAFast1>MASlow1)&& (MAFast2==MASlow2)&& (MAFast3(Point*trldistance)) { if(OrderStopLoss()MarketInfo(Symbol(), MODE_MINLOT)) { OrderClose(ticket,NormalizeDouble(OrderLots()/2,1),Bid,3,Green); } else { OrderClose(ticket,OrderLots(),Bid,3,Green); } } } } else { if((OrderOpenPrice()-Ask)>(Point*trldistance)) { if((OrderStopLoss()>(Ask+Point*trldistance)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*trldistance,OrderTakeProfit(),0,Red); if (PolLots) if (NormalizeDouble(OrderLots()/2,1)>MarketInfo(Symbol(), MODE_MINLOT)) { OrderClose(ticket,NormalizeDouble(OrderLots()/2,1),Ask,3,Green); } else { OrderClose(ticket,OrderLots(),Ask,3,Green); } } } } } double Lot() { double LotQ = Lots; if (Lots==0) { double margin = MarketInfo(Symbol(), MODE_MARGINREQUIRED); double minLot = MarketInfo(Symbol(), MODE_MINLOT); double maxLot = MarketInfo(Symbol(), MODE_MAXLOT); double step = MarketInfo(Symbol(), MODE_LOTSTEP); double account = AccountFreeMargin(); double percentage = account*RiskPercentage/100; LotQ = MathRound(percentage/margin/step)*step; if(LotQ < minLot) { LotQ = minLot; } if(LotQ > maxLot) { LotQ = maxLot; } } return (LotQ); }