//+------------------------------------------------------------------+
//|                                                   Stalin_HTF.mq5 | 
//|                               Copyright © 2018, Nikolay Kositsin | 
//|                              Khabarovsk,   <PRESIDIO_ANONYMIZED_EMAIL_ADDRESS> | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2018, Nikolay Kositsin"
#property link "farria@mail.redcom.ru"
//--- version number of the indicator
#property version   "1.60"
#property description "Stalin indicator with the ability to change timeframes in input parameters"
//--- drawing the indicator in the main window
#property indicator_chart_window 
//--- number of indicator buffers 2
#property indicator_buffers 2
//--- using a total of two graphical constructions
#property indicator_plots   2
//+----------------------------------------------+
//|  constant declarations                        |
//+----------------------------------------------+
#define RESET 0                     // constant to reset terminal command for indicator recalculation
#define INDICATOR_NAME "Stalin"     // constant for indicator name
#define SIZE 1                      // constant for the number of calls to CountIndicator function in the code
#define EMPTYVALUE 0.0              // constant for non-displayed indicator values
//+----------------------------------------------+
//|  Parameters for drawing indicator 1          |
//+----------------------------------------------+
//--- drawing indicator 1 as a symbol
#property indicator_type1   DRAW_ARROW
//--- pink color is used for the bearish line of the indicator
#property indicator_color1  clrMagenta
//--- thickness of indicator line 1 is 2
#property indicator_width1  2
//--- display label of the indicator
#property indicator_label1  "Stalin Sell"
//+----------------------------------------------+
//|  Parameters for drawing indicator 2          |
//+----------------------------------------------+
//--- drawing indicator 2 as a symbol
#property indicator_type2   DRAW_ARROW
//--- light green color is used for the bullish line of the indicator
#property indicator_color2  clrLime
//--- thickness of indicator line 2 is 3
#property indicator_width2  3
//--- display label of the indicator
#property indicator_label2  "Stalin Buy"
//+-------------------------------------+
//| Input parameters for the indicator   |
//+-------------------------------------+ 
input ENUM_TIMEFRAMES TimeFrame=PERIOD_H4; // Timeframe for the indicator
input ENUM_MA_METHOD MAMethod=MODE_EMA;
input int    MAShift=0;
input int    Fast=14;
input int    Slow=21;
input int    RSI=17;
input int    Confirm=0.0;
input int    Flat=0.0;
input bool   SoundAlert=false;
input bool   EmailAlert=false;
input uint SellSymb=234;                  // sell symbol
input uint BuySymb=233;                   // buy symbol
//+-------------------------------------+
//--- dynamic array declarations that will be used as indicator buffers
double DnBuffer[];
double UpBuffer[];
//--- integer variable declarations for the start of data counting
int min_rates_total;
//--- integer variable declarations for indicator handles
int Ind_Handle;
//+------------------------------------------------------------------+
//|  Get timeframe as a string                                          |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
  {return(StringSubstr(EnumToString(timeframe),7,-1));}
