Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      567 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X