Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add DataSeries without if (State == State.Configure)

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

    Add DataSeries without if (State == State.Configure)

    I set varriables in Indicator. One of them is reference to ATR and looks like:

    double d = indicator.ATR(indicator.BarsArray[indicator.BarsInProgress], 14)[indicator.CurrentBars[indicator.BarsInProgress];

    The second variable is referenced to custom Indicator that have to load additiona 1 Second data.

    double = indicator.BV(indicator.BarsArray[indicator.BarsInProgress], 5)[indicator.CurrentBars[indicator.BarsInProgress];

    Code must work on diferent DataType, not only Second.

    I don't use construction like this:
    protected override void OnStateChange()
    {
    if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Second, 1);
    }
    }

    How to set BarsArray "1 Second "Data Type in my case?

    #2
    Hello zhiga,

    If you want additional series, its necessary to call AddDataSeries() in State.Configure. If an indicator is hosted by a host script, the host script also has to call all of the same AddDataSeries() calls the hosted symbiote does.

    "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​"


    "Note: To maximize data loading performance, any NinjaScript object (indicator or strategy as host) which references a multi-series indicator which calls AddDataSeries must include it's own calls to AddDataSeries(). For example, if the code above was included in an indicator, and that indicator was referenced in a NinjaScript strategy, then the hosting strategy will need to include the same calls to AddDataSeries(). When the strategy adds the additional Bars objects, the calls to AddDataSeries() within the indicator will be ignored. If the Bars objects are not added by the strategy in such cases, and error will be thrown in the Log tab of the Control Center that would read - "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state.""


    I don't think there is any way around it, you will need to call AddDataSeries() to add a 1 second series (in both the hosted symbiote indicator and host indicator).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello zhiga,

      If you want additional series, its necessary to call AddDataSeries() in State.Configure. If an indicator is hosted by a host script, the host script also has to call all of the same AddDataSeries() calls the hosted symbiote does.

      "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​"


      "Note: To maximize data loading performance, any NinjaScript object (indicator or strategy as host) which references a multi-series indicator which calls AddDataSeries must include it's own calls to AddDataSeries(). For example, if the code above was included in an indicator, and that indicator was referenced in a NinjaScript strategy, then the hosting strategy will need to include the same calls to AddDataSeries(). When the strategy adds the additional Bars objects, the calls to AddDataSeries() within the indicator will be ignored. If the Bars objects are not added by the strategy in such cases, and error will be thrown in the Log tab of the Control Center that would read - "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state.""


      I don't think there is any way around it, you will need to call AddDataSeries() to add a 1 second series (in both the hosted symbiote indicator and host indicator).
      Thank you, Chelsea.


      Is it possible to use EnterLong() or EnterShort() in Indicator?

      Comment


        #4
        Hello zhiga,

        Unfortunately no, EnterLong() and EnterShort() are strategy methods only.

        From an indicator you would need to submit all orders through the account with the addon approach using <Account>.CreateOrder() and <Account>.Submit().

        The example linked below demonstrates.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        589 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        342 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        555 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X