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

Lookup Bars Question

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

    Lookup Bars Question

    I was just curious if anyone might know how I could look back in the last say 50 bars from whatever current price where the 3 is on my chart Here's a chart, I need to get the value for #3 level.

    How would or could you do it? Thanks!!

    https://gyazo.com/465aaf1fda020e0b1051f9a118c5efbd
    Last edited by clubfoot; 09-13-2016, 04:11 PM.

    #2
    The easiest way I can think to say it would be ...

    Show me the last 3 instances of a price change from current bar's value and then setting that value on the last one to whatever I want to make it usable.

    Any ideas?

    Comment


      #3
      Hello clubfoot, and thank you for your question.

      For this kind of strategy, you need some kind of threshold you can cross to mark off sections. One popular threshold is an SMA (simple moving average). Your threshold can be either a single value, or a DataSeries.

      However you define your threshold, you could collect crossover indices in a System.Collections.Generic.List object like this :

      First remember to initialize like this :

      Code:
      private System.Collections.Generic.List<int> myList;
      
      protected override void Initialize()
      {
          myList = new System.Collections.Generic.List<int>();
      Then we use it like this :

      Code:
      if (CrossAbove(Close, threshold, lookbackPeriod) || CrossBelow(Close, threshold, lookbackPeriod))
      {
          myList.Add(CurrentBar);
      }
      You would then be able to retrieve the index of the bar 50 before the 3rd most recent crossover like this :

      Code:
      int oldBar = CurrentBar - myList[2] + 50;
      Here is some publicly available MSDN documentation on System.Collections.Generic.List

      https://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

      And here is some documentation on CrossAbove . CrossBelow has a similar method signature.

      http://ninjatrader.com/support/helpG...crossabove.htm

      Finally, here is some documentation on CurrentBar .

      http://ninjatrader.com/support/helpG...currentbar.htm

      Please let us know if there are any other ways we can help.
      Last edited by NinjaTrader_JessicaP; 09-14-2016, 08:26 AM.
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Thank you Jessica, that did it!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JTizz, Today, 03:32 PM
        1 response
        33 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by ebaydan777, Today, 02:41 PM
        1 response
        25 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by aligator, Today, 02:28 PM
        1 response
        25 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by daniel_weber8, Today, 01:21 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by jungsoohuh, Today, 12:07 PM
        1 response
        35 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Working...
        X