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 = "";
}
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);
@@ -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<maxOpenTrades; i++) {
if(openTrades[i].active && openTrades[i].ticket == ticket) { idx = i; break; }
}
if(idx < 0) return;
void OnTradeClose(int ticket, double closePrice) {
// Trova il trade nell'array
int idx = -1;
for(int i=0; i<maxOpenTrades; i++) {
if(openTrades[i].active && openTrades[i].ticket == ticket) { idx = i; break; }
}
if(idx < 0) return;
TrackedTrade &t = openTrades[idx];
TrackedTrade *t = &openTrades[idx];
// Calcola MAE/MFE finali
if(t.isBuy) {
@@ -587,41 +587,41 @@ public:
return -1;
}
// Aggiorna MAE/MFE per tutti i trade aperti (chiamato ogni barra)
void UpdateOpenTrades(double high, double low) {
for(int i=0; i<maxOpenTrades; i++) {
if(!openTrades[i].active) continue;
TrackedTrade &t = openTrades[i];
if(high > 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<maxOpenTrades; i++) {
if(!openTrades[i].active) continue;
TrackedTrade *t = &openTrades[i];
if(high > 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<maxOpenTrades; i++) {
if(!openTrades[i].active) continue;
TrackedTrade &t = openTrades[i];
// Trailing stop: sposta SL dopo che il profitto supera la soglia
void TrailStops() {
for(int i=0; i<maxOpenTrades; i++) {
if(!openTrades[i].active) continue;
TrackedTrade *t = &openTrades[i];
double profitATR = t.isBuy
? (t.highestPrice - t.entryPrice) / t.entryATR
: (t.entryPrice - t.lowestPrice) / t.entryATR;
double profitATR = t.isBuy
? (t.highestPrice - t.entryPrice) / t.entryATR
: (t.entryPrice - t.lowestPrice) / t.entryATR;
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;
}
}
}
}
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");
@@ -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