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

Issue with Multiple Time Frames

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

    Issue with Multiple Time Frames

    Hi

    I have a problem with multiple timeframes where a code which was running fine previously is giving errors now.

    I am running the code on 60 Minutes (primary) and trying to load Daily bars in the data (loaded in in the State.Configure).

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"My Strategy 1";
    Name = "MyStrategy1";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    IsSuspendedWhileInactive = true;
    Type = @"C0";
    SmaParam = 10;
    AtrParam = 10;
    Multiplier = 0.7;
    LagParam = 5;
    AddPlot(Brushes.Orange, "MyLine1");
    AddPlot(Brushes.Orange, "MyLine2");
    AddPlot(Brushes.Orange, "MyLine3");
    }
    else if (State == State.Configure)
    {
    Print("Reached State.Configure");
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    Print("Reached State.DataLoaded");
    dlyStd = StDev(Inputs[1], 50); // uses the Daily Bars

    atr1 = AtrLine(AtrParam); // uses the 60 minute bar

    upper = new Series<double>(this, MaximumBarsLookBack.Infinite);
    lower = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }
    }

    I get an error when I try to add the indicator to a chart with 60 Minute data on CL 08-2019, with 350 days loaded up:

    "'MyStrategy1 tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load CL 08-19 Nymex: 60 Minute"

    I don't know why I am getting this error. I am loading the Daily data on the State.Configure, and why is the error saying it "Attempted to load CL 08-19 Nymex: 60 Minute" instead of saying that it attempted to load the Daily data?

    Other indicators that don't use multi-timeframes seem to be working alright.

    I also noticed that the Print line that prints "Reached State.Configure" is printed twice, whereas the documentation says that "State.Configure" is called only once. https://ninjatrader.com/support/help...tatechange.htm

    ----

    New update: I removed the additional time-frame data, and I still get the error: "'MyStrategy1' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load CL 08-19 Nymex: 60 Minute.

    With the additional time-frame data removed, the plot is displayed. However, the error does not go away. I think it could be something to do with the new Series<double> code.

    Any ideas why this is happening?
    Last edited by uday12; 07-07-2019, 02:18 PM.

    #2
    Hello uday12,

    The error is indicating that one of the indicators being called has AddDataSeries() but the host script is not also adding that same data series.

    From the help guide:

    "Should your script be the host for other scripts that are creating indicators and series dependent resources in State.DataLoaded, please make sure that the host is doing the same AddDataSeries() calls as those hosted scripts would. For further reference, please also review the 2nd example below and the 'Adding additional Bars Objects to NinjaScript' section in Multi-Time Frame & Instruments"



    I see AtrLine is called in this script. Does that script have AddDataSeries() in it?
    Are there other indicators called by this script?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      Is there any way around not loading the same dataeries as a called indicator is loading?
      I'm trying to use a vendors indicator in a strat & it's using different dataseries dynamically, there's no way I can hard code ahead of time what it's using.
      Why is this happening in NT8 & wasn't a problem in NT7?

      Comment


        #4
        Hello saturntd,

        In this case adding the series is a requirement now in NT8 due to the changes in NinjaScript. A hosted script or the indicator may add data, and if it does the host or strategy also needs to append the same series to use it in code.

        Generally this is not an issue as it is not expected for any item to load data dynamically, it should always be known ahead of time what series are being used. If the item being used is adding series dynamically that is a situation which is documented and known to be inconsistent so it would not be suggested to do this. I would not suggest trying to utilize this item from code, even if you add the correct series there are likely situations where it may fail to load correctly due to the dynamic nature.

        Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.

        Please let me know if I may be of additional assistance.
        Last edited by NinjaTrader_Jesse; 08-09-2019, 11:04 AM.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        14 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        11 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        6 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        244 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        387 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X