//+------------------------------------------------------------------+    
//| Custom indicator initialization function                           | 
//+------------------------------------------------------------------+  
int OnInit()
  {
//--- initialize variables 
   min_rates_total=2;
//--- get handle of the Stalin indicator
   Ind_Handle=iCustom(Symbol(),TimeFrame,"Stalin",MAMethod,MAShift,Fast,Slow,RSI,Confirm,Flat,SoundAlert,EmailAlert);
   if(Ind_Handle==INVALID_HANDLE)
     {
      Print(" Failed to get handle of the Stalin indicator");
      return(INIT_FAILED);
     }
//--- initialize indicator buffers
   IndInit(0,DnBuffer,EMPTYVALUE,min_rates_total,0,SellSymb);
   IndInit(1,UpBuffer,EMPTYVALUE,min_rates_total,0,BuySymb);
//--- create name for display in a separate subwindow and in tooltips
   string shortname;
   StringConcatenate(shortname,INDICATOR_NAME,"(",GetStringTimeframe(TimeFrame),")");
   IndicatorSetString(INDICATOR_SHORTNAME,shortname);
//--- set the accuracy for displaying indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- end of initialization
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+    
void OnDeinit(const int reason)
  {
//----
   Comment("");
//----
   ChartRedraw(0);
  }
//+------------------------------------------------------------------+  
//| Custom iteration function                                        | 
//+------------------------------------------------------------------+  
int OnCalculate(const int rates_total,    // number of history in bars at the current tick
                const int prev_calculated,// number of history in bars at the previous tick
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- check the validity of the chart periods
   if(!TimeFramesCheck(INDICATOR_NAME,TimeFrame)) return(RESET);
//--- check the number of bars for sufficient calculation
   if(rates_total<min_rates_total) return(RESET);
   if(BarsCalculated(Ind_Handle)<Bars(Symbol(),TimeFrame)) return(prev_calculated);
//--- index elements in arrays like in time series  
   ArraySetAsSeries(time,true);
//---
   if(!CountIndicator(0,NULL,TimeFrame,Ind_Handle,0,DnBuffer,1,UpBuffer,time,rates_total,prev_calculated,min_rates_total)) return(RESET);
//---     
   return(rates_total);
  }
//---
//+------------------------------------------------------------------+
//| Initialize indicator buffer                                       |
//+------------------------------------------------------------------+    
void IndInit(int Number,double &Buffer[],double Empty_Value,int Draw_Begin,int nShift,int Symb)
  {
//--- convert dynamic array to indicator buffer
   SetIndexBuffer(Number,Buffer,INDICATOR_DATA);
//--- set the beginning of the drawing offset for the indicator
   PlotIndexSetInteger(Number,PLOT_DRAW_BEGIN,Draw_Begin);
//--- set values of the indicator that will not be visible on the chart
   PlotIndexSetDouble(Number,PLOT_EMPTY_VALUE,Empty_Value);
//--- setting the shift of the indicator 2 horizontally
   PlotIndexSetInteger(Number,PLOT_SHIFT,nShift);
//--- symbol for the indicator
   PlotIndexSetInteger(Number,PLOT_ARROW,Symb);
//--- index elements in the buffer like in time series
   ArraySetAsSeries(Buffer,true);
//---
  }
//+------------------------------------------------------------------+
//| CountLine                                                        |
//+------------------------------------------------------------------+
bool CountIndicator(uint     Numb,            // Number of the CountLine function in the indicator code (starting number - 0)
                    string   Symb,            // Chart symbol
                    ENUM_TIMEFRAMES TFrame,   // Chart timeframe
                    int      IndHandle,       // Handle of the processed indicator
                    uint     BuffNumb1,       // Number of the processed indicator buffer
                    double&  IndBuf1[],       // Receiving indicator buffer
                    uint     BuffNumb2,       // Number of the processed indicator buffer
                    double&  IndBuf2[],       // Receiving indicator buffer
                    const datetime& iTime[],  // Time series
                    const int Rates_Total,    // number of history in bars at the current tick
                    const int Prev_Calculated,// number of history in bars at the previous tick
                    const int Min_Rates_Total) // minimum number of history in bars for calculation
  {
//---
   static int LastCountBar[SIZE];
   datetime IndTime[1];
   int limit;
//--- calculation of the required amount of data to be copied
//--- and the starting number limit for the loop counting the bars
   if(Prev_Calculated>Rates_Total || Prev_Calculated<=0)// check for the first start of indicator calculation
     {
      limit=Rates_Total-Min_Rates_Total-1; // starting number to calculate all bars
      LastCountBar[Numb]=limit;
     }
   else limit=LastCountBar[Numb]+Rates_Total-Prev_Calculated; // starting number to calculate new bars 
//--- main loop for indicator calculation
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      //--- reset the contents of the indicator buffers before calculation
      IndBuf1[bar]=EMPTYVALUE;
      IndBuf2[bar]=EMPTYVALUE;
      //--- copy newly appeared data into the IndTime array
      if(CopyTime(Symbol(),TFrame,iTime[bar],1,IndTime)<=0) return(RESET);

      if(iTime[bar]>=IndTime[0] && iTime[bar+1]<IndTime[0])
        {
         LastCountBar[Numb]=bar;
         double Arr1[1],Arr2[1];
         //--- copy newly appeared data into the Arr array
         if(CopyBuffer(IndHandle,BuffNumb1,iTime[bar],1,Arr1)<=0) return(RESET);
         if(CopyBuffer(IndHandle,BuffNumb2,iTime[bar],1,Arr2)<=0) return(RESET);
         IndBuf1[bar]=Arr1[0];
         IndBuf2[bar]=Arr2[0];
        }
      else
        {
         IndBuf1[bar]=IndBuf1[bar+1];
         IndBuf2[bar]=IndBuf2[bar+1];
        }
     }
//---     
   return(true);
  }
