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

reference IFibonacciRetracements fibRetracementsLongs

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

    reference IFibonacciRetracements fibRetracementsLongs

    Scenario: I have drawn a FibonacciRetracement previously. I want to change the EndTime parameter later based on some program logic condition being met.

    Question: Can I reference the IFibonacciRetracements so i can change only the EndTime parameter of an existing drawobject or do I need to redraw the FibonacciRetracement again? Or can I use DrawObjects to get the reference?

    I would hope to change only that one attribute instead of save all the parameters to redraw it again later.
    Last edited by ct; 07-19-2019, 08:16 PM.

    #2
    Hello ct,

    Thanks for your post.

    Yes, you can change only the one parameters and the fib will be redrawn using that along with the other properties that you did not change.

    here is a quick example you can test with (on live or market replay data)

    Note that I declared the object in the variables region as private at the class level so I can access the properties more easily.

    Once the data is live, the fib is drawn on the first bar close back 10 bars. Then, 5 bars later the fib is then drawn to the current bar as EndBarsAgo is all I changed.

    Code:
            #region Variables
                private bool doitonce = true;
                private int startbar;
                private IFibonacciRetracements fibRetracements;
            #endregion
    
            protected override void Initialize()
            {
                Overlay                = true;
            }
    
            protected override void OnBarUpdate()
            {
                if (Historical) 
                    return;  // wait until live data
    
                if (!Historical && doitonce)  // draw on close of first live bar once.
                {
                    fibRetracements = DrawFibonacciRetracements("tag1", true, 10, Low[10], 0, High[0]);
                    doitonce = false;
                    startbar = CurrentBar;   // save the start bar
                }
    
                if (CurrentBar - startbar == 5 && fibRetracements != null )
                {
                    fibRetracements.EndBarsAgo = 0;   // set the fib to the current bar
                }    
            }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul

      Thanks.

      Will this allow me to save or reference "fibRetracements" outside of a method/procedure/subroutine or on a return to that method after having exited?
      private IFibonacciRetracements fibRetracements; <--- I think this is all I was lacking. Duh. Cheers

      Comment


        #4
        Hello ct,

        Thanks for your reply.

        I believe that will be the case when you create the variable/object at the class level.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul

          Got it. Give yourself a gold start from me.

          And thanks for the prompt reply. Much appreciated.

          Cheers

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Waxavi, Today, 02:10 AM
          0 responses
          4 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          9 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Working...
          X