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

Bars object details

Collapse
X
 
  • 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


    Code:
    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, 06:39 AM.

    #2
    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.

    Comment


      #3
      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, 07:46 AM.

      Comment


        #4
        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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,605 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        8 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        4 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        13 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X