extern int MinPrfofit = 1; extern int MaxLoss = 10; extern int Delta = 3; extern int BB_Period = 1; extern int BB_Deviation = 2; extern bool FixLotMM = FALSE; extern double FixLotSize = 0.1; extern double RiskPercent = 10.0; extern int Slippage = 2; extern string Comm = "QQ:4225275 "; int MagicNum; double StopPoint, Spread, LotStep, Lots, Lots1, MaxLot, MinLot; double SetPoint() { double PricePoint; if (Digits == 3) PricePoint = 0.01; else { if (Digits == 5) PricePoint = 0.0001; else PricePoint = Point; } return(PricePoint); } int init() { MagicNum = StringGetChar(Symbol(), 0) + 77704 + StringGetChar(Symbol(), 1) * 2 + 3 * StringGetChar(Symbol(), 3) + StringGetChar(Symbol(), 4) << 2 + 10000 * Period(); StopPoint = MarketInfo(Symbol(), MODE_STOPLEVEL); Spread = MarketInfo(Symbol(), MODE_SPREAD); MaxLot = MarketInfo(Symbol(), MODE_MAXLOT); MinLot = MarketInfo(Symbol(), MODE_MINLOT); LotStep = MarketInfo(Symbol(), MODE_LOTSTEP); // HideTestIndicators(TRUE); return(0); } int start() { int i; double SLPrice, TPPrice, DiffPrice; bool LongSignal, ShortSignal; double UpperBoll, LowerBoll; if (FixLotMM) Lots = FixLotSize; else Lots = AccountFreeMargin() / 1000.0 * (RiskPercent / 100.0); if (Lots < MinLot) Lots = MinLot; else { if (Lots > MaxLot) Lots = MaxLot; else { for (Lots1 = MinLot; Lots1 <= Lots; Lots1 += LotStep) {} Lots = Lots1 - LotStep; } } if (Lots > 2300.0) Lots = NormalizeDouble(Lots, 0); for (i = OrdersTotal() - 1; i >= 0; i--) { OrderSelect(i, SELECT_BY_POS); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNum) continue; if (OrderType() == OP_BUY) { DiffPrice = Bid - OrderOpenPrice(); if ((MinPrfofit > 0 && DiffPrice >= MinPrfofit * SetPoint()) || (MaxLoss > 0 && DiffPrice <= (-1 * MaxLoss) * SetPoint())) { OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Purple); return(0); } } if (OrderType() == OP_SELL) { DiffPrice = OrderOpenPrice() - Ask; if ((MinPrfofit > 0 && DiffPrice >= MinPrfofit * SetPoint()) || (MaxLoss > 0 && DiffPrice <= (-1 * MaxLoss) * SetPoint())) { OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red); return(0); } } return(0); } UpperBoll = iBands(Symbol(), 0, BB_Period, BB_Deviation, 0, PRICE_OPEN, MODE_UPPER, 0); LowerBoll = iBands(Symbol(), 0, BB_Period, BB_Deviation, 0, PRICE_OPEN, MODE_LOWER, 0); if (Close[0] > UpperBoll + Delta * SetPoint()) ShortSignal = TRUE; else ShortSignal = FALSE; if (Close[0] < LowerBoll - Delta * SetPoint()) LongSignal = TRUE; else LongSignal = FALSE; if (LongSignal) { if (MaxLoss == 0) SLPrice = 0; else SLPrice = Ask - (MaxLoss + StopPoint) * SetPoint(); if (MinPrfofit == 0) TPPrice = 0; else TPPrice = Ask + (MinPrfofit + StopPoint + Spread) * SetPoint(); OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, SLPrice, TPPrice, Comm, MagicNum, 0xFF0000); } if (ShortSignal) { if (MaxLoss == 0) SLPrice = 0; else SLPrice = Bid + (MaxLoss + StopPoint) * SetPoint(); if (MinPrfofit == 0) TPPrice = 0; else TPPrice = Bid - (MinPrfofit + StopPoint + Spread) * SetPoint(); OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, SLPrice, TPPrice, Comm, MagicNum, 0x0000FF); } return(0); }