Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Difference between Current and Previous Value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Difference between Current and Previous Value

    I have created a simple indicator that that the current value of the StdDev and subtracts it from the previous value and then takes the average. For some reason nothing will plot in the window. It works if I use just the current value, but when I try to subtract the current from the previous it does not work. Any ideas what I am doing wrong?

    Please find listed below the code:

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Reference sample demonstrating how to use DataSeries objects to store self calculations.
    /// </summary>
    [Description("Reference sample demonstrating how to use DataSeries objects to store self calculations.")]
    public class svSDdiff : Indicator
    {
    #region Variables
    private int period = 5;

    // Defines the DataSeries object
    private DataSeries myDataSeries;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    // Adds a plot to our NinjaScript Indicator
    Add(new Plot(Color.Orange, PlotStyle.Line, "Average Range"));

    // Create a new DataSeries object and assign it to the variable myDataSeries declared in the ‘Variables’ region above
    myDataSeries = new DataSeries(this);

    CalculateOnBarClose = true;
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    /* To set values to our DataSeries we use the Set() method. Here we are setting the DataSeries
    object for the current bar to take on the absolute value of the difference between the current bar's
    open and close. */
    myDataSeries.Set(StdDev(Close,14)[1]-StdDev(Close,14)[0]);

    /* Take note that the method for setting the value to be plotted is the same as for setting a value
    to a DataSeries object. The difference here is that the custom DataSeries object is not plotted while
    this "AvgR" is plotted.

    In this case we are plotting the Simple Moving Average of the intermediate calculation step stored in our
    DataSeries object. */
    AvgR.Set(SMA(myDataSeries, Period)[0]);
    }

    #2
    Hi StevenV,

    Thanks for the post. If you check log tab of control center, it will show any error messages. You are running into this item here:


    You can resolve by adding this line to top of OnBarUpdate()
    if (CurrentBar < 1) return;
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kempotrader, Today, 08:56 AM
    0 responses
    6 views
    0 likes
    Last Post kempotrader  
    Started by kempotrader, Today, 08:54 AM
    0 responses
    4 views
    0 likes
    Last Post kempotrader  
    Started by mmenigma, Today, 08:54 AM
    0 responses
    2 views
    0 likes
    Last Post mmenigma  
    Started by halgo_boulder, Today, 08:44 AM
    0 responses
    1 view
    0 likes
    Last Post halgo_boulder  
    Started by drewski1980, Today, 08:24 AM
    0 responses
    3 views
    0 likes
    Last Post drewski1980  
    Working...
    X