Loading error - failed [539]

 

Buongiorno a tutti,

ho creato un indicatore (non è il primo che creo), ma al momento del load mi da il seguente errore:

2025.12.22 10:45:32.233    Custom Indicator    loading of Direzionalita (SP500.s,M1) from C:\Users\matte\AppData\Roaming\MetaQuotes\Terminal\406D9FF3E9C55C279FF8C66020886D20\MQL5\Indicators\Direzionalita.ex5 failed [539]


Non riesco a capire il problema, Metaeditor non mi da alcun tipo di errore nel codice. Che cosa posso fare? Ho già provato a disinstallare e reinstallare una nuova versione, ma niente.

//+------------------------------------------------------------------+
//|                                                Direzionalita.mq5 |
//|                                                        MatteoA80 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "MatteoA80"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0



// ===================== INPUT ======================
input bool   EnableLateralFilter = true;

// --- Indicatori base
input int    ADX_Period          = 14;
input double ADX_Threshold       = 20.0;   // soglia per "lateralità" (ADX basso)

input int    BB_Period           = 20;
input double BB_Deviation        = 2.0;
input double BB_MinWidth_Points  = 800;    // width minima (in points) per considerare "non stretto"

input int    EMA_Period          = 50;
input int    EMA_Slope_Bars      = 5;      // quante barre indietro per slope (trend forte)
input int    EMA_Flat_Bars       = 10;     // usato nella lateralità (EMA "piatta")
input double EMA_Flat_Points     = 300;    // differenza max in points per EMA "piatta"

input int    ATR_Period          = 14;

// --- HTF (opzionale)
input bool            EnableHTF_Filter = true;
input ENUM_TIMEFRAMES HTF_Period       = PERIOD_H1;

// --- Lateralità “valida”
input int    Lateral_MinBars     = 5;      // quante barre (con decadenza) per "confermare"
input int    Lateral_ConfirmBars = 3;      // conferma hard minima (extra)

// --- UI
input bool   ShowOverlay         = true;
input int    PanelX              = 20;     // sinistra
input int    PanelY              = 20;
input int    LineGap             = 16;
input int    FontSize            = 10;

// ===================== NOMI OGGETTI ======================
#define DL_L1 "DIR_LINE_1"
#define DL_L2 "DIR_LINE_2"
#define DL_L3 "DIR_LINE_3"
#define DL_L4 "DIR_LINE_4"
#define DL_L5 "DIR_LINE_5"

// ===================== HANDLE ======================
int hADX_LTF = INVALID_HANDLE;
int hBB_LTF  = INVALID_HANDLE;
int hEMA_LTF = INVALID_HANDLE;
int hATR_LTF = INVALID_HANDLE;
int hADX_HTF = INVALID_HANDLE;

// ===================== STATO (CACHE) ======================
static datetime g_lastBarTime = 0;

static double g_lastADX      = 0.0;
static double g_lastBBWidth  = 0.0;

static bool   g_strongBull   = false;
static bool   g_strongBear   = false;

static bool   g_isLateralRaw = false;   // lateralità “istantanea”
static int    g_lateralBars  = 0;       // conteggio con decadenza
static bool   g_isLateral    = false;   // lateralità “validata”


//+------------------------------------------------------------------+
//| Helper: crea label se non esiste                                 |
//+------------------------------------------------------------------+
void EnsureLabel(const string name, int idx)
{
   if(ObjectFind(0, name) >= 0) return;

   ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
   ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE, PanelX);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE, PanelY + idx*LineGap);
   ObjectSetInteger(0, name, OBJPROP_FONTSIZE, FontSize);
   ObjectSetString (0, name, OBJPROP_FONT, "Calibri");
   ObjectSetInteger(0, name, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, name, OBJPROP_BACK, false);
}

//+------------------------------------------------------------------+
//| Helper: set testo e colore                                       |
//+------------------------------------------------------------------+
void SetLabel(const string name, const string text, color c, bool hide=false)
{
   if(ObjectFind(0, name) < 0) return;
   ObjectSetInteger(0, name, OBJPROP_COLOR, c);
   ObjectSetString (0, name, OBJPROP_TEXT, text);
   ObjectSetInteger(0, name, OBJPROP_HIDDEN, hide);
}

