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

Calc on each x´th bar ONLY?!

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

    Calc on each x´th bar ONLY?!

    I´m trying to figure out how to make NT do calculations on each x'th bar ONLY. I can isolate each 3´rd bar this way;

    if
    (Bars.BarsSinceSession % 3 == 0)

    The problem is, NT gives the inbetween dataseries objects a zero value. Is there a way to avoid this?

    I realize I could add a second dataseries running at x3 (3 rather than 1 minute), but I´m trying to avoid that for now.

    //Fredrik

    #2
    Hi Frederik, this is correct if you don't set a value for the bars explicitly - we would advise to set one as other you could run into exceptions accessing dataseries values - working with the added series might be the easier way here.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand! Where do I go wrong in this basic example of multiseries times objects? I would expect this code to show a Close of the primary (TNA, 10 min) series and a Close of the secondary (TNA, 30 min). The only way I get the secondary to show is when primary is set to 30 min. Been playing around without luck.


      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Add(
      new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
      Overlay =
      false;

      Add(
      "TNA", PeriodType.Minute, 30);
      }
      protectedoverridevoid OnBarUpdate()
      {
      Plot0.Set(Closes[
      0][0]);

      if(BarsInProgress == 1)
      {
      Plot1.Set(Closes[
      1][0]*1.1); //.1 offset to avoid overlay
      }

      //Edit - sorry, I ment Close not SMA//
      Last edited by FREEN; 02-28-2011, 07:14 AM.

      Comment


        #4
        Hi Frederic, please try setting both plots (BarsArray 0 and 1) from BarsInProgress 0 only.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Like this?! This gives a blank panel.

          protected override void OnBarUpdate()
          {

          if(BarsInProgress == 0)
          {
          Plot1.Set(Closes[1][0]*1.1);
          Plot0.Set(Closes[0][0]);
          }
          }


          Shouldn´t it be as simple as this, wich gives a blank panel as well;

          protected override void OnBarUpdate()
          {
          Plot1.Set(Closes[1][0]*1.1);
          Plot0.Set(Closes[0][0]);
          }

          Did I miss something really basic here???

          Comment


            #6
            Frederic, the plots are linked to your primary series - please try with a currenbars check for both series in your script -

            protected override void OnBarUpdate()
            {
            if (BarsInProgress == 0 && CurrentBars[0] > BarsRequired && CurrentBars[1] > BarsRequired)
            Plot0.Set(Closes[0][0]);
            Plot1.Set(Closes[1][0]);
            }
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Guess this is what you´re saying, only I have to put it in my words: On the first bar update (10 min), the secondary series (30 min) is looking for the "lacking" 20 minutes?!

              if (CurrentBar < 2) return;

              Plot0.Set(Closes[
              0][0]);
              Plot1.Set(Closes[
              1][0]);

              Not sure why "if(BarsInProgress == 1)" didn´t prevent that though.

              //Fredrik

              Comment


                #8
                Correct Frederic, for multiseries scripts the regular check needs to be extended to all series. You want to plot from the primary series.
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

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