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

Swing Positions

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

    Swing Positions

    Is there a way to permanently label a swing? Using the "instance" isn't allowing enough time for any logic to be performed before it produces a new instance and changes the count.

    #2
    Hello Hamrall,

    Thanks for your note.

    When you say permanently label a swing, are you drawing text on the chart with DrawText() and this is being overwritten repeatedly?

    If so, use a bool that is reset once per bar to prevent the text from being overwritten.

    For example:

    In #region Variables:
    private bool oncePerBar = false;

    In OnBarUpdate():
    if (FirstTickOfBar == true)
    {
    oncePerBar = false;
    }
    if (oncePerBar == false)
    {
    DrawText("myText"+CurrentBar, "my text", 0, High[0]+4*TickSize, Color.Black);
    oncePerBar = true;
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      No not exactly. Using the "Swing" indicator if I were to set say 5 different swings using the instance of 0,1,2,3,4 and try to perform some type of logic say "is swing0 > swing3" it would be fine but if a new swing came then the instances would update by 1 so instance 0 would now be instance 1 and so fourth.

      Comment


        #4
        Hello Hamrall,

        By default the Swing indicator should only update once per bar (COBC is true by default).

        Meaning a new swing should not appear until the bar closes and a new bar opens.

        Do you have Calculate on bar close set to false?

        Are you finding the Swing is set more than once per bar?


        If you want to save the value of the swing, save this to a variable and you will be able to call this value anytime.

        For example:

        private double savedSwingValue = 0;

        savedSwingValue = Swing(5).SwingHigh[0];

        Print(savedSwingValue);


        Also, keep in mind that the swing sets values historically. So at any time the Swing could change in the historical data. This is just how the swing indicator works.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I'm trying to save the instance not the double. So I can compare a swing to another swing based on when they occurred(before or after each other). So if I try to get the bar of the second most recent swing I use instance 2 (Swing().SwingHighBar(0,2,CurrentBar) and the most recent is (Swing().SwingHighBar(0,1,CurrentBar). Now if I want to see if the most recent swing is higher than the previous swing and a new swing high comes after the (Swing().SwingHighBar(0,1,CurrentBar) then this swing would now be (Swing().SwingHighBar(0,2,CurrentBar). Hopefully I am explaining this right

          Comment


            #6
            Hello Hamrall,

            Instead of saving the value, save the bars ago number to an int.

            So when you detect the swing, set the bars ago value to a variable.

            private int previousSwingBarsAgo = 0;

            prevousSwingBarsAgo = CurrentBar;
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              If I save the barsago number of the most recent swing wont the next swing(now the new most recent) be a different bar?

              Comment


                #8
                Hi Hamrall,

                You would be saving the CurrentBar number.

                When you find how many bars ago this was use CurrentBar - previousSwingBarsAgo. This will give you the amount of bars ago that bar was.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  If I do it this way I get an error on calling 'OnBarUpdate' everytime if I try to do any sort of calculation with the bars

                  Comment


                    #10
                    I found my mistake. Thank for your help!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by trilliantrader, 04-10-2024, 09:33 PM
                    7 responses
                    25 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by traderqz, Today, 12:06 AM
                    5 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by Mongo, Today, 11:05 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post Mongo
                    by Mongo
                     
                    Started by guillembm, Today, 11:25 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post guillembm  
                    Started by Tim-c, Today, 10:58 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X