NinjaTrader scalping strategy workflow

NinjaTrader scalping strategy with managed NinjaScript code

Scalping futures like the S&P 500 E-mini (ES) or Micro (MES) requires fast execution, tight brackets, and disciplined risk management. Pineify generates clean, single-file NinjaScript scalping strategies ready for NinjaTrader 8 compilation and testing.

Managed NinjaScript Scalping Strategy

A complete single-file NinjaTrader 8 scalping strategy featuring fast EMA crossover signals and managed tick-based profit targets and stop losses.

using System;
using System.ComponentModel.DataAnnotations;
using NinjaTrader.Cbi;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Indicators;

namespace NinjaTrader.NinjaScript.Strategies
{
    public class ScalpingStrategy : Strategy
    {
        [NinjaScriptProperty]
        [Range(1, 100)]
        [Display(Name = "Fast EMA Period", GroupName = "Parameters", Order = 0)]
        public int FastEmaPeriod { get; set; }

        [NinjaScriptProperty]
        [Range(2, 200)]
        [Display(Name = "Slow EMA Period", GroupName = "Parameters", Order = 1)]
        public int SlowEmaPeriod { get; set; }

        [NinjaScriptProperty]
        [Range(1, 100)]
        [Display(Name = "Profit Target (Ticks)", GroupName = "Risk", Order = 2)]
        public int TargetTicks { get; set; }

        [NinjaScriptProperty]
        [Range(1, 100)]
        [Display(Name = "Stop Loss (Ticks)", GroupName = "Risk", Order = 3)]
        public int StopLossTicks { get; set; }

        private EMA fastEma;
        private EMA slowEma;

        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Name = "ScalpingStrategy";
                Description = "Fast momentum scalping strategy with managed tick-based brackets.";
                Calculate = Calculate.OnBarClose;
                EntriesPerDirection = 1;
                EntryHandling = EntryHandling.AllEntries;
                IsExitOnSessionCloseStrategy = true;
                ExitOnSessionCloseSeconds = 30;
                IsFillLimitOnTouch = false;
                TraceOrders = false;

                FastEmaPeriod = 9;
                SlowEmaPeriod = 21;
                TargetTicks = 8;
                StopLossTicks = 12;
            }
            else if (State == State.DataLoaded)
            {
                fastEma = EMA(FastEmaPeriod);
                slowEma = EMA(SlowEmaPeriod);

                SetProfitTarget("LongScalp", CalculationMode.Ticks, TargetTicks);
                SetStopLoss("LongScalp", CalculationMode.Ticks, StopLossTicks, false);

                SetProfitTarget("ShortScalp", CalculationMode.Ticks, TargetTicks);
                SetStopLoss("ShortScalp", CalculationMode.Ticks, StopLossTicks, false);
            }
        }

        protected override void OnBarUpdate()
        {
            if (CurrentBar < Math.Max(FastEmaPeriod, SlowEmaPeriod))
                return;

            if (Position.MarketPosition == MarketPosition.Flat)
            {
                if (CrossAbove(fastEma, slowEma, 1))
                {
                    EnterLong("LongScalp");
                }
                else if (CrossBelow(fastEma, slowEma, 1))
                {
                    EnterShort("ShortScalp");
                }
            }
        }
    }
}

Direct answer

A NinjaTrader scalping strategy targets small, rapid price moves on short intervals like 1-minute or tick charts. Traders can execute scalps manually using NinjaTrader ATM (Advanced Trade Management) brackets or automate entries and exits with a managed NinjaScript Strategy. Pineify can generate a single-file C# scalping strategy with configurable tick targets and stops for testing in NinjaTrader Strategy Analyzer.

What to know first

  • Scalping relies on small tick targets (such as 4 to 12 ticks on ES/MES) with predefined stop losses.
  • NinjaTrader ATM strategies offer visual bracket management for discretionary scalping on the SuperDOM or Chart Trader.
  • Automated NinjaScript scalping uses SetProfitTarget and SetStopLoss tied to specific entry signal names.
  • Slippage and commission costs significantly impact scalping profitability and must be modeled during backtests.
  • Test every scalping script in simulation and Strategy Analyzer before committing live capital.

Supported scope

What this NinjaScript workflow can cover

  • Single-file managed NinjaScript strategy
  • Configurable tick-based profit targets and stops
  • Fast EMA momentum crossover entry logic
  • Automated session-close position flattening
  • Ready for Strategy Analyzer and simulation testing

