forked from animatedread/Warrior_EA
Introduce m_useSwingContext flag and FindConfirmedZigZagPivot method to compute normalized swing direction/magnitude/age features from the existing ADZigZag indicator. Only pivots that are at least m_swingConfirmationBars old are trusted, preventing lookahead bias. The SWING_SCAN_CAP_BARS macro limits backward scan depth. Default is off.
134 lines
11 KiB
MQL5
134 lines
11 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Inputs.mqh |
|
|
//| AnimateDread |
|
|
//| https://www.mql5.com |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "AnimateDread"
|
|
#property link "https://www.mql5.com"
|
|
#include "..\Enumerations\InputEnums.mqh"
|
|
//--- Every "input string ..._Settings"/"AISignals" below this point (Expert_Settings, MM_Settings,
|
|
//--- Entry_Settings, Trailing_Settings, NNetworks_Settings, Indicator_Settings, AISignals,
|
|
//--- SF_Settings, NF_Settings, DOM_Settings) is a group-divider label, not a real setting - MetaTrader's
|
|
//--- Inputs tab renders an `input string` whose value equals its own comment as a section header in
|
|
//--- the dialog. Consumed entirely by the terminal's GUI, never read by any MQL5 statement in this
|
|
//--- codebase - that's expected, not a dead/unwired input.
|
|
//--- Expert General Settings
|
|
input string Expert_Settings = "Warrior EA Configuration"; // Warrior EA Configuration
|
|
input ulong Expert_MagicNumber = 2024; // Unique identifier for EA's orders
|
|
//--- The chart control panel's "Delete && Reset Weights" button does the same thing interactively,
|
|
//--- but only works on a live chart with a visible GUI. This input remains the way to force a
|
|
//--- reset headlessly - Strategy Tester runs, genetic/complete optimization, and .set-file-driven
|
|
//--- automation have no chart to click a button on - so it is NOT made redundant by the panel.
|
|
input bool trainingMode = false; // Headless equivalent of panel's Reset Weights button
|
|
input bool Expert_EveryTick = false; // Calculate technical analysis on every tick
|
|
input bool VerboseMode = false; // Detailed logging in the journal
|
|
//--- Money Management Settings
|
|
input string MM_Settings = "Money Management Settings"; // Money Management Settings
|
|
input MONEY_MANAGEMENT_STRATEGY MM_STRATEGY = FIXED_RISK; // Select MM strategy
|
|
input double Money_FixLot_Lots = 0.01; // Fixed trading volume [0.01-10]
|
|
input MONEY_RISK_PERCENT_PRESET Money_Risk_Percent = RISK_PCT_1; // Percentage of account balance to risk per trade
|
|
//--- Entry Strategy Settings
|
|
input string Entry_Settings = "Entry Settings"; // Entry Settings
|
|
input TRADING_DIRECTION tradingdirection = BOTH; // Allowed trading direction (Buy, Sell, Both)
|
|
input ENTRY_MULTIPLIER Entry_Multiplier = MARKET; // Entry price offset multiplier based on ATR
|
|
input BARS_EXPIRATION Signal_Expiration = BARS_X3; // Time to expiration for pending orders (in bars)
|
|
input bool UseDatabaseRanking = false; // Use time based win rates for filters weights
|
|
input ATR_MULTIPLIER SL_Atr_Multiplier = ATR_x3; // Stop-loss distance beyond swing high/low, as a multiple of ATR
|
|
input RISK_REWARD_RATIO Min_Risk_Reward_Ratio = RR_1x2; // Minimum reward:risk ratio required to open a trade
|
|
input SL_TP_SOURCE SLTP_Source = SLTP_RULE_BASED; // SL/TP sizing method
|
|
input CONFIDENCE_SOURCE Confidence_Source = CONF_AI; // Confidence source for AI SL/TP, AI exit, and AI lot sizing
|
|
input bool Use_AI_Exit = false; // Close position early when confidence reverses against it
|
|
input THRESHOLDS_PRESET AI_Exit_Threshold = T70; // Min. confidence required to trigger an early AI exit
|
|
input bool Use_AI_Lot_Sizing = false; // Scale lot size by confidence (Intelligent MM strategy only)
|
|
//--- Trailing Stop Settings
|
|
input string Trailing_Settings = "Trailing Settings"; // Trailing Settings
|
|
input TRAILING_STRATEGY TrailingStrategy = TRAILING_STRATEGY_NONE; // Default Trailing stop strategy
|
|
//--- Neural Networks Settings
|
|
input string NNetworks_Settings = "Neural Networks Settings"; // Neural Networks Settings
|
|
input AI_CHOICE AIType = MLP; // Artificial Intelligence algorithm
|
|
// Restores the SGD/ADAM choice the early EA had before it was hardcoded to ADAM. Now honored by
|
|
// all three signal types (PAI/CONV/LSTM) - CNeuronLSTMOCL has an accelerated SGD+momentum kernel
|
|
// (LSTM_UpdateWeightsMomentum, AI\Network.mqh) alongside its original Adam-only one. SGD's own
|
|
// learning rate/momentum are the SgdLearningRate/SgdMomentum inputs (AI\Network.mqh), not a
|
|
// multiple of Adam's rate.
|
|
input ENUM_OPTIMIZATION TrainingOptimizer = ADAM; // Weight-update optimizer (PAI/CONV/LSTM)
|
|
input TRAINING_YEARS_PRESET StudyPeriods = YEARS_10; // No. of years for AI Training
|
|
input PERCENTAGE_PRESETS MinWR = PCT_80; // Min. Win Rate to stop training
|
|
input PERCENTAGE_PRESETS MinRecall = PCT_60; // Min. per-class OOS recall to stop training
|
|
input OOS_SPLIT_PRESET OOSSplit = OOS_30; // Out-of-sample holdout, share of study period never trained on
|
|
input CLASS_SAMPLE_WEIGHT_PRESET ClassSampleWeight = CSW_15; // Currently unused - class balance is oversampling-only now
|
|
input FOCAL_GAMMA_PRESET FocalLossGamma = FG_20; // Focal-loss exponent - down-weights confident examples
|
|
input OUTPUT_NEURONS_COUNT OutputNeuronsCount = OUTPUT_CLASSIFICATION; // Type of output algorithm
|
|
input FIRST_LAYER_NEURONS InitialNeurons = NEURONS_1000; // No. of neurons in first hidden layer
|
|
input HIDDEN_LAYERS_COUNT HiddenLayersCount = LAYERS_4; // No. of hidden layers
|
|
input MIN_NEURONS_COUNT MinNeuronsCount = MIN_NEURONS_20; // Min. No. neurons per hidden layer
|
|
input NEURONS_REDUCTION_FACTOR NeuronsReduction = RF_70; // Neurons reduction per hidden layer
|
|
input SWING_CONFIRMATION_PRESET SwingConfirmationBars = SC_100; // Bars to wait before trusting a ZigZag reversal as a label
|
|
input MAX_ERAS_PRESET MaxErasPerRun = ME_1000; // Safety cap: max eras per training call before pausing
|
|
input RETRY_COOLDOWN_PRESET TrainRetryCooldownSec = RC_60; // Seconds to wait after era cap before retrying training
|
|
//--- Global Indicator Settings
|
|
input string Indicator_Settings = "Indicator Settings"; // Input Data Settings (applies globally)
|
|
// Was PERIOD_5 - smaller than ADZigZag's own InpDepth=12 (CustomIndicators\ADZigZag.mq5), meaning
|
|
// the model's feature window covered less than half of what its own training label (a confirmed
|
|
// ZigZag swing pivot) requires to even exist. It was structurally unable to see enough bars to
|
|
// recognize the swing structure it was being asked to classify - a plausible root cause of the
|
|
// erratic (non-converging, 0-90% swinging) Buy/Sell OOS recall observed across many real training
|
|
// runs. PERIOD_20 gives comfortable margin above Depth=12 for a full swing leg to be visible.
|
|
input IND_PERIODS_PRESETS ind_Periods = PERIOD_20; // Number of candles to analyse
|
|
input ENUM_APPLIED_VOLUME VolumeData = VOLUME_TICK; // Volume Data
|
|
input string AISignals = "AI Signals"; // AI Signals
|
|
input bool EnableVolume = true; // Analyse Volume Patterns
|
|
input bool EnableTime = true; // Analyse Temporal Patterns
|
|
input bool EnableATR = true; // Analyse Volatility Patterns
|
|
// Direction/magnitude/age of the last CONFIRMED ZigZag swing (see BufferTempDataCompute()'s
|
|
// m_useSwingContext block) - reads the same ADZigZag indicator the training labels already come from,
|
|
// under the same repainting embargo (SwingConfirmationBars above), so it stays lookahead-safe.
|
|
input bool EnableSwingContext = false; // Analyse ZigZag Swing Context Patterns
|
|
// Event proximity + impact only (minutes since/until the nearest symbol-relevant calendar event,
|
|
// weighted by impact) - not actual-vs-forecast deviation, since a release's outcome isn't knowable
|
|
// ahead of time the way its scheduled time is (see System\NewsRelevance.mqh's declaration comment).
|
|
input bool EnableNews = false; // Analyse News Event Proximity/Impact Patterns
|
|
input NF_LOOKBACK_PRESETS NewsFeatureWindowMinutes = M60; // How far the news feature looks back/ahead
|
|
input bool EnableADCumulativeDelta = false; // Analyse AD Cumulative Delta Patterns
|
|
input bool EnableADShorteningOfThrust = false; // Analyse AD Shortening of Thrust Patterns
|
|
input bool EnableADWyckoffEventStream = false; // Analyse AD Wyckoff Event Stream Patterns
|
|
input bool EnableADWyckoffFailedStructure = false; // Analyse AD Wyckoff Failed Structure Patterns
|
|
input bool EnableADWyckoffSignificantBarInversion = false; // Analyse AD Wyckoff Significant Bar Inversion Patterns
|
|
input bool AutoTuneIndicators = false; // Randomly search AD indicator params for better OOS accuracy
|
|
input TUNE_TRIALS_PRESET IndicatorTuneTrials = TT_8; // No. of tuning trials to run when AutoTuneIndicators is enabled
|
|
//--- Time Filter Settings
|
|
input string SF_Settings = "Time Related Settings"; // Session Filter Settings
|
|
input CLOSE_DAY_OF_WEEK targetDayOfWeek = CLOSE_EVERYDAY; // Preferred day for closing positions
|
|
input CLOSE_HOUR_OF_DAY targetHour = CH_22; // Preferred hour for closing positions
|
|
input CLOSE_MINUTE_OF_HOUR targetMinutes = CM_0; // Preferred minute for closing positions
|
|
input bool SF_trade_LondonSession = false; // Trade during London session
|
|
input bool SF_trade_TokyoSession = false; // Trade during Tokyo session
|
|
input bool SF_trade_NewYorkSession = true; // Trade during New York session
|
|
input ENTRY_HOUR_OF_DAY ITF_GoodHourOfDay = -1; // Preferred trading hour
|
|
input int ITF_BadHoursOfDay = 0; // Hours to avoid trading
|
|
input TIME_FILTER_DAY_OF_WEEK ITF_GoodDayOfWeek = -1; // Preferred trading day
|
|
input int ITF_BadDaysOfWeek = 0; // Days to avoid trading
|
|
//--- News Filter Settings
|
|
input string NF_Settings = "News Filter Settings"; // News Filter Settings
|
|
input NF_LOOKBACK_PRESETS NF_LookMinutes = M60; // Lookback period to avoid trading around news
|
|
input NF_IMPACT_PRESETS NF_MinImpact = HOLIDAYS; // Minimum news impact to filter out
|
|
//--- Market Depth (DOM) Settings
|
|
input string DOM_Settings = "Market Depth Settings"; // Market Depth (DOM) Settings
|
|
// Availability is verified once in OnInit() (MarketBookAdd + a brief poll for real data) BEFORE any
|
|
// neural network is initialized - if this symbol/broker doesn't provide real Depth of Market, this
|
|
// input is treated as false for the whole run, the user is alerted via a popup, and the filter below
|
|
// is never created. Not a trained NN input feature: MT5 only exposes the CURRENT order book (no
|
|
// historical DOM), so it participates as a live-only, rule-based confirmation/veto in the same
|
|
// weighted Direction() composite the News/Session/ITF filters already use - see
|
|
// Signals\SignalMarketDepth.mqh's class-level comment for the full rationale.
|
|
input bool EnableMarketDepth = false; // Order-book imbalance as live filter (needs broker DOM)
|
|
input DOM_DEPTH_LEVELS_PRESET DOM_DepthLevels = DOM_LEVELS_5; // No. of book levels per side summed into the imbalance ratio
|
|
input DOM_IMBALANCE_SCALE_PRESET DOM_ImbalanceScale = DOM_SCALE_100; // Influence of book imbalance on composite signal
|
|
input DOM_MAX_SPREAD_MULTIPLE_PRESET DOM_MaxSpreadMultiple = DOM_SPREADMULT_3x; // Veto entries when spread exceeds this multiple of its average
|
|
//--- Risk Guard Settings
|
|
input string RiskGuard_Settings = "Risk Guard Settings"; // Risk Guard Settings
|
|
//--- Blocks new entries only (never closes existing positions - see Signals\SignalRiskGuard.mqh's
|
|
//--- class-level comment) once either limit is breached. RISK_LIMIT_DISABLED (0) on both means this
|
|
//--- filter is a permanent no-op, same convention as DOM_SPREADMULT_OFF above.
|
|
input RISK_LIMIT_PCT_PRESET MaxDailyLossPct = RISK_LIMIT_DISABLED; // Halt entries for the day once loss exceeds this % of balance
|
|
input RISK_LIMIT_PCT_PRESET MaxDrawdownPct = RISK_LIMIT_DISABLED; // Halt entries once drawdown from equity peak exceeds this %
|