• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Sh00tHerMcGavin, Today, 07:39 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post Sh00tHerMcGavin  
                    Started by Mberg, Today, 05:13 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post Mberg
                    by Mberg
                     
                    Started by Barry Milan, Today, 01:33 PM
                    2 responses
                    10 views
                    0 likes
                    Last Post marcus2300  
                    Started by NW Trader, Today, 03:42 PM
                    2 responses
                    8 views
                    0 likes
                    Last Post NW Trader  
                    Started by ralett, Today, 01:42 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ShawnB  
                    Working...
                    X