Scalping mechanics on NinjaTrader 8: tick bars vs time bars

Scalpers often trade tick bars (such as 500-tick or 1000-tick) rather than fixed-time bars (like 1-minute or 5-minute). Tick charts compress low-activity periods and expand during high-volume market moves, providing clearer visibility of immediate momentum shifts.

When writing automated strategies in NinjaScript, select whether Calculate runs OnBarClose or OnEachTick. OnBarClose prevents intra-bar signal flicker and repainting, while OnEachTick allows immediate fills on price changes but requires careful state handling to prevent duplicate orders.

  • Tick charts: Each bar represents a fixed number of transactions (e.g., 500 ticks on S&P 500 futures)
  • Time charts: Each bar represents a fixed elapsed time (e.g., 1-minute or 3-minute bars)
  • Calculate setting: OnBarClose for stable signal confirmation, OnEachTick for rapid intra-bar evaluation

ATM strategy brackets vs managed NinjaScript code

NinjaTrader provides two main approaches to scalping: ATM (Advanced Trade Management) templates and coded NinjaScript strategies. ATM templates work best for discretionary traders placing orders directly from the SuperDOM or Chart Trader, automatically attaching stop loss and take profit orders upon fill.

Managed NinjaScript strategies embed order rules directly in C# code using SetProfitTarget and SetStopLoss. This automated approach ensures consistent execution, eliminates emotional hesitation during fast market moves, and enables systematic backtesting across historical tick data.

  • ATM Strategies: Ideal for manual scalping with one-click order submission and visual drag-and-drop adjustments
  • NinjaScript Strategies: Ideal for algorithmic scalping with automated entry triggers and programmatic bracket enforcement
  • Risk Management: Both approaches enforce predefined risk before an entry order executes

Designing an S&P 500 futures scalping rule set

The S&P 500 E-mini (ES) and Micro E-mini (MES) trade in 0.25 index point ticks ($12.50 per tick for ES, $1.25 for MES). A typical scalping setup might target 8 ticks ($2.00 index points) with a 12-tick stop loss ($3.00 index points), targeting short-term momentum or pullbacks to moving averages.

In addition to moving averages, scalpers often look for resistance scalps where price rejects a prior session high, VWAP band, or key volume level. The Strategy below demonstrates a trend-following momentum scalp using fast and slow exponential moving averages combined with managed bracket orders.

  • Entry rules: Fast EMA crosses above Slow EMA for long, crosses below for short
  • Risk rules: Configurable tick-based profit targets and stop losses set in State.DataLoaded
  • Session exit: Automatic position closure before market close to avoid overnight margin requirements

Managing execution friction: commissions and slippage

Because scalping strategies capture modest tick gains, trading fees and execution slippage represent a large percentage of gross profits. A 4-tick gain on MES ($5.00) can be substantially reduced by round-trip commissions and a single tick of slippage.

When running historical backtests in Strategy Analyzer, always configure realistic commission schedules and at least one tick of slippage per trade. A strategy that shows high profitability under zero-cost assumptions may fail in live trading once real-world friction is applied.

  • Include full round-trip broker and exchange fees in backtest properties
  • Add 1 to 2 ticks of slippage to simulate market order fills in volatile conditions
  • Review trade distribution to ensure profits are not dependent on a few outlier bars

Generating custom scalping strategies with Pineify

Pineify NinjaTrader AI Coding Agent turns written scalping concepts into clean, compilable NinjaScript Strategy files. You can specify custom indicators (such as EMA, VWAP, or ATR), define precise entry and exit conditions, and configure tick-based risk brackets.

Each generated file follows single-file NinjaScript architecture, making it easy to open in NinjaScript Editor, press F5 to compile, and attach to your NinjaTrader charts or Strategy Analyzer for thorough testing.

Sources and verification

Pineify provides information and code-generation assistance, not investment advice. Generated code, static checks, backtests, simulations, and historical examples cannot predict prices or guarantee returns. Review all code and test it in NinjaTrader Editor, Strategy Analyzer, and a simulation account before considering live use.

Frequently asked questions

Generate Custom Scalping Strategies with AI

Describe your scalping rules, select your indicators and risk brackets, and receive a complete, compilable NinjaScript Strategy file.