voglio creare un EA che sfrutti questo indicatore. bisogna impostare stop loss, take profit, trailing stop (con possibilità di annullarlo mettendo valore 0), e max ordini aperti
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

// Input parameters
extern int EmaPeriod = 10;
extern int BollingerPeriod = 17;
extern double BollingerDeviations = 2.0;
extern int RsiPeriod = 12;
extern int MacdFastEmaPeriod = 10;
extern int MacdSlowEmaPeriod = 19;
extern int MacdSignalSmoothing = 13;
extern double RsiUpperLevel = 80;
extern double RsiLowerLevel = 20;

// Buffer per i segnali di buy e sell
double BuySignalBuffer[];
double SellSignalBuffer[];

// Flag per tenere traccia se il segnale precedente era di buy o sell
bool prevBuySignal = false;
bool prevSellSignal = false;

// Identifica il codice simbolo di Wingdings per le frecce
enum arrow_codes {
    UP_ARROW = 233, // Freccia verde verso l’alto
    DOWN_ARROW = 234 // Freccia rossa verso il basso
};

// Inizializzazione dell’indicatore
int OnInit() {
    // Mappare i buffer dei segnali a colori specifici
    IndicatorBuffers(2);
    SetIndexBuffer(0, BuySignalBuffer);
    SetIndexBuffer(1, SellSignalBuffer);
    SetIndexArrow(0, UP_ARROW);
    SetIndexArrow(1, DOWN_ARROW);
    
    SetIndexStyle(0, DRAW_ARROW, 0, 2, clrLime); // Freccia verde per buy
    SetIndexStyle(1, DRAW_ARROW, 0, 2, clrRed); // Freccia rossa per sell
    
    ArraySetAsSeries(BuySignalBuffer, true);
    ArraySetAsSeries(SellSignalBuffer, true);
    
    return(INIT_SUCCEEDED);
}

// Funzione chiamata ad ogni tick
int OnCalculate(const int rates_total,
                const int prev_calculated,
                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[]) {
    // Begin calculation from enough bars for the bands and moving averages.
    int bars_required = MathMax(BollingerPeriod, EmaPeriod);
    int start = prev_calculated > bars_required ? prev_calculated - 1 : bars_required;
    
    for (int i = start; i < rates_total; i++) {
        double currentEma = iMA(NULL, 0, EmaPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
        double previousEma = iMA(NULL, 0, EmaPeriod, 0, MODE_EMA, PRICE_CLOSE, i + 2);
        double middleBand = iBands(NULL, 0, BollingerPeriod, BollingerDeviations, 0, PRICE_CLOSE, MODE_MAIN, i);
        
        // Acquiring MACD current and signal values indirectly
        double MACD = iMACD(NULL, 0, MacdFastEmaPeriod, MacdSlowEmaPeriod, MacdSignalSmoothing, PRICE_CLOSE, MODE_MAIN, i);
        double MACDSignal = iMACD(NULL, 0, MacdFastEmaPeriod, MacdSlowEmaPeriod, MacdSignalSmoothing, PRICE_CLOSE, MODE_SIGNAL, i);
        
        double RsiValue = iRSI(NULL, 0, RsiPeriod, PRICE_CLOSE, i);
        
        // Buy condition
        if (currentEma > middleBand && previousEma < middleBand && MACD > MACDSignal && RsiValue > RsiLowerLevel && RsiValue < RsiUpperLevel) {
            if (!prevBuySignal) { // Solo se prima non c’era un segnale di buy
                prevBuySignal = true;
                BuySignalBuffer[i] = low[i] - 4 * _Point;
            }
        } else {
            prevBuySignal = false;
            BuySignalBuffer[i] = EMPTY_VALUE;
        }
        
        // Sell condition
        if (currentEma < middleBand && previousEma > middleBand && MACD < MACDSignal && RsiValue > RsiLowerLevel && RsiValue < RsiUpperLevel) {
            if (!prevSellSignal) { // Solo se prima non c’era un segnale di sell
                prevSellSignal = true;
                SellSignalBuffer[i] = high[i] + 4 * _Point;
            }
        } else {
            prevSellSignal = false;
            SellSignalBuffer[i] = EMPTY_VALUE;
        }
    }
    
    return(rates_total);
}