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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      152 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      89 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      131 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      127 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X