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 helpwanted, Today, 03:06 AM
    1 response
    7 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    7 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    385 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X