From c70c2f28ce138ebc3fcbe87120bc8aadc456585e Mon Sep 17 00:00:00 2001 From: pietro_giacobazzi Date: Sat, 13 Jun 2026 15:07:05 +0200 Subject: [PATCH] Fix compile errors: NeuralNet input param rename, Orchestrator refs to pointers, EVT_MaxAbsZ call, SYMBOL_MARGIN_INITIAL, remove unused var --- .../Experts/MultiAgentTest/Core/NeuralNet.mqh | 74 ++++++++-------- .../MultiAgentTest/Core/Orchestrator.mqh | 84 +++++++++---------- .../Experts/MultiAgentTest/MultiAgentTest.mq5 | 3 +- 3 files changed, 80 insertions(+), 81 deletions(-) diff --git a/MQL5/Experts/MultiAgentTest/Core/NeuralNet.mqh b/MQL5/Experts/MultiAgentTest/Core/NeuralNet.mqh index cf75b84..fdd82e0 100644 --- a/MQL5/Experts/MultiAgentTest/Core/NeuralNet.mqh +++ b/MQL5/Experts/MultiAgentTest/Core/NeuralNet.mqh @@ -255,50 +255,50 @@ public: m_lossCsvFn = ""; } - void ForwardPass(vector &input, vector &output, vector &h1Cache) { - h1Cache.Resize(m_hidden); - for(int i = 0; i < m_hidden; i++) { - double sum = m_b1[i]; - for(int j = 0; j < m_inputs; j++) - sum += input[j] * m_W1[j][i]; - h1Cache[i] = ReLU(sum); - } - // BatchNorm inferenza: normalizza con running stats (NeuroBook §6.3) - ApplyBN(h1Cache); - // Dropout scaling in inferenza: scale = 1 - dropoutRate (NeuroBook §6.2) - if(m_dropoutRate > 0) { - for(int i = 0; i < h1Cache.Size(); i++) - h1Cache[i] *= (1.0 - m_dropoutRate); - } + void ForwardPass(vector &inp, vector &output, vector &h1Cache) { + h1Cache.Resize(m_hidden); + for(int i = 0; i < m_hidden; i++) { + double sum = m_b1[i]; + for(int j = 0; j < m_inputs; j++) + sum += inp[j] * m_W1[j][i]; + h1Cache[i] = ReLU(sum); + } + // BatchNorm inferenza: normalizza con running stats (NeuroBook §6.3) + ApplyBN(h1Cache); + // Dropout scaling in inferenza: scale = 1 - dropoutRate (NeuroBook §6.2) + if(m_dropoutRate > 0) { + for(int i = 0; i < h1Cache.Size(); i++) + h1Cache[i] *= (1.0 - m_dropoutRate); + } - output.Resize(m_outputs); - for(int i = 0; i < m_outputs; i++) { - double sum = m_b2[i]; - for(int j = 0; j < m_hidden; j++) - sum += h1Cache[j] * m_W2[j][i]; - output[i] = sum; - } - Softmax(output); - } + output.Resize(m_outputs); + for(int i = 0; i < m_outputs; i++) { + double sum = m_b2[i]; + for(int j = 0; j < m_hidden; j++) + sum += h1Cache[j] * m_W2[j][i]; + output[i] = sum; + } + Softmax(output); + } - void Forward(vector &input, vector &output) { - vector h1Cache; - ForwardPass(input, output, h1Cache); - } + void Forward(vector &inp, vector &output) { + vector h1Cache; + ForwardPass(inp, output, h1Cache); + } - double TrainSample(vector &input, vector &target, double lr, double weight = 1.0) { + double TrainSample(vector &inp, vector &target, double lr, double weight = 1.0) { if(!m_initialized) return -1.0; // ── Forward ── // Layer 1: W1*x + b1 → z1 → ReLU → h1_raw → Dropout → h1_drop → BN → h1_norm vector z1(m_hidden); vector h1_raw(m_hidden); - for(int i = 0; i < m_hidden; i++) { - z1[i] = m_b1[i]; - for(int j = 0; j < m_inputs; j++) - z1[i] += input[j] * m_W1[j][i]; - h1_raw[i] = ReLU(z1[i]); - } +for(int i = 0; i < m_hidden; i++) { + z1[i] = m_b1[i]; + for(int j = 0; j < m_inputs; j++) + z1[i] += inp[j] * m_W1[j][i]; + h1_raw[i] = ReLU(z1[i]); + } // Dropout (NeuroBook §6.2): salva in m_dropoutMask, applica a h1_drop vector h1_drop(m_hidden); @@ -390,11 +390,11 @@ public: for(int i = 0; i < m_hidden; i++) dL_dz1[i] = dL_dh1_drop[i] * ReLUDeriv(z1[i]); - // dL/dW1 = input ⊗ dL/dz1 + // dL/dW1 = inp ⊗ dL/dz1 matrix dL_dW1(m_inputs, m_hidden); for(int i = 0; i < m_inputs; i++) for(int j = 0; j < m_hidden; j++) - dL_dW1[i][j] = input[i] * dL_dz1[j]; + dL_dW1[i][j] = inp[i] * dL_dz1[j]; // dL/db1 = dL/dz1 vector dL_db1(m_hidden); diff --git a/MQL5/Experts/MultiAgentTest/Core/Orchestrator.mqh b/MQL5/Experts/MultiAgentTest/Core/Orchestrator.mqh index 43e5eb7..38585bb 100644 --- a/MQL5/Experts/MultiAgentTest/Core/Orchestrator.mqh +++ b/MQL5/Experts/MultiAgentTest/Core/Orchestrator.mqh @@ -424,7 +424,7 @@ public: Print("ERROR: slot non disponibile nonostante capacity expansion"); return -1; } - TrackedTrade &t = openTrades[idx]; +TrackedTrade *t = &openTrades[idx]; t.ticket = ticket; t.entryPrice = price; t.entryATR = MathMax(atr, 1e-10); @@ -468,15 +468,15 @@ public: AddTrade(ticket, price, atr, combinedZ, combinedZ > 0); } - void OnTradeClose(int ticket, double closePrice) { - // Trova il trade nell'array - int idx = -1; - for(int i=0; i t.highestPrice) t.highestPrice = high; - if(low < t.lowestPrice) t.lowestPrice = low; - t.barsHeld++; - } - } +// Aggiorna MAE/MFE per tutti i trade aperti (chiamato ogni barra) + void UpdateOpenTrades(double high, double low) { + for(int i=0; i t.highestPrice) t.highestPrice = high; + if(low < t.lowestPrice) t.lowestPrice = low; + t.barsHeld++; + } + } - // Trailing stop: sposta SL dopo che il profitto supera la soglia - void TrailStops() { - for(int i=0; i trigger) { - double offset = AdaptiveTrailOffset(); - double newSL; - if(t.isBuy) { - newSL = t.highestPrice - offset * t.entryATR; - if(newSL > t.slPrice) t.slPrice = newSL; - } else { - newSL = t.lowestPrice + offset * t.entryATR; - if(newSL < t.slPrice) t.slPrice = newSL; - } - } - } - } + double trigger = AdaptiveTrailTrigger(); + if(profitATR > trigger) { + double offset = AdaptiveTrailOffset(); + double newSL; + if(t.isBuy) { + newSL = t.highestPrice - offset * t.entryATR; + if(newSL > t.slPrice) t.slPrice = newSL; + } else { + newSL = t.lowestPrice + offset * t.entryATR; + if(newSL < t.slPrice) t.slPrice = newSL; + } + } + } + } // Trade da chiudere per inversione di segnale (ritorna array di ticket) void GetTradesToClose(int &closeTickets[], double currentZ, double minZ) { @@ -1253,7 +1253,7 @@ public: FileWriteString(fh, "CorrMinSamples," + (string)corrMinSamples + "\r\n"); FileWriteString(fh, "WeightMin," + StringFormat("%.6f", weightMin) + "\r\n"); FileWriteString(fh, "WeightAlpha," + StringFormat("%.6f", weightAlpha) + "\r\n"); - double evtMaxAbsZ = EVT_MaxAbsZ(MathMax(agentCount * 2, 2)); + double evtMaxAbsZ = EVT_MaxAbsZ(); FileWriteString(fh, "EVT_MaxAbsZ," + StringFormat("%.4f", evtMaxAbsZ) + "\r\n"); FileWriteString(fh, "\r\n"); diff --git a/MQL5/Experts/MultiAgentTest/MultiAgentTest.mq5 b/MQL5/Experts/MultiAgentTest/MultiAgentTest.mq5 index a4409de..3212f6c 100644 --- a/MQL5/Experts/MultiAgentTest/MultiAgentTest.mq5 +++ b/MQL5/Experts/MultiAgentTest/MultiAgentTest.mq5 @@ -216,7 +216,6 @@ void PrintNeuralStats() { Print(" " + orchestrator.NeuralInfo()); // Feature importanza approssimata: media |W1| per input if(orchestrator.IsNeuralReady()) { - string lines[8]; // Non possiamo accedere direttamente ai pesi Print(" (vedi CSV per loss history e training samples)"); } @@ -349,7 +348,7 @@ void ManagePositions(const MarketData &data, const FinalSignal &fs) { // Solo il margine libero limita i trade double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE); - double marginReq = lot * SymbolInfoDouble(sym, SYMBOL_MARGIN_REQUIRED); + double marginReq = lot * SymbolInfoDouble(sym, SYMBOL_MARGIN_INITIAL); if(marginReq >= freeMargin && freeMargin > 0) { Print("Margine insufficiente: lot=", lot, " free=", freeMargin, " req=", marginReq); return; // Skip — solo il margine blocca i trade