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

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 sidlercom80, 10-28-2023, 08:49 AM
    168 responses
    2,262 views
    0 likes
    Last Post sidlercom80  
    Started by Barry Milan, Yesterday, 10:35 PM
    3 responses
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by WeyldFalcon, 12-10-2020, 06:48 PM
    14 responses
    1,429 views
    0 likes
    Last Post Handclap0241  
    Started by DJ888, 04-16-2024, 06:09 PM
    2 responses
    9 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by jeronymite, 04-12-2024, 04:26 PM
    3 responses
    41 views
    0 likes
    Last Post jeronymite  
    Working...
    X