//+------------------------------------------------------------------+
//| Core: calcolo lateralità (score 0..4)                             |
//+------------------------------------------------------------------+
int ComputeLateralScore()
{
   int score = 0;

   // --- ADX basso
   double adxBuf[1];
   if(CopyBuffer(hADX_LTF, 0, 0, 1, adxBuf) > 0)
   {
      g_lastADX = adxBuf[0];
      if(g_lastADX < ADX_Threshold) score++;
   }

   // --- Bollinger width stretto
   double bbUp[1], bbLow[1];
   if(CopyBuffer(hBB_LTF, 0, 0, 1, bbUp) > 0 &&
      CopyBuffer(hBB_LTF, 2, 0, 1, bbLow) > 0)
   {
      g_lastBBWidth = (bbUp[0] - bbLow[0]) / _Point;
      if(g_lastBBWidth < BB_MinWidth_Points) score++;
   }

   // --- EMA piatta
   double emaNow[1], emaPast[1];
   if(CopyBuffer(hEMA_LTF, 0, 0, 1, emaNow) > 0 &&
      CopyBuffer(hEMA_LTF, 0, EMA_Flat_Bars, 1, emaPast) > 0)
   {
      if(MathAbs(emaNow[0] - emaPast[0]) / _Point < EMA_Flat_Points)
         score++;
   }

   // --- ATR non in espansione (semplice)
   double atrNow[1], atrPrev[1];
   if(CopyBuffer(hATR_LTF, 0, 0, 1, atrNow) > 0 &&
      CopyBuffer(hATR_LTF, 0, 1, 1, atrPrev) > 0)
   {
      if(atrNow[0] <= atrPrev[0]) score++;
   }

   return score;
}

//+------------------------------------------------------------------+
//| Core: trend forte bull/bear                                       |
//+------------------------------------------------------------------+
void ComputeStrongTrend()
{
   g_strongBull = false;
   g_strongBear = false;

   // ADX forte
   double adxBuf[1];
   if(CopyBuffer(hADX_LTF, 0, 0, 1, adxBuf) <= 0) return;
   double adx = adxBuf[0];
   bool adxStrong = (adx >= 25.0);

   // EMA slope
   double emaNow[1], emaPast[1];
   if(CopyBuffer(hEMA_LTF, 0, 0, 1, emaNow) <= 0 ||
      CopyBuffer(hEMA_LTF, 0, EMA_Slope_Bars, 1, emaPast) <= 0)
      return;

   bool emaUp   = (emaNow[0] > emaPast[0]);
   bool emaDown = (emaNow[0] < emaPast[0]);

   // Prezzo vs EMA
   double cls = iClose(_Symbol, _Period, 0);

   // BB width “ampio” = mercato in espansione
   double bbUp[1], bbLow[1];
   if(CopyBuffer(hBB_LTF, 0, 0, 1, bbUp) <= 0 ||
      CopyBuffer(hBB_LTF, 2, 0, 1, bbLow) <= 0)
      return;

   double bbWidth = (bbUp[0] - bbLow[0]) / _Point;
   bool bbExpanded = (bbWidth >= BB_MinWidth_Points * 1.2);

   if(adxStrong && emaUp   && cls > emaNow[0] && bbExpanded) g_strongBull = true;
   if(adxStrong && emaDown && cls < emaNow[0] && bbExpanded) g_strongBear = true;
}

//+------------------------------------------------------------------+
//| UpdateMarketState: SOLO a nuova barra                             |
//+------------------------------------------------------------------+
void UpdateMarketState(const datetime barTime0)
{
   // 1) Trend forte (bull/bear)
   ComputeStrongTrend();

   // 2) Lateralità LTF (score)
   int score = ComputeLateralScore();
   bool lateralLTF = (score >= 3);

   // 3) Lateralità HTF (solo ADX)
   bool lateralHTF = true;
   if(EnableHTF_Filter && hADX_HTF != INVALID_HANDLE)
   {
      double htfAdx[1];
      if(CopyBuffer(hADX_HTF, 0, 0, 1, htfAdx) > 0)
         lateralHTF = (htfAdx[0] < ADX_Threshold);
   }

   // 4) Lateralità raw (se trend forte attivo, NON la considero lateralità)
   bool lateralNow = (lateralLTF && lateralHTF && !g_strongBull && !g_strongBear);
   g_isLateralRaw = lateralNow;

   // 5) Conteggio con decadenza (patch “non reset secco”)
   if(lateralNow)
      g_lateralBars++;
   else
      g_lateralBars = MathMax(0, g_lateralBars - 1);

   // 6) Stato validato (serve “storia”)
   g_isLateral = (g_lateralBars >= Lateral_MinBars && g_lateralBars >= Lateral_ConfirmBars);

   // salva l’ultima barra
   g_lastBarTime = barTime0;
}

