• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Bars object details

  • Filter
  • Time
  • Show
Clear All
new posts

    Bars object details

    I found myself creating 2 methods, that are doing logically completely the same thing
    but on 2 different objects
    • One works with the strategy
    • Second works with the Indicator

    For example, let's have a method that find the highest bar in the range.

    Method, that works with indicator is
    public int GetIndexOfTheHighestBar(Indicator indicator, int fromIndex, int toIndex) { ... }

    Method that works with strategy is:
    public int GetIndexOfTheHighestBar(Strategy strategy, int fromIndex, int toIndex) { ... }

    The logic inside both is exactly the same, so ideally, we would not need to have 2 methods, just provide Bars instance, that will be processed inside the method.
    Is it OK according to public API or should I use some another approach?

    Finally, it could look like:

    public int GetIndexOfTheHighestBar(Bars bar, int fromIndex, int toIndex) { ... }

    I expect, this code can be called from Strategy and Indicator the same

    Bars primaryBars = BarsArray[0]
    int index = GetIndexOfHighestBar(primaryBars, 0, 100);  // returns index of highest bar within last 100 bars

    Problem is, that I didn't find some good documentation about usage of the Bars class.
    Help talks about 6 properties/methods that are not of my primary interest:
    • BarsSinceSession
    • GetBar
    • GetDayBar
    • FirstBarOfSession
    • PercentComplete
    • Session
    • TickCount

    On the other hand, I found there are present many other methods, that look very useful for accessing the dataseries:
    • GetOpen(index),
    • GetHigh(index),
    • GetLow(index),
    • GetClose(index)
    • GetVolume(index)

    These could be most useful for accessing the bars and their OHLC(V) values.
    Then Bars object could be used for accessing the bars-data without locking to Strategy/Indicator instance.

    Can these public methods of the Bars object be used freely, or is there any reason, they are not in documentation? I find them to be quite important to be mentioned in the docs, to see a big picture.
    Last edited by misova; 05-22-2015, 05:39 AM.

    Hello misova,

    Thank you for your post.

    In NinjaTrader 7 these are considered unsupported and thus undocumented.

    NinjaTrader 7 offers the UserDefinedMethods, but these are separate for both Strategies and Indicators: http://www.ninjatrader.com/support/h...ed_methods.htm

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service


      Thank you,
      I understand that unsupported policy

      But could you suggest some way how to approach the problem of duplication of same code for Strategy and for Indicator ? (example in 1st post)

      The methods just need to iterate the bars OHLC values , so the duplication of the same code is quite ugly and hard to maintain.
      Last edited by misova; 05-22-2015, 06:46 AM.


        Hello misova,

        Thank you for your response.

        Create the method in the UserDefinedMethods for strategies and again for indicators. You would then only have the code in two places. Otherwise, there would not be any means to have one source for the method in NinjaTrader. You could potentially create the method in one indicator and have it produce the value as a plot or exposed variable and then just call that indicator from any other indicators or strategies.

        For information on exposing variables please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=4991

        Please let me know if I may be of further assistance.
        Patrick H.NinjaTrader Customer Service


        Latest Posts


        Topics Statistics Last Post
        Started by zulok, Today, 05:02 PM
        0 responses
        1 view
        Last Post zulok
        by zulok
        Started by Andreas M., Today, 04:42 PM
        0 responses
        Last Post Andreas M.  
        Started by sidlercom80, Today, 12:29 PM
        2 responses
        Last Post fx.practic  
        Started by itrader46, Today, 02:49 PM
        3 responses
        Last Post NinjaTrader_ChelseaB  
        Started by m94306, Today, 03:01 PM
        1 response
        Last Post NinjaTrader_Heath