Skip to content

Grid Autostrategy

Version: v.2.0.0.0

Grid Autostrategy

Description

This strategy uses the interaction of price with one or more exponential moving averages (EMAs) and the slope of the EMA to define where to place an order grid. When price is trading within the average price zone, a grid of orders is placed: the strategy buys when price moves down and sells when price moves up, aiming to capture mean reversion around the average.

Properties

General Parameters

  • Becktest mode [default: false] — Becktest mode.
  • Debug Mode [default: false] — Debug Mode.
  • Show indicators [default: true] — Show indicators.
  • Direction [default: Both] — Direction (OnlyLong, OnlyShort, Both).
  • Calculation type exit orders [default: Percent] — Calculation type exit orders (Ticks, Pips, Percent, Currency).
  • Qty contracts [default: 1, range: 1–∞] — Qty contracts.
  • Grid count [default: 5, range: 1–∞] — Grid count.
  • Order Spacing (ticks) [default: 15, range: 1–∞] — Order Spacing (ticks).
  • Stop loss [default: 0.5, range: 0.001–∞] — Stop loss.
  • Profit target [default: 0.5, range: 0.001–∞] — Profit target.
  • Use ROI? [default: false] — Use ROI?
  • Use ML.NET filter? [default: true] — Use ML.NET filter?

Indicator Parameters

  • Ema period 1 [default: 200, range: 1–∞] — Sets the period for the EMA 1 indicator.
  • Ema period 2 [default: 50, range: 1–∞] — Sets the period for the EMA 2 indicator.
  • Ema difference [default: 250] — Sets the difference with Ema 1 and Ema 2 which should be no more than that so that there is a signal to enter.
  • Slope Degree [default: 25] — The Slope indicator value sets the slope limits in which the EMA 1 indicator should be in order to have a signal for entry, it means that if you set the value to 0.5, the slope should be between 0.5 and -0.5 in order to trigger a signal..

Ensemble Models

  • Use LightGbm [default: true] — Enable LightGbm classifier.
  • Use FastTree [default: true] — Enable FastTree classifier.
  • Use FastForest [default: true] — Enable FastForest classifier.
  • 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 classifier.
  • Use SGD Calibrated [default: true] — Enable SGD calibrated classifier.

Feature Params

  • (Slope) Start Bars Ago [default: 14, range: 1–∞] — Start bar (ago) for VWAP slope.
  • (Slope) End Bars Ago [default: 0, range: 0–∞] — End bar (ago) for VWAP slope.
  • (Delta) Type [default: BidAsk] — Cumulative delta calculation type.
  • (Delta) Period [default: Session] — Cumulative delta period.
  • (Delta) Size Filter [default: 0, range: 0–∞] — Delta size filter (0 = off).
  • (VWAP) Resolution [default: Tick] — VWAP resolution.
  • (VWAP) Standard Deviations [default: Two] — VWAP standard deviation bands.
  • (VWAP) SD1/SD2/SD3 Multiplier [default: 0.75, 1.5, 3, range: 0.001–∞] — VWAP SD multipliers.
  • (ATR) Period [default: 14, range: 1–∞] — ATR period.
  • (MACD) Fast/Slow/Smooth [default: 12, 26, 9, range: 1–∞] — MACD periods.
  • (Gap) Session Start Time [default: 08:30] — Local time of the first bar of the session used for gap calculation.
  • Signal Offset Bars [default: 0, range: 0–∞] — Bars ago to read input signal.

ML Engine

  • Enable Logging [default: false] — When enabled: Print() to Output window 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, range: 1–∞] — Bars ahead used for labeling training samples.
  • Records Before Retrain [default: 10, range: 1–∞] — Minimum samples before retraining.

ML Metrics Filter

  • Min AUC [default: 0.0, range: 0–1] — Minimum AUC required to pass metrics filter.
  • Min F1 [default: 0.0, range: 0–1] — Minimum F1 score required to pass metrics filter.
  • Min Accuracy [default: 0.0, range: 0–1] — Minimum accuracy required to pass metrics filter.
  • Min Precision [default: 0.0, range: 0–1] — Minimum precision required to pass metrics filter.
  • Min Recall [default: 0.0, range: 0–1] — Minimum recall required to pass metrics filter.

