• 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.

Announcement

Collapse
No announcement yet.

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.
    Patrick H.NinjaTrader Customer Service

    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.
        Patrick H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by indy73, Today, 10:52 PM
        0 responses
        3 views
        0 likes
        Last Post indy73
        by indy73
         
        Started by martyn73, Today, 07:04 PM
        0 responses
        5 views
        0 likes
        Last Post martyn73  
        Started by sergey_z, Today, 02:56 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by samir, Today, 02:46 PM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by neoikon, Today, 02:24 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X