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

Multiple time frames and UserDefinedMethod

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

    Multiple time frames and UserDefinedMethod

    Hi,

    I have the following code

    int barOffset = barOffset = (Historical || CalculateOnBarClose) ? 0 : 1;
    Print(barsBack + " " + open[barOffset] + " " + high[barOffset] + " " + low[barOffset] + " " + close[barOffset] + " " + close[0] + " " + time[barOffset] + " " + Time[0]);

    I am passing in several IDataSeries and an ITimeSeries and all the values are as expected except Time[0].

    I thought that would give me the current time of the primary bar whereas it is giving me the time the current secondary bar will end.

    I put the test indicator, which calls a UserDefinedMethod on a 5 tick range bar chart (6E). Because the times of the data series won't be even multiples of each other (3 minutes and 5 tick range), I want to make 100% certain I understand the nuances of how the data is handled.

    So if it is 1344 and the last 3 minute bar is 1342, as expected, I get the OHLC of that bar along with the time 1342.

    But as I mentioned above, I expected to get the time of the current bar in the range chart where the indicator is.

    Any idea where I have the misunderstanding? Alternatively, if I wanted the time from a given bar on the primary chart, how would I code that?
    Last edited by ScottB; 03-16-2011, 02:10 PM.

    #2
    Hi Scott,

    Unless you have that within a BarsInProgress check, it will return Time[0] for all series whenever there is a bar update there.

    If you only want to check within context of first series, add:

    if (BarsInProgress == 0)
    Print(barsBack + " " + open[barOffset] + " " + high[barOffset] + " " + low[barOffset] + " " + close[barOffset] + " " + close[0] + " " + time[barOffset] + " " + Time[0]);

    Series relate to other series differently, depending on whether accessed from historical or real time context. This statement can help you see this for the first two series:

    if (BarsInProgress == 0)
    Print("Primary Series: " + Time[0] + " Secondary Series: " + Times[1][0]);

    There are a couple diagrams that break this down in more detail here:
    How Bar Data is Referenced
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan, I suspect that is the issue since I called the method (which is defined in UserDefinedMethods) from the test indicator within a BarsInProgressCheck equal to the second data series.

      If I understand this correctly, this is very good architecture in my opinion because it gives me a consistency within the method based on the context from which it is called.

      Because I called it from within a BarsInProgressCheck, that is the context; perfect.

      Thanks as always.

      Scott

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Austiner87, Today, 11:24 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by ETFVoyageur, 04-30-2024, 02:04 PM
      10 responses
      76 views
      0 likes
      Last Post ETFVoyageur  
      Started by Drone360x, Today, 10:27 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Salahinho99, Yesterday, 04:13 AM
      2 responses
      26 views
      0 likes
      Last Post Salahinho99  
      Started by truepenny, Today, 03:45 AM
      4 responses
      21 views
      0 likes
      Last Post truepenny  
      Working...
      X