//+------------------------------------------------------------------+
//| TimeFramesCheck()                                                |
//+------------------------------------------------------------------+    
bool TimeFramesCheck(string IndName,
                     ENUM_TIMEFRAMES TFrame) // Timeframe of the indicator
  {
//--- check the validity of the chart periods
   if(TFrame<Period() && TFrame!=PERIOD_CURRENT)
     {
      Comment("The chart period for the indicator "+IndName+" cannot be less than the period of the current chart! \n You should change the input parameters of the indicator!");
      return(RESET);
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+


use a confirmação de entreguar signal de compra e venda do codigo acima e coloque no meu codigo abaixo no lugar das medias moveis e engolfo e use em confluencia com os indicadores que ja tem no meu codigo abaixo e me entregue o codigo completo com a alteração:

#include <Trade/Trade.mqh>

// ---- INPUTS ----
input group "--- Trading Inputs ---";
input double Lots = 0.01; // Lot Size
input int TpPoints = 50; // Take Profit in points [m5-50p, h1-200p]
input int StopLossPoints = 65000; // Stop Loss in points
input ENUM_TIMEFRAMES IchimokuTimeFrame = PERIOD_CURRENT; // Timeframe (will use current timeframe)

// ---- Ichimoku Inputs ----
input int TenkanPeriod = 9; // Tenkan-sen Period
input int KijunPeriod = 26; // Kijun-sen Period
input int SenkouSpanBPeriod = 52; // Senkou Span B Period
input int Displacement = 26; // Displacement

// ---- Stochastic Inputs ----
input int StochasticKPeriod = 5; // %K period
input int StochasticDPeriod = 3; // %D period
input int StochasticSlowing = 3; // Slowing for the Stochastic

// ---- Parabolic SAR Inputs ----
input double SARStep = 0.02; // Parabolic SAR Step
input double SARMaximum = 0.2; // Parabolic SAR Maximum

// ---- Bollinger Bands Inputs ----
input int BollingerPeriod = 20; // Bollinger Bands Period
input double BollingerDeviation = 2.0; // Bollinger Bands Deviation

// ---- RSI Inputs ----
input int RsiPeriod = 14; // RSI Period
input double RsiOverbought = 70.0; // RSI Overbought Level
input double RsiOversold = 30.0; // RSI Oversold Level

// ---- ATR Inputs ----
input int AtrPeriod = 14; // ATR Period
input double AtrMultiplier = 1.5; // ATR Multiplier for volatility filter

// ---- Spread Maximum ----
input double MaxSpread = 30.0; // Maximum spread in points

// ---- GLOBAL VARIABLES ----
int handleIchimoku;
int handleStochastic;
int handleSAR;
int handleBollinger;
int handleRsi;
int handleAtr;
int handleSMA200;
int handleSMA20;

double Tenkan[], Kijun[], SenkouSpanA[], SenkouSpanB[], Chikou[];
double StochasticK[], StochasticD[];
double SAR[];
double BollingerUpper[], BollingerMiddle[], BollingerLower[];
double RsiBuffer[];
double AtrBuffer[];
double SMA200[];
double SMA20[];

CTrade trade;

int barsTotal;

// ---- EXPERT INIT ----
int OnInit()
{
    handleIchimoku = iIchimoku(_Symbol, Period(), TenkanPeriod, KijunPeriod, SenkouSpanBPeriod);
    handleStochastic = iStochastic(_Symbol, Period(), StochasticKPeriod, StochasticDPeriod, StochasticSlowing, MODE_SMA, STO_LOWHIGH);
    handleSAR = iSAR(_Symbol, Period(), SARStep, SARMaximum);
    handleBollinger = iBands(_Symbol, Period(), BollingerPeriod, BollingerDeviation, 0, PRICE_CLOSE);
    handleRsi = iRSI(_Symbol, Period(), RsiPeriod, PRICE_CLOSE);
    handleAtr = iATR(_Symbol, Period(), AtrPeriod);
    handleSMA200 = iMA(_Symbol, Period(), 200, 0, MODE_SMA, PRICE_CLOSE);
    handleSMA20 = iMA(_Symbol, Period(), 20, 0, MODE_SMA, PRICE_CLOSE);
    
    return(INIT_SUCCEEDED);
}

// ---- EXPERT DEINIT ----
void OnDeinit(const int reason)
{
    IndicatorRelease(handleIchimoku);
    IndicatorRelease(handleStochastic);
    IndicatorRelease(handleSAR);
    IndicatorRelease(handleBollinger);
    IndicatorRelease(handleRsi);
    IndicatorRelease(handleAtr);
    IndicatorRelease(handleSMA200);
    IndicatorRelease(handleSMA20);
}

// ---- ON TICK FUNCTION ----
void OnTick()
{
    int bars = iBars(_Symbol, Period());
    if(barsTotal != bars)
    {
        barsTotal++;
        double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
        double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
        double spread = (ask - bid) / _Point;

        // Verificar spread máximo
        if(spread > MaxSpread)
        {
            Print(__FUNCTION__, " > Spread too high: ", spread, " points");
            return;
        }

        // Copiar os dados do Ichimoku
        CopyBuffer(handleIchimoku, 0, 0, 1, Tenkan); // Tenkan-sen
        CopyBuffer(handleIchimoku, 1, 0, 1, Kijun);  // Kijun-sen
        CopyBuffer(handleIchimoku, 2, 0, 1, SenkouSpanA); // Senkou Span A
        CopyBuffer(handleIchimoku, 3, 0, 1, SenkouSpanB); // Senkou Span B
        CopyBuffer(handleIchimoku, 4, 0, 1, Chikou); // Chikou Span

        // Copiar os dados do Estocástico
        CopyBuffer(handleStochastic, 0, 0, 1, StochasticK); // %K
        CopyBuffer(handleStochastic, 1, 0, 1, StochasticD); // %D

        // Copiar os dados do Parabolic SAR
        CopyBuffer(handleSAR, 0, 0, 1, SAR);

        // Copiar os dados das Bandas de Bollinger
        CopyBuffer(handleBollinger, 0, 0, 1, BollingerUpper);  // Upper Band
        CopyBuffer(handleBollinger, 1, 0, 1, BollingerMiddle); // Middle Band
        CopyBuffer(handleBollinger, 2, 0, 1, BollingerLower);  // Lower Band

        // Copiar os dados do RSI
        CopyBuffer(handleRsi, 0, 0, 1, RsiBuffer);

        // Copiar os dados do ATR
        CopyBuffer(handleAtr, 0, 0, 1, AtrBuffer);

        // Copiar os dados do SMA de 200 períodos
        CopyBuffer(handleSMA200, 0, 0, 1, SMA200);

        // Copiar os dados do SMA de 20 períodos
        CopyBuffer(handleSMA20, 0, 0, 1, SMA20);

        // Verificar se já existem posições abertas
        bool hasOpenPosition = false;
        for(int i = 0; i < PositionsTotal(); i++)
        {
            ulong posTicket = PositionGetTicket(i);
            if(PositionSelectByTicket(posTicket) && PositionGetString(POSITION_SYMBOL) == _Symbol)
            {
                hasOpenPosition = true;
                break;
            }
        }

        // Filtro de volatilidade
        double atr = AtrBuffer[0];
        double volatilityThreshold = atr * AtrMultiplier;

        // Calcular a diferença percentual entre as médias móveis de 20 e 200 períodos
        double smaDistance = (SMA20[0] - SMA200[0]) / SMA200[0] * 100;

        // Limite para diferença percentual (exemplo: 5%)
        double smaThreshold = 5.0;

        // Sinal de VENDA
        if(!hasOpenPosition && smaDistance < smaThreshold && Tenkan[0] < Kijun[0] && bid < SenkouSpanA[0]
            && StochasticK[0] > StochasticD[0] && StochasticK[0] > 80 && bid > SAR[0]
            && bid > BollingerMiddle[0] && RsiBuffer[0] < RsiOverbought && atr < volatilityThreshold
            && SMA20[0] < SMA200[0] && bid < SMA200[0])
        {
            Print(__FUNCTION__, " > SELL Signal...");
            trade.Sell(Lots, _Symbol, 0, bid + StopLossPoints * _Point, bid - TpPoints * _Point);
        }
        
        // Sinal de COMPRA
        else if(!hasOpenPosition && smaDistance < smaThreshold && Tenkan[0] > Kijun[0] && bid > SenkouSpanA[0]
            && StochasticK[0] < StochasticD[0] && StochasticK[0] < 20 && bid < SAR[0]
            && bid < BollingerMiddle[0] && RsiBuffer[0] > RsiOversold && atr < volatilityThreshold
            && SMA20[0] > SMA200[0] && bid > SMA200[0])
        {
            Print(__FUNCTION__, " > BUY Signal...");
            trade.Buy(Lots, _Symbol, 0, ask - StopLossPoints * _Point, ask + TpPoints * _Point);
        }
    }

    // Loop para verificar as posições abertas e o Take Profit
    int pointsBuy = 0;
    int pointsSell = 0;
    for(int i = PositionsTotal() - 1; i >= 0; i--)
    {
        ulong posTicket = PositionGetTicket(i);
        if(PositionSelectByTicket(posTicket))
        {
            ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);

            if(pointsBuy > TpPoints)
            {
                // Fechar posições de compra
                if(posType == POSITION_TYPE_BUY)
                    trade.PositionClose(posTicket);
            }
            if(pointsSell > TpPoints)
            {
                // Fechar posições de venda
                if(posType == POSITION_TYPE_SELL)
                    trade.PositionClose(posTicket);
            }
        }
    }

    Comment("\nTenkan-sen: ", DoubleToString(Tenkan[0], 5),
            "\nKijun-sen: ", DoubleToString(Kijun[0], 5),
            "\nSenkou Span A: ", DoubleToString(SenkouSpanA[0], 5),
            "\nSenkou Span B: ", DoubleToString(SenkouSpanB[0], 5),
            "\nChikou: ", DoubleToString(Chikou[0], 5),
            "\nStochastic %K: ", DoubleToString(StochasticK[0], 5),
            "\nStochastic %D: ", DoubleToString(StochasticD[0], 5),
            "\nParabolic SAR: ", DoubleToString(SAR[0], 5),
            "\nBollinger Upper: ", DoubleToString(BollingerUpper[0], 5),
            "\nBollinger Middle: ", DoubleToString(BollingerMiddle[0], 5),
            "\nBollinger Lower: ", DoubleToString(BollingerLower[0], 5),
            "\nRSI: ", DoubleToString(RsiBuffer[0], 5),
            "\nATR: ", DoubleToString(AtrBuffer[0], 5),
            "\nSMA 200: ", DoubleToString(SMA200[0], 5),
            "\nSMA 20: ", DoubleToString(SMA20[0], 5),
            "\nPoints Buy: ", pointsBuy,
            "\nPoints Sell: ", pointsSell);
}