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

Why does my indicator plot horizontally at 0.00 on the chart?

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

    Why does my indicator plot horizontally at 0.00 on the chart?

    Hi All

    My first indicator, in which I attempted to plot a triangle on a bar where the low of current bar is > than the high of the previous bar. Unfortunately I am getting a series of triangles plotted along the bottom of the chart at 0.00 price level. If anyone could help, I would appreciate it.

    Here is the code:

    public class PriceAction : Indicator
    {
    #region Variables
    // Wizard generated variables
    // 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.TriangleUp, "Plot0"));
    Overlay = true;
    }

    /// <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.
    Plot0.Set(Low[0] > High[-1] ? 1 : 0);
    }

    #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 Plot0
    {
    get { return Values[0]; }
    }

    #endregion
    }
    }

    #2
    Hello _abdul_hameed,

    Thanks for your post and welcome to the NinjaTrader forums!

    The code in the Plot0.Set() says to plot either at the value of 0 or 1 depending on the logic condition. On every OnBarUpdate() the logic is evaluated and will print a triangle either at the value of 0 or at the value of 1.

    The reference to a [-1] bars ago index is incorrect, a -1 would refer to a future bar. To refer to a previous bar use [1]

    If your goal is to plot a triangle only when the condition Low[0] > High[1] is true then you would want to write your condition as:

    if (Low[0] > High[1])
    {
    Plot0.Set(Low[0]); // plot a triangle on the low of the current bar
    }


    If you want to offset the triangle from the low of the bar you could change to Plot0.Set(Low[0] - 3 * TickSize); // plot triangle 3 ticks below low of the bar.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by elirion, Today, 09:32 PM
    0 responses
    2 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by cre8able, Today, 09:15 PM
    1 response
    5 views
    0 likes
    Last Post bltdavid  
    Started by cummish, Today, 08:43 PM
    0 responses
    12 views
    0 likes
    Last Post cummish
    by cummish
     
    Started by Option Whisperer, Today, 07:58 PM
    4 responses
    21 views
    0 likes
    Last Post Option Whisperer  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    13 responses
    87 views
    0 likes
    Last Post ETFVoyageur  
    Working...
    X