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

Accessing Chart Lookback Period

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

    Accessing Chart Lookback Period

    I want to set a variable in a custom indicator I'm working on which is the lookback period of the chart the indicator is loaded to.

    For example, on a 30 minute chart the "default" lookback period is 15 days. When I load my indicator to this chart, my variable would be set to 15.

    So, how can I access the current chart's lookback period in my indicator code?

    Thanks!

    #2
    Hello,

    So you want to use the number of bars on the chart to determine a variable in your system? There are probably a few ways to do this, but one way would be to count the number of bars on a chart using CurrentBar and use that as determine the variable value you want. You may want to use !Historical to wait until the chart is built.
    DenNinjaTrader Customer Service

    Comment


      #3
      Ben,

      What I am working on is an indicator which will gather bar by bar statistics, per each time period, for the specified chart lookback period. So i want to set up a a nested loop first for the chart lookback then loop by number of bars per day to gather up the data.

      For example, on a 30 minute regular trading hours chart , for the last 20 (or more) trading sessions I would gather the:

      High/Low range
      Open/Close range
      Volume


      Of each 30 minute period. Then run some basic stats like mean, median, mode, standard deviation, etc. of each DataSeries.

      So the 1st set of stats. would be for all Bar No. 1 series (9:30-10AM), 2nd set would be of all Bar No. 2 series (10-1030), and so on. Make sense?

      I currently am doing all of this basically by hand exporting and processing the data in Excel. I thought it would be worth a few days work coding it up to make it a bit faster, and could run the indicator on a chart and see the stats. in "real time".

      I wonder if anyone else has tackled this coding exercise? I haven't found any sort of statistics type of indicators like this anywhere (yet).

      I guess a simpler approach may be just to setup a couple of user input variables for "DaysLookback" and "BarsPerDay" for the looping.
      Last edited by Pepperdog; 12-19-2009, 08:13 PM.

      Comment


        #4
        Hello,

        I can't code it for you, but I would use a day change trigger using either DayOfWeek:

        Or DateTime.Now:

        You could also also use FirstBarOfSession:


        At any rate, any of these could be used to notify your system that it needs to do a calculation and draw text.

        Rather then have a set BarsBack or something variable, I would just gather "all bars" during a day. I say this because, some days may not have the same number of bars do to market openning and closing etc.

        Give it a try and post code snippets that you need help with.
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,771 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X