NinjaTrader scalping strategy workflow

NinjaTrader scalping strategy with managed NinjaScript code

This NinjaTrader 8 example evaluates EMA crossovers at bar close and requests tick-based stops and targets. Inspect its source and test costs, fill assumptions, and session behavior before drawing conclusions about short-horizon trading.

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

  • Small price targets make spread, commission, slippage, and order handling material to the result.
  • 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
  • Configured session-close exit handling
  • Native compilation and simulation checklist

Scalping mechanics on NinjaTrader 8: tick bars vs time bars

Tick bars group a configured number of ticks, while time bars group observations by interval. The same EMA periods therefore cover different durations on those charts. Compare signal timing and data construction before choosing either representation.

Calculate.OnBarClose evaluates this example after bar close. OnEachTick changes evaluation frequency; it does not guarantee immediate fills or prevent duplicate orders. Bar-close evaluation also does not rule out every form of repainting, data revision, or future-data misuse.

  • 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 express entry and protective-order rules in C#. Order acceptance, execution timing, rejection, partial fills, and loss size remain dependent on the platform, connection, broker, and market.

  • 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
  • Protection: configure intended exits before entry, then verify their actual submission and fill behavior.

Designing an S&P 500 futures scalping rule set

ES and MES have a 0.25 index-point tick, worth $12.50 and $1.25 per contract respectively. The example requests an 8-tick target (2 index points) and a 12-tick stop (3 index points). These are illustrative inputs, not validated settings or maximum-loss guarantees.

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: the example requests exit 30 seconds before session close; this does not meet a broker cutoff 15 minutes before close. Add and test an earlier cutoff if required.

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.

Model commissions and test several slippage assumptions suited to the contract, order type, size, and data. A one- or two-tick scenario is a sensitivity test, not proof of realistic fills. Compare those assumptions with observed execution records when available.

  • Include full round-trip broker and exchange fees in backtest properties
  • Stress-test slippage over multiple scenarios instead of assuming a universal 1-to-2-tick cost.
  • Review trade distribution to ensure profits are not dependent on a few outlier bars

Generating custom scalping strategies with Pineify

Pineify can draft a single-file NinjaScript Strategy from explicit entry and exit rules. Standard indicators such as EMA and ATR fit the supported reference; specialized VWAP or Order Flow dependencies require separate API and entitlement checks.

Review the complete draft, run the external static/API check, compile in NinjaScript Editor, and test in the destination environment. Generation does not establish compilation success, execution quality, or profitability.

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 entry, exit, and protective-order rules to draft an editable NinjaScript Strategy for source review and native testing.