//<=====================================================================+|| // JS_SISTEM.mq4 || // © 2009,|| // Пишу торговые системы js_sergey@list.ru || //<=====================================================================+|| #define major 1 #define minor 0 //======================================================================|| extern string SS1 = " НАСТРОЙКИ ММ "; extern double Minsum = 100; //-$- остановка работы советника extern double Lots = 0.01;//Минимальный лот extern int SLoss = 80; //StopLoss avto Otstup extern int TakeProfit = 400; //Максимальный профит extern bool MM = True;//Управление капиталом True-вкл extern double Risk = 2; //Процент свободных средств extern int Slippage = 3; //Проскальзывание цены extern int Magic = 7777777; //======================================================================|| extern string SS2 = " MA НАСТРОЙКИ "; extern int Razk = 28;//EURUSD-28: GBRUSD-39: extern int MA_1 = 55; extern int MA_2 = 89; extern int MA_3 = 144; //======================================================================|| extern string SS3 = " OsMA НАСТРОЙКИ "; extern int fast = 13; extern int slow = 55; extern int signal = 21; //======================================================================|| extern string SS4 = " RVI НАСТРОЙКИ "; extern int RVI_Per = 55; extern double RVI_max = 0.05; extern double RVI_min = -0.05; //======================================================================|| extern string SS5 = "ТРЕЙЛИНГ ТЕНИ"; extern bool Trailing = true; extern int Tmfrm = 30; // период, по барам которого следует тралить extern int Bars_n = 13; // кол-во баров, по которым следует тралить extern int Indent = 1; // отступ от тени бара, на котором размещается стоплосс extern bool Trlinloss = false; // следует ли тралить на участке лоссов (между курсом стоплосса и открытия) //======================================================================|| extern string SS6 = " --- цвет символов ---"; extern bool UseSound = True; // Использовать звуковой сигнал extern string Sound_o = "ok.wav"; // Наименование звукового файла //======================================================================|| #include #include double new_extremum, Rsmin, Rsmax; int AvgRange; string comm; double s1[]; void start() { if(AccountFreeMargin()0.0 && RVI_M>RVI_S && RVI_S>=RVI_max && ima_a>ima_b && ima_b>ima_c && rash_1 0) return; if (CloseOrders(OP_SELL) > 0) return; price = Ask; sl = If(StopLoss > 0, price - StopLoss*Point,0); tp = If(TakeProfit > 0, price + TakeProfit*Point,0); Buy(Symbol(), GetLots(), price, sl, tp, Magic); return; } //====================================================================================================================== if (OsMA1<0.0 && RVI_M 0) return; if (CloseOrders(OP_BUY) > 0) return; price = Bid; sl = If(StopLoss > 0, price + StopLosb*Point,0); tp = If(TakeProfit > 0, price - TakeProfit*Point,0); Sell(Symbol(), GetLots(), price, sl, tp, Magic); return; }} //====================================================================================================================== double If(bool cond, double if_true, double if_false) { if (cond) return (if_true); return (if_false); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ double GetLots() { return (Lots); } int CloseOrders(int type) { int cnt = OrdersTotal(); for (int i=cnt-1; i >= 0; i--) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != Magic) continue; if (OrderType() != type) continue; if (type == OP_BUY) { RefreshRates(); CloseOrder(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID)); continue; } if (type == OP_SELL) { RefreshRates(); CloseOrder(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK)); continue; }} int orders = 0; cnt = OrdersTotal(); for (i = 0; i < cnt; i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != Magic) continue; if (OrderType() == type) orders++; } return (orders); } //====================================================================================================================== void TrailPositions() { int cnt = OrdersTotal(); for (int i=0; iiLow(NULL,Tmfrm,i)) new_extremum = iLow(NULL,Tmfrm,i); } if (Trlinloss==true) { if ((((new_extremum - Indent*Point)>OrderStopLoss()) || (OrderStopLoss()==0)) && (new_extremum - Indent*PointOrderStopLoss()) || (OrderStopLoss()==0)) && ((new_extremum - Indent*Point)>OrderOpenPrice()) && (new_extremum - Indent*PointAsk+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)) if (!OrderModify(OrderTicket(),OrderOpenPrice(),new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration())) Print("Не удалось модифицировать ордер №",OrderTicket(),". Ошибка: ",GetLastError()); } else { if ((((new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point)Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)) if (!OrderModify(OrderTicket(),OrderOpenPrice(),new_extremum + (Indent + MarketInfo(Symbol(),MODE_SPREAD))*Point,OrderTakeProfit(),OrderExpiration())) Print("Не удалось модифицировать ордер №",OrderTicket(),". Ошибка: ",GetLastError()); }}}} //====================================================================================================================== int SleepOk = 2000; int SleepErr = 6000; int Buy(string symbol, double lot, double price, double sl, double tp, int magic, string comment="") { int dig = MarketInfo(symbol, MODE_DIGITS); price = NormalizeDouble(price, dig); sl = NormalizeDouble(sl, dig); tp = NormalizeDouble(tp, dig); string _lot = DoubleToStr(lot, 2); string _price = DoubleToStr(price, dig); string _sl = DoubleToStr(sl, dig); string _tp = DoubleToStr(tp, dig); //====================================================================================================================== int res = OrderSend(symbol, OP_BUY, lot, price, Slippage, sl, tp, comment, magic, 0); PlaySound(Sound_o); if (res >= 0) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("Error opening BUY order: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (-1); } int Sell(string symbol, double lot, double price, double sl, double tp, int magic, string comment="") { int dig = MarketInfo(symbol, MODE_DIGITS); price = NormalizeDouble(price, dig); sl = NormalizeDouble(sl, dig); tp = NormalizeDouble(tp, dig); string _lot = DoubleToStr(lot, 2); string _price = DoubleToStr(price, dig); string _sl = DoubleToStr(sl, dig); string _tp = DoubleToStr(tp, dig); //====================================================================================================================== int res = OrderSend(symbol, OP_SELL, lot, price, Slippage, sl, tp, comment, magic, 0); PlaySound(Sound_o); if (res >= 0) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("Error opening SELL order: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (-1); } bool CloseOrder(int ticket, double lot, double price) { if (!OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES)) return(false); int dig = MarketInfo(OrderSymbol(), MODE_DIGITS); string _lot = DoubleToStr(lot, 2); string _price = DoubleToStr(price, dig); Print("CloseOrder ", ticket, ", ", _lot, ", ", _price, ", ", Slippage); bool res = OrderClose(ticket, lot, price, Slippage); if (res) { Sleep(SleepOk); return (res); } int code = GetLastError(); Print("CloseOrder failed: ", ErrorDescription(code), " (", code, ")"); Sleep(SleepErr); return (false); } //======================================================================================================================