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

Getting Last Swing Low Value

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

    Getting Last Swing Low Value

    Hi, I'm working on a strategy that uses swing values and the correct swing high value prints which was taken from https://ninjatrader.com/support/help...html?swing.htm however when converted to the swing low value it's different for just about every bar.

    Swing high - swinghigh0 = High[Math.Max(0, Swing1.SwingHighBar(0,1,100))];
    Swing Low - swinglow0 = Low[Math.Min(0, Swing1.SwingLowBar(0,1,100))];

    You can see from the picture that the swing low value appears to be constantly changing and I'm not sure what's wrong as the swing high values match the chart.
    Attached Files

    #2
    Hello itsthefriz,

    Thanks for your post.

    You need to change Math.Min to Math.Max in this line: Swing Low - swinglow0 = Low[Math.Min(0, Swing1.SwingLowBar(0,1,100))];

    What is happening is that Math.Min is choosing the Minimum of 0 or the bars ago, or if no swing found it would return a -1. A -1 would lead to a bar index error.

    Math.Max is used to return either 0 or the bars ago but would not let the -1 pass through and this would prevent an index error, so the correct usage here is:
    Swing Low - swinglow0 = Low[Math.Max(0, Swing1.SwingLowBar(0,1,100))];
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Ah, okay, I think I've got it... Math.Min is constantly returning the 0 bar because it is minimum bar of the given index rather than the last swing value which is found using Math.Max which returns the number of bars ago the swing occurred, if that's right?

      Comment


        #4
        Hello itsthefriz,

        Thanks for your reply.

        Correct, except that could return -1 because the swing indicator will return -1 if no swing is found and in that case, you would generate a bar index error and your script would stop.

        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NUVERSA, Today, 10:08 AM
        0 responses
        5 views
        0 likes
        Last Post NUVERSA
        by NUVERSA
         
        Started by truepenny, Today, 03:45 AM
        3 responses
        20 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Started by truepenny, Today, 03:59 AM
        5 responses
        21 views
        0 likes
        Last Post truepenny  
        Started by nicthe, Yesterday, 07:38 AM
        7 responses
        29 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by trilliantrader, Today, 09:34 AM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X