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

Fibonacci Retracements

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

    Fibonacci Retracements

    Could any of the seasoned NT programers tell me why the code listed below does not draw any object on my chart ?

    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Fib Retracements
    /// </summary>
    [Description("Fib Retracements")]
    [Gui.Design.DisplayName("Fib2")]
    public class Fib2 : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // 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.Orange, PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (Close[0] > Close[1])
    DrawFibonacciRetracements("Lines" + CurrentBar, 1, High[0], 0, Low[0]);
    else if (Close[0] <= Close[1])
    DrawFibonacciRetracements("Lines" + CurrentBar, 1, Low[0], 0, High[0]);
    }

    Thanks.

    #2
    Any error messages in your log tab?

    Do you want a lot of fib objects on your chart? The way you wrote it is what you will get, or do you only every want one to be visible? If the latter, use the same "tag" value insread of making it unique by adding the CurrentBar to the tag name.
    RayNinjaTrader Customer Service

    Comment


      #3
      Actually, I see the issue which will be displayed in the Log Tab.

      Add:

      if (CurrentBar < 1)
      return;

      Your are accessing Close[1] on the 1st bar of the chart where 1 bar ago does not yet exist.
      RayNinjaTrader Customer Service

      Comment


        #4
        Now it works great, thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Brevo, Today, 01:45 AM
        0 responses
        2 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        3 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        238 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        4 views
        0 likes
        Last Post oviejo
        by oviejo
         
        Working...
        X