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 ghoul, Today, 06:02 PM
    2 responses
    12 views
    0 likes
    Last Post ghoul
    by ghoul
     
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    44 views
    0 likes
    Last Post jeronymite  
    Started by Barry Milan, Yesterday, 10:35 PM
    7 responses
    20 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by AttiM, 02-14-2024, 05:20 PM
    10 responses
    180 views
    0 likes
    Last Post jeronymite  
    Started by DanielSanMartin, Yesterday, 02:37 PM
    2 responses
    13 views
    0 likes
    Last Post DanielSanMartin  
    Working...
    X