Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing additional data series into added indicator

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

    Passing additional data series into added indicator

    Hello,

    I'm trying to pass an additional daily data series on CL into the Range indicator from the NT8 library and store the previous days value of Range at close as a basic double (RangePreviousDay).
    I'm using a trading range of 8:30am EST to 3:15pm EST and I want the value to be accessed at the start of the new day using 5 minute bars on my chart.

    So I have;

    private Range RangeDay;

    ...

    private double RangePreviousDay;


    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    RangeDay = Range(Values[1]);


    ...
    ....
    protected override void OnBarUpdate()
    {
    RangePreviousDay = Range()[1];
    if(RangePreviousDay > 3)
    return;


    The goal is if previous days value of Range is >3, end onbarupdate.
    Can someone tell me why this is failing?

    Thanks very much.

    #2
    Hello AuroraAustralis,

    Thanks for your post.

    Anytime something is not working as expected you can check the "log" tab of the control center as it will contain any run-time errors messages. Additionally we recommend debugging by using print statements. You would want to print the values determined to understand if they make sense or are as expected. Tedious but it removes the mystery of why the code works as it does. We have a summarized debug reference here: https://ninjatrader.com/support/foru...ead.php?t=3418

    You are creating a local instance of the range indicator here: RangeDay = Range(Values[1]); however it needs to be located under State == State.DataLoaded and Values[1] needs to be replaced with BarsArray[1].

    In the OnBarUpdate() you have the statement RangePreviousDay = Range()[1]; which is using the range indicator but not the local range indicator, you should change this line to RangePreviousDay = RangeDay[1];

    Prior to that statement, you will need to add a CurrentBars check to avoid an indexing error. Basically, you make sure that enough day bars have loaded before accessing them. The first time the code checks RangePreviousDay = RangeDay[1]; it will likely error out because on the first bar loaded, there will not be a previous bar yet. Reference: https://ninjatrader.com/support/help...urrentbars.htm

    If your chart is using an RTH trading hours session then you can use the IsFirstBarOfSession bool as the trigger to then obtain the prior day range. Reference: https://ninjatrader.com/support/help...rofsession.htm

    As you have added a dataseries your script has become a multi time frame script and there are additional considerations needed to either isolate by the bars in progress or otherwise account for which bars object is calling the OnBarUpdate(). We highly recommend a review of: https://ninjatrader.com/support/help...nstruments.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Island_Boy_Trading, Today, 07:39 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by cmarkb, Today, 07:19 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by wjadevries, Today, 03:29 AM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by Oracletrades, Yesterday, 09:10 PM
    1 response
    119 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by ginx10k, Today, 07:04 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X