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

Failed Swing Indicator

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

    Failed Swing Indicator

    I am trying to create an indicator that will calculate the SMA average of a sepcified period of the High - (Minus) the open of a bar and that value multiplied by 2.8 to plot that line on the chart. Here is how far I got using the Wizard as a start, the compilation is providing a failuer message..

    #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;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class FailedSwing : Indicator
    {
    #region Variables
    private int period = 4;
    // Wizard generated variables
    private string defaultInst = @"YM ##-## (Daily)"; // Default setting for DefaultInst
    // User defined variables (add any user defined variables below)
    #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()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.RoyalBlue), PlotStyle.Line, "FSwing"));
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Value.Set((SMA(High)[0] - SMA (Open)[0])*2.8);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries FSwing
    {
    get { return Values[0]; }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public string DefaultInst
    {
    get { return defaultInst; }
    set { defaultInst = value; }
    }
    #endregion
    }
    }

    #2
    Hello,
    There is not a period set for the SMA. A period must be set for the SMA to calculate.
    I have proved an example of the code for Value.Set() that will compile.
    Code:
    Value.Set((SMA(High, 20)[0] - SMA(Open, 20)[0]) * 2.8);
    If we can be of any other assistance please let us know.
    Cody B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Tim-c, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by FrancisMorro, Today, 03:24 AM
    0 responses
    2 views
    0 likes
    Last Post FrancisMorro  
    Started by Segwin, 05-07-2018, 02:15 PM
    10 responses
    1,772 views
    0 likes
    Last Post Leafcutter  
    Started by Rapine Heihei, 04-23-2024, 07:51 PM
    2 responses
    31 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    945 views
    0 likes
    Last Post spwizard  
    Working...
    X