Fix compile errors: NeuralNet input param rename, Orchestrator refs to pointers, EVT_MaxAbsZ call, SYMBOL_MARGIN_INITIAL, remove unused var

This commit is contained in:
pietro_giacobazzi
2026-06-13 15:07:05 +02:00
parent 67c8485373
commit c70c2f28ce
3 changed files with 80 additions and 81 deletions
+37 -37
View File
@@ -255,50 +255,50 @@ public:
m_lossCsvFn = ""; m_lossCsvFn = "";
} }
void ForwardPass(vector &input, vector &output, vector &h1Cache) { void ForwardPass(vector &inp, vector &output, vector &h1Cache) {
h1Cache.Resize(m_hidden); h1Cache.Resize(m_hidden);
for(int i = 0; i < m_hidden; i++) { for(int i = 0; i < m_hidden; i++) {
double sum = m_b1[i]; double sum = m_b1[i];
for(int j = 0; j < m_inputs; j++) for(int j = 0; j < m_inputs; j++)
sum += input[j] * m_W1[j][i]; sum += inp[j] * m_W1[j][i];
h1Cache[i] = ReLU(sum); h1Cache[i] = ReLU(sum);
} }
// BatchNorm inferenza: normalizza con running stats (NeuroBook §6.3) // BatchNorm inferenza: normalizza con running stats (NeuroBook §6.3)
ApplyBN(h1Cache); ApplyBN(h1Cache);
// Dropout scaling in inferenza: scale = 1 - dropoutRate (NeuroBook §6.2) // Dropout scaling in inferenza: scale = 1 - dropoutRate (NeuroBook §6.2)
if(m_dropoutRate > 0) { if(m_dropoutRate > 0) {
for(int i = 0; i < h1Cache.Size(); i++) for(int i = 0; i < h1Cache.Size(); i++)
h1Cache[i] *= (1.0 - m_dropoutRate); h1Cache[i] *= (1.0 - m_dropoutRate);
} }
output.Resize(m_outputs); output.Resize(m_outputs);
for(int i = 0; i < m_outputs; i++) { for(int i = 0; i < m_outputs; i++) {
double sum = m_b2[i]; double sum = m_b2[i];
for(int j = 0; j < m_hidden; j++) for(int j = 0; j < m_hidden; j++)
sum += h1Cache[j] * m_W2[j][i]; sum += h1Cache[j] * m_W2[j][i];
output[i] = sum; output[i] = sum;
} }
Softmax(output); Softmax(output);
} }
void Forward(vector &input, vector &output) { void Forward(vector &inp, vector &output) {
vector h1Cache; vector h1Cache;
ForwardPass(input, output, 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; if(!m_initialized) return -1.0;
// ── Forward ── // ── Forward ──
// Layer 1: W1*x + b1 → z1 → ReLU → h1_raw → Dropout → h1_drop → BN → h1_norm // Layer 1: W1*x + b1 → z1 → ReLU → h1_raw → Dropout → h1_drop → BN → h1_norm
vector z1(m_hidden); vector z1(m_hidden);
vector h1_raw(m_hidden); vector h1_raw(m_hidden);
for(int i = 0; i < m_hidden; i++) { for(int i = 0; i < m_hidden; i++) {
z1[i] = m_b1[i]; z1[i] = m_b1[i];
for(int j = 0; j < m_inputs; j++) for(int j = 0; j < m_inputs; j++)
z1[i] += input[j] * m_W1[j][i]; z1[i] += inp[j] * m_W1[j][i];
h1_raw[i] = ReLU(z1[i]); h1_raw[i] = ReLU(z1[i]);
} }
// Dropout (NeuroBook §6.2): salva in m_dropoutMask, applica a h1_drop // Dropout (NeuroBook §6.2): salva in m_dropoutMask, applica a h1_drop
vector h1_drop(m_hidden); vector h1_drop(m_hidden);
@@ -390,11 +390,11 @@ public:
for(int i = 0; i < m_hidden; i++) for(int i = 0; i < m_hidden; i++)
dL_dz1[i] = dL_dh1_drop[i] * ReLUDeriv(z1[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); matrix dL_dW1(m_inputs, m_hidden);
for(int i = 0; i < m_inputs; i++) for(int i = 0; i < m_inputs; i++)
for(int j = 0; j < m_hidden; j++) 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 // dL/db1 = dL/dz1
vector dL_db1(m_hidden); vector dL_db1(m_hidden);
@@ -424,7 +424,7 @@ public:
Print("ERROR: slot non disponibile nonostante capacity expansion"); Print("ERROR: slot non disponibile nonostante capacity expansion");
return -1; return -1;
} }
TrackedTrade &t = openTrades[idx]; TrackedTrade *t = &openTrades[idx];
t.ticket = ticket; t.ticket = ticket;
t.entryPrice = price; t.entryPrice = price;
t.entryATR = MathMax(atr, 1e-10); t.entryATR = MathMax(atr, 1e-10);
@@ -468,15 +468,15 @@ public:
AddTrade(ticket, price, atr, combinedZ, combinedZ > 0); AddTrade(ticket, price, atr, combinedZ, combinedZ > 0);
} }
void OnTradeClose(int ticket, double closePrice) { void OnTradeClose(int ticket, double closePrice) {
// Trova il trade nell'array // Trova il trade nell'array
int idx = -1; int idx = -1;
for(int i=0; i<maxOpenTrades; i++) { for(int i=0; i<maxOpenTrades; i++) {
if(openTrades[i].active && openTrades[i].ticket == ticket) { idx = i; break; } if(openTrades[i].active && openTrades[i].ticket == ticket) { idx = i; break; }
} }
if(idx < 0) return; if(idx < 0) return;
TrackedTrade &t = openTrades[idx]; TrackedTrade *t = &openTrades[idx];
// Calcola MAE/MFE finali // Calcola MAE/MFE finali
if(t.isBuy) { if(t.isBuy) {
@@ -587,41 +587,41 @@ public:
return -1; return -1;
} }
// Aggiorna MAE/MFE per tutti i trade aperti (chiamato ogni barra) // Aggiorna MAE/MFE per tutti i trade aperti (chiamato ogni barra)
void UpdateOpenTrades(double high, double low) { void UpdateOpenTrades(double high, double low) {
for(int i=0; i<maxOpenTrades; i++) { for(int i=0; i<maxOpenTrades; i++) {
if(!openTrades[i].active) continue; if(!openTrades[i].active) continue;
TrackedTrade &t = openTrades[i]; TrackedTrade *t = &openTrades[i];
if(high > t.highestPrice) t.highestPrice = high; if(high > t.highestPrice) t.highestPrice = high;
if(low < t.lowestPrice) t.lowestPrice = low; if(low < t.lowestPrice) t.lowestPrice = low;
t.barsHeld++; t.barsHeld++;
} }
} }
// Trailing stop: sposta SL dopo che il profitto supera la soglia // Trailing stop: sposta SL dopo che il profitto supera la soglia
void TrailStops() { void TrailStops() {
for(int i=0; i<maxOpenTrades; i++) { for(int i=0; i<maxOpenTrades; i++) {
if(!openTrades[i].active) continue; if(!openTrades[i].active) continue;
TrackedTrade &t = openTrades[i]; TrackedTrade *t = &openTrades[i];
double profitATR = t.isBuy double profitATR = t.isBuy
? (t.highestPrice - t.entryPrice) / t.entryATR ? (t.highestPrice - t.entryPrice) / t.entryATR
: (t.entryPrice - t.lowestPrice) / t.entryATR; : (t.entryPrice - t.lowestPrice) / t.entryATR;
double trigger = AdaptiveTrailTrigger(); double trigger = AdaptiveTrailTrigger();
if(profitATR > trigger) { if(profitATR > trigger) {
double offset = AdaptiveTrailOffset(); double offset = AdaptiveTrailOffset();
double newSL; double newSL;
if(t.isBuy) { if(t.isBuy) {
newSL = t.highestPrice - offset * t.entryATR; newSL = t.highestPrice - offset * t.entryATR;
if(newSL > t.slPrice) t.slPrice = newSL; if(newSL > t.slPrice) t.slPrice = newSL;
} else { } else {
newSL = t.lowestPrice + offset * t.entryATR; newSL = t.lowestPrice + offset * t.entryATR;
if(newSL < t.slPrice) t.slPrice = newSL; if(newSL < t.slPrice) t.slPrice = newSL;
} }
} }
} }
} }
// Trade da chiudere per inversione di segnale (ritorna array di ticket) // Trade da chiudere per inversione di segnale (ritorna array di ticket)
void GetTradesToClose(int &closeTickets[], double currentZ, double minZ) { void GetTradesToClose(int &closeTickets[], double currentZ, double minZ) {
@@ -1253,7 +1253,7 @@ public:
FileWriteString(fh, "CorrMinSamples," + (string)corrMinSamples + "\r\n"); FileWriteString(fh, "CorrMinSamples," + (string)corrMinSamples + "\r\n");
FileWriteString(fh, "WeightMin," + StringFormat("%.6f", weightMin) + "\r\n"); FileWriteString(fh, "WeightMin," + StringFormat("%.6f", weightMin) + "\r\n");
FileWriteString(fh, "WeightAlpha," + StringFormat("%.6f", weightAlpha) + "\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, "EVT_MaxAbsZ," + StringFormat("%.4f", evtMaxAbsZ) + "\r\n");
FileWriteString(fh, "\r\n"); FileWriteString(fh, "\r\n");
@@ -216,7 +216,6 @@ void PrintNeuralStats() {
Print(" " + orchestrator.NeuralInfo()); Print(" " + orchestrator.NeuralInfo());
// Feature importanza approssimata: media |W1| per input // Feature importanza approssimata: media |W1| per input
if(orchestrator.IsNeuralReady()) { if(orchestrator.IsNeuralReady()) {
string lines[8];
// Non possiamo accedere direttamente ai pesi // Non possiamo accedere direttamente ai pesi
Print(" (vedi CSV per loss history e training samples)"); 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 // Solo il margine libero limita i trade
double freeMargin = AccountInfoDouble(ACCOUNT_MARGIN_FREE); 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) { if(marginReq >= freeMargin && freeMargin > 0) {
Print("Margine insufficiente: lot=", lot, " free=", freeMargin, " req=", marginReq); Print("Margine insufficiente: lot=", lot, " free=", freeMargin, " req=", marginReq);
return; // Skip — solo il margine blocca i trade return; // Skip — solo il margine blocca i trade