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

Indicator on Primary Data Series vs Secondary Data Series

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

    Indicator on Primary Data Series vs Secondary Data Series

    Hi,

    I've a strategy running with the below format. If I've a strategy with multiple data series. Inside else if (State == State.DataLoaded) do I need to call the indicator with the below example1 or example 2?

    Example 1: CurrentDayOHL1 = CurrentDayOHL(Close);
    Example 2: CurrentDayOHL1 = CurrentDayOHL(Closes[0]);

    I've attached a small portion of the script with 2 options highlighted in red. Option 1 shows without the "s[0]", and Option 2 with it. All the indicators that I've are on the Primary Data Series, so my assumption is that all of them will be one way or the other.

    Option 1:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Name";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 3;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    AddVolumetric(Instrument.FullName, BarsPeriodType.Minute, 1440, VolumetricDeltaType.BidAsk, 1);
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    ClearOutputWindow();
    VOL1 = VOL(Close);
    VolumeUpDown1 = VolumeUpDown(Close);
    CurrentDayOHL1 = CurrentDayOHL(Close);
    VWAP11 = VWAP1(Close, 1);
    CumDelta1 = CumDelta(Close, Brushes.Red, Brushes.LimeGreen, Brushes.Black, 1, 0, false);

    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 60 || (BarsInProgress == 1 && BarsArray[1] == null))
    return;

    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType1 = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

    if (barsType1 == null)
    return;

    try
    {
    // Condition
    }
    catch{}


    Option 2:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Name";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 3;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    AddVolumetric(Instrument.FullName, BarsPeriodType.Minute, 1440, VolumetricDeltaType.BidAsk, 1);
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    ClearOutputWindow();
    VOL1 = VOL(Closes[0]);
    VolumeUpDown1 = VolumeUpDown(Closes[0]);
    CurrentDayOHL1 = CurrentDayOHL(Closes[0]);
    VWAP11 = VWAP1(Closes[0], 1);
    CumDelta1 = CumDelta(Closes[0], Brushes.Red, Brushes.LimeGreen, Brushes.Black, 1, 0, false);

    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 60 || (BarsInProgress == 1 && BarsArray[1] == null))
    return;

    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType1 = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

    if (barsType1 == null)
    return;

    try
    {
    // Condition
    }
    catch{}​

    #2
    Hello AgriTrdr,

    Thank you for your post.

    If you specifically want to use the close series, you can use the second version. You could also use BarsArray[0]. Please see this section of our help guide:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate,

      Thanks for your response. Would all of them be using the second example with "Closes[0]" since all of them are with Primary Data Series?

      Also, just as knowledge, BarsArray[0] would go where if I wanted to use that route?

      Thanks

      Comment


        #4
        Hello AgriTrdr,

        Thank you for your reply.

        Closes[0] would refer specifically to the Close series of the primary bars.

        BarsArray[0] is just a specific way to refer to the primary bars series, you'd use that in place of using Closes[0].

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate,

          So in the below example, would BarsArray[0] would be referred the correct way:

          ClearOutputWindow();
          VOL1 = VOL(BarsArray[0])[0];
          VolumeUpDown1 = VolumeUpDown(BarsArray[0])[0];
          CurrentDayOHL1 = CurrentDayOHL(BarsArray[0])[0];
          VWAP11 = VWAP1(BarsArray[0], 1)[0];
          CumDelta1 = CumDelta(BarsArray[0], Brushes.Red, Brushes.LimeGreen, Brushes.Black, 1, 0, false)[0];

          Thanks

          Comment


            #6
            Hello AgriTrdr,

            Thank you for your reply.

            Not quite, if you try to refer to the current bar value there you'll hit errors, so you want to eliminate the bars ago:

            Code:
            ClearOutputWindow();
            VOL1 = VOL(BarsArray[0]);
            VolumeUpDown1 = VolumeUpDown(BarsArray[0]);
            CurrentDayOHL1 = CurrentDayOHL(BarsArray[0]);
            VWAP11 = VWAP1(BarsArray[0], 1);
            CumDelta1 = CumDelta(BarsArray[0], Brushes.Red, Brushes.LimeGreen, Brushes.Black, 1, 0, false);

            Please let us know if we may be of further assistance to you.​
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Thanks this is good info to know.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NM_eFe, 04-30-2024, 06:14 AM
              5 responses
              30 views
              0 likes
              Last Post NM_eFe
              by NM_eFe
               
              Started by Jonker, 04-27-2024, 01:19 PM
              2 responses
              20 views
              0 likes
              Last Post Jonker
              by Jonker
               
              Started by Max Baxter, 03-07-2019, 09:20 PM
              8 responses
              266 views
              0 likes
              Last Post Ymcapital  
              Started by Felix Reichert, 04-26-2024, 02:12 PM
              9 responses
              52 views
              0 likes
              Last Post Felix Reichert  
              Started by AaronKoRn, 04-27-2024, 09:49 PM
              3 responses
              31 views
              0 likes
              Last Post AaronKoRn  
              Working...
              X