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

Custom Bar Type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom Bar Type

    [I am aware coding of custom bar types is unsupported; with that understood, I am asking for any directional guidance you can provide for the following. Thanks!]

    I am coding a custom range bar type that will close each bar only if a simple indicator condition is met. The indicator is run with CalculateOnBarClose = false.

    The challenges I face are constructing and assigning values to an indicator from the NinjaTrader.Data namespace (rather than from NinjaTrader.Strategy or NinjaTrader.Indicator).

    From within the range bar’s Add() method, which is called tick by tick, I can construct the indicator, as follows:
    Code:
    NinjaTrader.Indicator.MyIndicator myIndicator = NinjaTrader.Indicator.MyIndicator();
    I can then assign the indicator’s period to this object, as follows:
    Code:
    myIndicator.Period  = this.Period;
    I can then create a DataSeries, as follows:
    Code:
    DataSeries barCloses = new DataSeries(myIndicator);
    I can then use bars, the overloaded Bars object, to assign values to this DataSeries, and to then assign this IDataSeries DataSeries to the indicator, as follows:
    Code:
    If (bars.Count > 1)
    {[INDENT]for (int i = 0; 1 < bars.Count; i++)
    {[INDENT]Bar bar = (Bar) bars.Get(i);
    barCloses.Set(bar.Close);[/INDENT]
    }
    myIndicator.RequiredDataSeries = barCloses;[/INDENT]
    }
    Then, later on in the Add() method, I access the indicator values I need (which I have made a public property of the indicator) as follows:
    Code:
    double myIndicatorAPublicProperty = myIndicator.APublicProperty;
    The above syntax is all accepted by the compiler.

    But the code doesn’t do as I expect it to!

    I suspect I am not constructing (or loading) the indicator object correctly (although of course there could also be other problems!).

    Can you see anything obviously wrong with the above approach?

    Please don't respond simply that this is not supported ...

    Many thanks.

    #2
    Hi AnotherTrader,

    Thank you for your post.

    You won't be able to call an indicator in a bar type that way, as a bar type is loading first and there is no data for the indicator to calculate off of.

    You would need to include the actual calculation of the indicator in the bar type rather than calling it.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sidlercom80, 10-28-2023, 08:49 AM
    167 responses
    2,260 views
    0 likes
    Last Post jeronymite  
    Started by warreng86, 11-10-2020, 02:04 PM
    7 responses
    1,361 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Perr0Grande, Today, 08:16 PM
    0 responses
    5 views
    0 likes
    Last Post Perr0Grande  
    Started by elderan, Today, 08:03 PM
    0 responses
    9 views
    0 likes
    Last Post elderan
    by elderan
     
    Started by algospoke, Today, 06:40 PM
    0 responses
    10 views
    0 likes
    Last Post algospoke  
    Working...
    X