//+------------------------------------------------------------------+
//| UI                                                                |
//+------------------------------------------------------------------+
void UpdateUI()
{
   if(!ShowOverlay)
   {
      // se overlay OFF, nascondo tutto
      SetLabel(DL_L1, "", clrWhite, true);
      SetLabel(DL_L2, "", clrWhite, true);
      SetLabel(DL_L3, "", clrWhite, true);
      SetLabel(DL_L4, "", clrWhite, true);
      SetLabel(DL_L5, "", clrWhite, true);
      return;
   }

   // Colori e testo stato
   string stateTxt = "TREND NON FORTE";
   color  stateCol = clrSilver;

   if(g_isLateral)
   {
      stateTxt = "⚠ LATERALITÀ ATTIVA";
      stateCol = clrRed;
   }
   else if(g_strongBull)
   {
      stateTxt = "✅ STRONG BULL TREND";
      stateCol = clrLime;
   }
   else if(g_strongBear)
   {
      stateTxt = "✅ STRONG BEAR TREND";
      stateCol = clrOrangeRed;
   }

   SetLabel(DL_L1, stateTxt, stateCol, false);
   SetLabel(DL_L2, "TF: " + EnumToString(_Period) + " | HTF: " + EnumToString(HTF_Period), clrWhite, false);
   SetLabel(DL_L3, "Barre lateralità (decay): " + (string)g_lateralBars, clrWhite, false);
   SetLabel(DL_L4, "ADX: " + DoubleToString(g_lastADX, 1) + " | BB: " + DoubleToString(g_lastBBWidth, 0), clrWhite, false);
   SetLabel(DL_L5, "Raw lateral: " + (g_isLateralRaw ? "true" : "false"), clrDarkGray, false);
}

//+------------------------------------------------------------------+
//| INIT                                                             |
//+------------------------------------------------------------------+
int OnInit()
{
   hADX_LTF = iADX(_Symbol, _Period, ADX_Period);
   hBB_LTF  = iBands(_Symbol, _Period, BB_Period, 0, BB_Deviation, PRICE_CLOSE);
   hEMA_LTF = iMA(_Symbol, _Period, EMA_Period, 0, MODE_EMA, PRICE_CLOSE);
   hATR_LTF = iATR(_Symbol, _Period, ATR_Period);

   if(EnableHTF_Filter)
      hADX_HTF = iADX(_Symbol, HTF_Period, ADX_Period);

   // ⚠️ NON fallire qui
   Print("Direzionalità: OnInit completato. Attendo dati...");

   EnsureLabel(DL_L1, 0);
   EnsureLabel(DL_L2, 1);
   EnsureLabel(DL_L3, 2);
   EnsureLabel(DL_L4, 3);
   EnsureLabel(DL_L5, 4);

   g_lastBarTime = 0;

   return INIT_SUCCEEDED;
}


//+------------------------------------------------------------------+
//| DEINIT                                                           |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   if(hADX_LTF != INVALID_HANDLE) IndicatorRelease(hADX_LTF);
   if(hBB_LTF  != INVALID_HANDLE) IndicatorRelease(hBB_LTF);
   if(hEMA_LTF != INVALID_HANDLE) IndicatorRelease(hEMA_LTF);
   if(hATR_LTF != INVALID_HANDLE) IndicatorRelease(hATR_LTF);
   if(hADX_HTF != INVALID_HANDLE) IndicatorRelease(hADX_HTF);

   ObjectDelete(0, DL_L1);
   ObjectDelete(0, DL_L2);
   ObjectDelete(0, DL_L3);
   ObjectDelete(0, DL_L4);
   ObjectDelete(0, DL_L5);
}

//+------------------------------------------------------------------+
//| CALCULATE                                                        |
//+------------------------------------------------------------------+
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[])
{
   if(hADX_LTF == INVALID_HANDLE || hBB_LTF == INVALID_HANDLE ||
   hEMA_LTF == INVALID_HANDLE || hATR_LTF == INVALID_HANDLE)
{
   SetLabel(DL_L1, "⏳ Attendo dati indicatori...", clrGray);
   return rates_total;
}
   
   
   
   if(!EnableLateralFilter)
   {
      UpdateUI();
      return rates_total;
   }

   // safety: serve un minimo di storia
   if(rates_total < 100)
      return rates_total;

   // SOLO a nuova barra
   if(time[0] != g_lastBarTime)
   {
      UpdateMarketState(time[0]);
      UpdateUI();
      ChartRedraw(0);
   }

   return rates_total;
}




grazie

saluti

 

Problema noto con l'ultima beta 5488.

Dovresti usare la versione ufficiale 5430, a meno che tu non voglia essere un beta-tester.

Forum sul trading, sistemi di trading automatizzati e test di strategie di trading

Organizza i nostri forum

Alain Verleyen , 26.11.2025 16:50

Ho creato un archivio su Telegram per fornire gli ultimi file di rilascio ufficiali.

https://t.me/MT5Exe/6


 
Alain Verleyen #:

Problema noto con l'ultima beta 5488.

Dovresti usare la versione ufficiale 5430, a meno che tu non voglia essere un beta-tester.


grazie Alain, ma al momento della reinstallazione non mi ha chiesto se voglio la versione stabile o la versione beta... ti confermo che ho la versione 5488
 
All about MT5 updates.
All about MT5 updates.
  • 2025.12.16
  • www.mql5.com
This topic will be used to bring together all information about MT5 updates process. This is NOT for chitchat...