Warrior_EA/Signals/SignalLSTM.mqh
AnimateDread d9a4f91717 refactor: compose topologies from named stages; drop dead code
DRY - topology construction
---------------------------
CSignalCONV and CSignalHYBRID each built the Conv+Pool front-end from scratch;
CSignalLSTM and CSignalHYBRID each built the LSTM stage from scratch. The
duplicates had already drifted: HYBRID guarded the LSTM step with
MathMax(1, historyBars/2), CSignalLSTM divided unguarded, so a historyBars of 1
gave two different steps for what is documented as the same layer.

Extracted AddConvPoolStage() and AddLstmStage() onto CExpertSignalAIBase. The
three overrides are now compositions:

  CONV   = AddConvPoolStage
  LSTM   = AddLstmStage
  HYBRID = AddConvPoolStage && AddLstmStage

HYBRID's "matches the standalone CONV front-end exactly, then adds LSTM" is
enforced by construction instead of by comment. Took the guarded step for both.

Also fixed a descriptor leak the duplicates shared: on a failed topology.Add()
the CLayerDescription was neither owned by the array nor deleted.

Dead code
---------
- CNet::SaveCheckpoint / CNet::LoadCheckpoint (123 lines). Superseded by the
  in-memory CaptureWeights/RestoreWeights pair; Network.mqh:1312 already said so
  ("This replaces the file-based SaveCheckpoint/LoadCheckpoint"). Zero call
  sites - every remaining mention was a comment. The five comments that
  referenced them have been reworded rather than left dangling.

- CExpertSignalCustom::CheckForDuplicateTrade / FindLastTradeIndex /
  UpdateTradeStatusAndExit: declared, never defined anywhere, never called.
  They only made it look as though duplicate-trade detection existed.

Compiles 0 errors, 0 warnings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-29 00:38:05 -04:00

61 lines
3.3 KiB
MQL5

//+------------------------------------------------------------------+
//| Warrior_EA |
//| AnimateDread |
//| |
//+------------------------------------------------------------------+
#include "..\Expert\ExpertSignalAIBase.mqh"
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class |
//| Title=Signals of indicator 'LSTM AI' |
//| Type=SignalAdvanced |
//| Name=LSTM AI |
//| ShortName=LSTM |
//| Class=CSignalLSTM |
//| Page=signal_lstm |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CSignalLSTM. |
//| Purpose: Class of generator of trade signals based on |
//| the 'LSTM AI' indicator. |
//| Is derived from the CExpertSignalAIBase class. |
//| Only the network topology differs from the other AI signals: an |
//| input layer feeds a single LSTM layer before the common tapering |
//| hidden-layer stack (see AddCustomLayers). |
//+------------------------------------------------------------------+
class CSignalLSTM : public CExpertSignalAIBase
{
protected:
virtual bool AddCustomLayers(CArrayObj *topology) override;
//--- keep the tapering Dense stack TANH-bounded, matching the LSTM layer's own bounded
//--- output, instead of the base class's default PRELU (see the base declaration's comment)
virtual ENUM_ACTIVATION HiddenLayerActivation(void) override { return TANH; }
public:
CSignalLSTM(void);
//--- method of creating the indicator and timeseries
virtual bool InitIndicators(CIndicators *indicators) override;
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CSignalLSTM::CSignalLSTM(void)
{
SetIdentity("LSTM", "LSTM");
}
//+------------------------------------------------------------------+
//| Create indicators and bootstrap/load the network. |
//+------------------------------------------------------------------+
bool CSignalLSTM::InitIndicators(CIndicators *indicators)
{
return InitNeuralNetwork(indicators);
}
//+------------------------------------------------------------------+
//| LSTM layer inserted between the input layer and the common |
//| tapering hidden-layer stack. |
//+------------------------------------------------------------------+
bool CSignalLSTM::AddCustomLayers(CArrayObj *topology)
{
return AddLstmStage(topology);
}
//+------------------------------------------------------------------+