ML Engine
Version: v.1.0.0.0

Description
Universal ML engine for signal filtering and forecasting.
Important
For probability forecasting and for this indicator to work, you must add to Input Series the data series of another indicator that provides directional signals: > 0 for long and < 0 for short. The ML Engine does not work on its own; it only works in combination with such an indicator.
This indicator requires an active NinjaTrader Order Flow + subscription to function.
Properties
Ensemble Models
- Use LightGbm [default: true] — Enable LightGbm.
- Use FastTree [default: true] — Enable FastTree.
- Use FastForest [default: true] — Enable FastForest.
- Use SDCA LogReg [default: true] — Enable SDCA logistic regression.
- Use LBFGS LogReg [default: true] — Enable LBFGS logistic regression.
- Use Averaged Perceptron [default: true] — Enable Averaged Perceptron.
- Use SGD Calibrated [default: true] — Enable SGD calibrated.
Feature Params
- (Slope) Start Bars Ago [default: 14] — Start bar for VWAP slope.
- (Slope) End Bars Ago [default: 0] — End bar for VWAP slope.
- (Delta) Type [default: BidAsk] — Cumulative delta type.
- (Delta) Period [default: Session] — Cumulative delta period.
- (Delta) Size Filter [default: 0] — Delta size filter (0 = off).
- (VWAP) Resolution [default: Tick] — VWAP data resolution.
- (VWAP) Standard deviations [default: Two] — VWAP standard deviations.
- (VWAP) SD1/SD2/SD3 Multiplier [default: 0.75, 1.5, 3, range: 0.001–∞] — Multipliers.
- (ATR) Period [default: 14] — ATR period.
- (MACD) Fast/Slow/Smooth [default: 12, 26, 9] — MACD periods.
- (Gap) Session Start Time [default: 08:30] — Session start for gap calculation.
- Signal Offset Bars [default: 0, range: 0–∞] — Bars ago to read input signal.
ML Engine
- Enable Logging [default: false] — Print to Output and write MLEngine.log.
- Show Metrics Table [default: true] — Show ensemble metrics table on chart.
- Show Probability [default: true] — Show probability label on chart.
- Use Metrics Filter [default: false] — Block signals if metrics below thresholds.
- Use Auto Weights [default: true] — Auto weight models by AUC and F1.
- Min Probability [default: 0.5, range: 0–1] — Minimum ensemble probability to pass signal.
- Bars Ahead [default: 60] — Bars ahead for labeling training samples.
- Records Before Retrain [default: 10] — Minimum samples before retraining.
ML Metrics Filter
- Min AUC [default: 0] — Minimum AUC.
- Min F1 [default: 0] — Minimum F1 score.
- Min Accuracy [default: 0] — Minimum accuracy.
- Min Precision [default: 0] — Minimum precision.
- Min Recall [default: 0] — Minimum recall.
Probability Style
- Probability font — Font family for probability labels.
- Probability color — Text color for probability labels.
- Probability offset (ticks) [default: 0] — Vertical offset in ticks.
Table Style
- Table position [default: TopLeft] — Corner of chart for metrics table.
- Table font — Font family for metrics table.
- Table text color — Text color for metrics table.
- Table background — Background fill for metrics table.
- Table outline — Border/outline color for metrics table.
- Table opacity [default: 75, range: 0–100] — Opacity (0-100).
For developers: using ML Engine in strategies
Below is a step‑by‑step example of how to connect ML Engine to your own strategy and use its MLSignal for entries.
1. Create a new strategy
Create a new NinjaScript Strategy (e.g. MLEngineTest) in the NinjaTrader.NinjaScript.Strategies namespace.
At the top of the file keep the standard using directives and make sure you have:
using NinjaTrader.NinjaScript;using NinjaTrader.NinjaScript.Indicators;
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class MLEngineTest : Strategy
{
// ...
}
}
2. Declare fields for base signal and ML Engine
Inside the strategy class, add:
- any indicators that will generate your base directional signal (e.g. EMAs);
- a
Series<double>for that base signal; - an
Indicators.ASF.MLEnginefield.
private EMA EMA1;
private EMA EMA2;
private Series<double> BaseSignal = null;
private Indicators.ASF.MLEngine mlengine = null;
3. Configure required additional data series (State.Configure)
ML Engine requires two extra data series (Tick and Day). They must be added in State.Configure, otherwise the indicator will not work:
else if (State == State.Configure)
{
AddDataSeries(BarsPeriodType.Tick, 1);
AddDataSeries(BarsPeriodType.Day, 1);
}
4. Create ML Engine instance (State.DataLoaded)
In State.DataLoaded:
- Instantiate your base indicators (e.g. EMAs).
- Create
BaseSignalseries. - Create
mlenginevia theMLEngine(...)NinjaScript method, passingBaseSignalas the first parameter. - Add the indicator to the chart (optional but recommended).
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 14);
EMA2 = EMA(Close, 50);
BaseSignal = new Series<double>(this, MaximumBarsLookBack.Infinite);
mlengine = MLEngine(
BaseSignal, // input signal series (>0 long, <0 short)
false, true, true, false, // model toggles (example)
true, // Use Auto Weights
0.5, // Min Probability
60, // Bars Ahead
10, // Records Before Retrain
0, 0, 0, 0, 0, // metrics filters
TextPosition.TopLeft,
new SimpleFont("Consolas", 11) { Bold = false },
Brushes.Silver, Brushes.Black, Brushes.Transparent, 75,
new SimpleFont("Consolas", 11) { Bold = false },
Brushes.CornflowerBlue, 10,
true, true, true, true, true, true, true,
14, // ATR Period
0, // Signal Offset Bars
CumulativeDeltaType.UpDownTick,
CumulativeDeltaPeriod.Session,
0, // Delta Size Filter
VWAPResolution.Standard,
VWAPStandardDeviations.Two,
0.75, 1.5, 3, // VWAP SD multipliers
14, 12, 26, 9, // ATR + MACD
DateTime.Parse("09:30", System.Globalization.CultureInfo.InvariantCulture),
0 // Probability offset ticks
);
AddChartIndicator(mlengine);
}
You can tune these parameters according to the Properties section above or your template.
5. Feed base signal and use MLSignal in OnBarUpdate
On each bar:
- Ensure you work only on the main series (
BarsInProgress == 0). - Make sure there is enough history loaded:
- on the primary series you must have at least 21 bars + Signal Offset Bars;
- on the daily series you must have at least 1 bar (1 day).
- Calculate your base signal (
BaseSignal[0]) so that: > 0means long,< 0means short,0means no signal.- Use
mlengine.MLSignal[0]as a filtered ML output for entries.
Example using EMA cross:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
// Make sure all series have enough bars
if (CurrentBars[0] < 21 || CurrentBars[2] < 1)
return;
// 1 = long signal, -1 = short signal, 0 = no signal
BaseSignal[0] =
CrossAbove(EMA1, EMA2, 1) ? 1 :
CrossBelow(EMA1, EMA2, 1) ? -1 : 0;
// Use ML-filtered signal for entries
if (mlengine.MLSignal[0] > 0)
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
if (mlengine.MLSignal[0] < 0)
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
}
This pattern can be reused with any other indicator that outputs a signed signal (>0 long, <0 short). You only need to plug its output into BaseSignal[0] instead of the EMA cross logic.