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

Keeping track of Highs and Lows

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

    Keeping track of Highs and Lows

    Programming question: In my new strategy, I'd like to keep track of the highs and lows made by an indicator. For example: Let's say that I'm using a set of Stochastics, and I want to keep track of the highs and lows made by the %K line (by measuring the slope to catch inflections, let's say.)

    I'd like to have some kind of array, or DataSeries, that I could refer to in the strategy. For example, let's say I have an array of "Lows", so I could see if I've been making higher lows.

    This seems like it should be straightforward, but then I had an "a-ha" moment: I'm comfortable creating my own custom indicators using DataSeries objects, but a DataSeries always adds a new value for every minute/candle/tick. If I have a series of 100 Tick bars, they may only contain, say, five highs and five lows.

    So I suppose, in general, my question becomes: I want to create a DataSeries/Array that only adds a new value occasionally and irregularly. Is this a problem?

    #2
    Hello pbailey19,

    Thank you for your post.

    There are multiple ways that you could accomplish this.

    You could have a variable that contains the current low, if there is a new lower low, you can add this value to a list (array) of low values then set the variable to that new low.
    http://www.dotnetperls.com/list

    You could also use LowestBar(Low, CurrentBar-1)[0]. The [0] would be the lowest low, [1] would be the second lowest low, etc.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Whoa! I didn't know that LowestBar (or HighestBar, I assume) would do that. I mean, I thought it was a single value, not an array/list. Of course, before I get too excited ... it sounds like it's sorting the highs and lows by value, instead of keeping them in order, chronologically. So I would always be getting an array of sorted lows and highs.

      Yeah, I think maintaining a list of highs and lows is the way to go, for me. Unless there's a way to keep LowestBar and HighestBar from sorting?

      Comment


        #4
        Hi pbailey19,

        LowestBar will return a bars ago value of where that bar was.
        http://www.ninjatrader.com/support/h.../lowestbar.htm

        To print the low from using that you would call Low[Lowestbar(Low, CurrentBar-1)[0]].

        That would return the price of the lowest low.

        However, it looks like it would be better for you to store the lows to a list.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by pbailey19 View Post
          Programming question: In my new strategy, I'd like to keep track of the highs and lows made by an indicator. For example: Let's say that I'm using a set of Stochastics, and I want to keep track of the highs and lows made by the %K line (by measuring the slope to catch inflections, let's say.)

          I'd like to have some kind of array, or DataSeries, that I could refer to in the strategy. For example, let's say I have an array of "Lows", so I could see if I've been making higher lows.

          This seems like it should be straightforward, but then I had an "a-ha" moment: I'm comfortable creating my own custom indicators using DataSeries objects, but a DataSeries always adds a new value for every minute/candle/tick. If I have a series of 100 Tick bars, they may only contain, say, five highs and five lows.

          So I suppose, in general, my question becomes: I want to create a DataSeries/Array that only adds a new value occasionally and irregularly. Is this a problem?
          You will need to use either an ArraList or a generic List.

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello pbailey19,

            Thank you for your post.

            There are multiple ways that you could accomplish this.

            You could have a variable that contains the current low, if there is a new lower low, you can add this value to a list (array) of low values then set the variable to that new low.
            Create a new List, add elements to it, and loop over its elements with for and foreach.


            You could also use LowestBar(Low, CurrentBar-1)[0]. The [0] would be the lowest low, [1] would be the second lowest low, etc.
            More about ...http://csharp.net-informations.com/collection/list.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by funk10101, Today, 12:02 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by GLFX005, Today, 03:23 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by nandhumca, Yesterday, 03:41 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by The_Sec, Yesterday, 03:37 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by vecnopus, Today, 06:15 AM
            0 responses
            1 view
            0 likes
            Last Post vecnopus  
            Working...
            X