Probability Style

  • Probability font — Font family for probability labels.
  • Probability color — Text color for probability labels on chart.
  • Probability offset (ticks) [default: 0, range: -∞–∞] — Vertical offset in ticks.

Table Style

  • Table position [default: TopLeft] — Corner of chart where metrics table is drawn.
  • 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 table (0-100).

Roi Parameters

  • Roi 1 [default: false] — Enable first ROI level.
  • Period 1 [default: 15, range: 0–∞] — Bars for first ROI level.
  • Roi value 1 (%) [default: 0.2, range: 0–∞] — Target ROI percentage for first level.
  • Roi 2 [default: false] — Enable second ROI level.
  • Period 2 [default: 30, range: 1–∞] — Bars for second ROI level.
  • Roi value 2 (%) [default: 0.1, range: 0–∞] — Target ROI percentage for second level.
  • Roi 3 [default: false] — Enable third ROI level.
  • Period 3 [default: 45, range: 1–∞] — Bars for third ROI level.
  • Roi value 3 (%) [default: 0.05, range: 0–∞] — Target ROI percentage for third level.

Money Management

  • Enable Daily Profit [default: true] — Control daily profit.
  • Enable Daily Loss [default: true] — Control daily loss.
  • Daily loss limit ($) [default: 1000, range: 1–∞] — Daily loss limit in currency.
  • Daily profit target ($) [default: 1000, range: 1–∞] — Daily profit target in currency.

Day of Week

  • Sunday [default: false] — Enable trading on Sunday.
  • Monday [default: true] — Enable trading on Monday.
  • Tuesday [default: true] — Enable trading on Tuesday.
  • Wednesday [default: true] — Enable trading on Wednesday.
  • Thursday [default: true] — Enable trading on Thursday.
  • Friday [default: true] — Enable trading on Friday.
  • Saturday [default: false] — Enable trading on Saturday.

Trading time

  • Enable session 1 times? (optional) [default: true] — Enable first trading session.
  • Session 1 start time [default: 00:00] — Session first start time.
  • Session 1 end time [default: 12:00] — Session first end time.
  • Enable session 2 times? (optional) [default: true] — Enable second trading session.
  • Session 2 start time [default: 12:00] — Session second start time.
  • Session 2 end time [default: 16:00] — Session second end time.
  • Enable session 3 times? (optional) [default: false] — Enable third trading session.
  • Session 3 start time [default: 16:00] — Session third start time.
  • Session 3 end time [default: 23:59] — Session third end time.
  • Enable exit on session close [default: true] — Enable exit at the session close.
  • Session close time [default: 23:59] — Session close time.
  • Exit on session close minutes [default: 1, range: 1–∞] — Minutes before session close to exit.

Note:

If all days are disabled, the strategy will trade without any restrictions on days.

If all trading session clocks are turned off, the auto strategy will trade without time restrictions.

Version Change History

v.1.0.0.2 (Nov 12, 2023)

1) Improved trading session time.

v.1.0.0.3 (Aug 1, 2024)

1) A new architecture is created.

2) A separate class for strategy variables is created, protecting variables from the thread race.

3) New Stop Loss and Profit functions are added.

4) Stop Loss and Profit order calculation type is added (ticks, pips, percent, currency).

5) Trade direction filter function is added, optional (Only long, only short, both directions).

6) Created a special function of raising a position after breaking the connection with the strategy, which takes into account how many grid orders have already been executed and restores grid orders that have not been executed yet.

7) Created special order names used in special events of closing a position, closing due to risk, or closing a position due to the end of the session.

8) Updated manual.

v.1.0.0.4 (Feb 23, 2025)

1) Added detailed commenting to all code to better understand how the code works.

v.1.2.0.0 (May 21, 2025)

1) Added detailed code comments for better understanding.

2) Improved OnBarUpdate method execution conditions.

3) Updated strategy state names for more accurate representation of strategy operation.

4) Added detailed comments to strategy and indicator.

5) Added ROI function for trade exit.

v.1.2.0.1 (Oct 26, 2025)

1) Trading hours and days logic updated — if all sessions are disabled, the strategy now runs without time restrictions instead of stopping trading.

v.2.0.0.0 (Mar 9, 2026)

1) ML Engine filter feature added.