//+------------------------------------------------------------------+ //| HedgeMargin.mq5 | //| Copyright 2025, Denversid | //| https://t.me/Denversid | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Denversid" #property link "https://t.me/Denversid " #property version "1.00" #include #include #include CTrade trade; CSymbolInfo symInfo; CPositionInfo posInfo; input int delayMinutes = 5; // Задержка между сделками в минутах input bool revers = true; // Если true - Сначала buy покупки, false - Сначала sell покупки datetime lastTradeTime = 0; //+------------------------------------------------------------------+ //| Функция подсчета количества позиций | //+------------------------------------------------------------------+ int GetAllPositionCount() { int allCount = 0; for(int i = PositionsTotal() - 1; i >= 0; i--) { if(posInfo.SelectByIndex(i)) { if(posInfo.Magic() == 555556 && posInfo.Symbol() == _Symbol) { allCount++; } } } return allCount; } //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { trade.SetExpertMagicNumber(555556); // Замена цвета графика МТ5 ChartSetInteger(0, CHART_COLOR_CHART_UP, clrLime); ChartSetInteger(0, CHART_COLOR_CHART_DOWN, clrRed); ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, clrLime); ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, clrRed); ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrBlack); ChartSetInteger(0, CHART_SHOW_GRID, false); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(TimeCurrent() - lastTradeTime < delayMinutes * 60) return; int positionCount = GetAllPositionCount(); if(positionCount < 5) { if(revers) { if(trade.Buy(1)) lastTradeTime = TimeCurrent(); } else { if(trade.Sell(1)) lastTradeTime = TimeCurrent(); } } else if(positionCount >= 5 && positionCount < 10) { if(revers) { if(trade.Sell(1)) lastTradeTime = TimeCurrent(); } else { if(trade.Buy(1)) lastTradeTime = TimeCurrent(); } } } //+------------------------------------------------------------------+