Announcement

Collapse
No announcement yet.

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 AHamxa, Today, 11:24 PM
    0 responses
    5 views
    0 likes
    Last Post AHamxa
    by AHamxa
     
    Started by AHamxa, Today, 11:22 PM
    0 responses
    4 views
    0 likes
    Last Post AHamxa
    by AHamxa
     
    Started by AHamxa, Today, 11:17 PM
    0 responses
    4 views
    0 likes
    Last Post AHamxa
    by AHamxa
     
    Started by Spiderbird, 07-27-2018, 07:52 PM
    12 responses
    9,240 views
    2 likes
    Last Post Mountain_cast  
    Started by chrischongpdx, Today, 09:39 PM
    0 responses
    7 views
    0 likes
    Last Post chrischongpdx  
    Working...
    X