Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    83 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    45 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    65 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    57 views
    0 likes
    Last Post CarlTrading  
    Working...
    X