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 Duration

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

    Swing Duration

    Platforn NT 7.0.0.18

    I would like to calculate the 'duration' (in number of bars) of a swing.
    On a swing low, I have the current low and I have saved the previous high.

    Subtracting one from the other gives me a weird number...and converting it
    to 'int' doesn't seem to help.
    swing_duration =Math.Abs(Convert.ToInt32(curHigh - curLow));

    What did I miss?

    Thanks..............

    #2
    Hi photog53,

    Can you please provide the code snippets you are using for curHigh and curLow
    TimNinjaTrader Customer Service

    Comment


      #3
      Certainly.....(I am using the ZigZag code 'renamed' to another indicator).

      I capture the highs and lows on each swing into a 'hold variable'.
      holdLow=currentZigZagLow;
      holdHigh=currentZigZagHigh;
      before ZigZag resets the value for a new swing.

      These are valid high/lows because my "tick" swing calculation for the number of ticks in each swing is working perfectly....
      tickswingdn = Math.Abs(Convert.ToInt32(Math.Round((holdHigh - currentZigZagLow) / TickSize, 0, MidpointRounding.AwayFromZero)));
      tickswingup = Math.Abs(Convert.ToInt32(Math.Round((holdLow - currentZigZagHigh) / TickSize, 0, MidpointRounding.AwayFromZero)));

      The only thing that eludes me is how to use this info
      (to get the 'number of bars' in the swing....and the number of bars back from 'CurrentBar' that the swing occurred.

      Thanks.........

      Comment


        #4
        Hi photog53,

        Have you considered accessing with...
        Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)

        Described here - http://www.ninjatrader-support.com/H...helpguide.html

        Perhaps you can change the "instance" value, and compare to see when one swing started an another began?
        TimNinjaTrader Customer Service

        Comment


          #5
          I will take a look at that......

          but I really want to sync the swing with ZigZag calculations.

          It seems like I should be able to save a bar value (Ex: Low[0]) from some point back,
          and later subtract it from CurrentBar to get an integer value with the number of bars between the two of them. Is there no quick, easy way to calculate the number of bars between two points using saved 'double values' of the bar??

          Comment


            #6
            photog53,

            It is not that simple. The two indicators you are using repaint themselves. Meaning, at some point in the future it will go ahead and redraw its old values to match what it newly saw. That is why both of the indicators look so good, because it uses new data to change what the indicator looked like in the past. There's no real way you can "sync" the two. They both decide to repaint at different times depending on what newer data tells it what to do.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              I understand.....and I really do appreciate your taking the time to help me understand the concept in addition to the specific coding issue.



              I will do two things.

              1. I will take your suggestion and change my approach for the "swing" to use your
              original post. (thanks !!)

              2. In a slightly different context........
              I would like to calculate the number of bars between a saved point in the past
              and 'CurrentBar'. I have a saved value ( double holdval = High[0] ) from a past
              point...and I want to calculate the number of bars between CurrentBar and that point.

              How would I do that?


              Thanks again for the help...;.(as always Ninja Support is outstanding).

              Comment


                #8
                Hi photog53,

                If you know the bar number, you can simply subtract it from the CurrentBar.

                Otherwise, if you want to store a value, like CurrentBar or High[0] you can either...
                1. Set it as a variable, then use a bool to ensure it won't be set again
                2. Create a data series to access it later - http://www.ninjatrader-support.com/H...tml?Overview24
                TimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by samish18, Today, 01:01 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by WHICKED, Today, 12:56 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by cre8able, Today, 01:16 PM
                0 responses
                3 views
                0 likes
                Last Post cre8able  
                Started by chbruno, 04-24-2024, 04:10 PM
                2 responses
                47 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by WHICKED, Today, 12:45 PM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X