Latest News

2022 Start working on a new website

BBS Trading Expert
Watch the Youtube BBS video and here is a crude oil trading example


Want to know more about:

NinjaTrader formulas.

MetaStock formulas.

MetaTrader formulas.

My YouTube videos.

AXIOM business books awards, bronze medal! Thank You!

No longer available!



Favorite articles in 2010, 11, 12, 14 and 2015 S&C Readers' Choice Awards.

readers choice awards

AXIOM Business Books Awards, bronze medal.

AXIOM award






NinjaTrader Formulas

HOME   Back to Ninjatrader Formulas Overview


ATR was developed by J. Welles Wilder and introduced in his book, “New concepts in technical trading systems” (1978). The Average True Range (ATR) indicator measures a security's volatility.

The basic ATR trailing stop trading method formula will switch from support to resistance and visa-versa when breaking support or resistance. For the ATR trailing stop method we calculate the maximum allowed loss based on the basic ATR function multiplied by a factor.

It is clear that the trailing stop based on ATR is a dynamic stop related to the higher or lower volatility in price action.

You can make the ATR trailing stop more or less sensitive by using different multiplication factors. Apply the ATR trailing stop at past data to find the best fitting value and apply this value for future data.

Special offer: "Capturing Profit with technical Analysis"

Vervoort Atr Trailing stop chart


Special offer: "BBS Band Indicators" DVD

This is the basic NinjaScript formula switching on stop breaks:


#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
    /// <summary>
    /// </summary>
    [Description("Sylvain Vervoort Average True Range Trailing Stop")]
    public class SVEATRTrailingStop : Indicator
        #region Variables
           private int     period     = 5;
           private double  multi = 3.5;
           Double     trail, loss;

        /// <summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        /// </summary>
        protected override void Initialize()
            Add(new Plot(Color.Blue, PlotStyle.Line, "Trailing Stop"));
            CalculateOnBarClose  = true;
            Overlay                   = true;

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
                if (CurrentBar < 1)

                // Trailing stop
                loss = ATR(Input, Period)[0] * multi;
                if (Close[0] > Value[1] && Close[1] > Value[1])
                      trail = Math.Max(Value[1], Close[0] - loss);
                else if (Close[0] < Value[1] && Close[1] < Value[1])
                      trail = Math.Min(Value[1], Close[0] + loss);
                else if (Close[0] > Value[1]) trail = Close[0] - loss;
                else trail = Close[0] + loss;

        #region Properties
        [Description("ATR period")]
           [Gui.Design.DisplayName("1. ATR Period")]
        public int Period
            get { return period; }
            set { period = Math.Max(1, value); }
           [Description("ATR multiplication Factor")]
           [Gui.Design.DisplayName("2. ATR Multiplication Factor")]
        public double Multi
            get { return multi; }
            set { multi = Math.Max(0, value); }

Download SVEATRTrailingStop



HOME   Back to NinjaTrader Formulas Overview


Risk Disclosure: Futures and forex trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones’ financial security or life style. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.

Hypothetical Performance Disclosure: Hypothetical performance results have many inherent limitations, some of which are described below. no representation is being made that any account will or is likely to achieve profits or losses similar to those shown; in fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk of actual trading. for example, the ability to withstand losses or to adhere to a particular trading program in spite of trading losses are material points which can also adversely affect actual trading results. There are numerous other factors related to the markets in general or to the implementation of any specific trading program which cannot be fully accounted for in the preparation of hypothetical performance results and all which can adversely affect trading results.

See more 'Legal Disclosures' in the bottom menu bar!

Copyright © 2007, All rights reserved.