Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

built in bar time-span variable?

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

    #16
    Hi Lance,
    Please rerun it for type=day, value=1 day, from 1/1/2013, to 7/12/2013, security=$EURUSD.
    Thanks

    Comment


      #17
      Hello,

      Thank you for that information. This case Bars.FirstBarOfSession will always be false because the daily bar will not register as the first bar of session.

      If you wanted to wait three bars you could do the same thing along these lines

      if(myVariable <= 3)
      {
      myVariable++;
      return;
      }
      LanceNinjaTrader Customer Service

      Comment


        #18
        Thanks Lance.

        My goal was to have the code work automatically for any type bar [ie] day or minute. Can I do that with the suggested code?

        Perhaps a future NT version could define a daily bar as the first bar of session because it is the first bar of a session.

        Comment


          #19
          You could do a check at the start to determine what bars period is being used



          Then once you've identified the bar type you can handle the logic accordingly.
          LanceNinjaTrader Customer Service

          Comment


            #20
            Thanks, I'll give that a shot

            Comment


              #21
              I thought I had this nailed down, but I don’t. Sorry about that.
              The following code works for day bars but execution never comes to an end for 60 minute bars. type=day, value=60 min, from 1/1/2013, to 7/12/2013, security=$EURUSD. As you can see, I commented out the offending ‘else if’ clause and replaced it with a simpler ‘else’, but it still goes into an endless loop.
              I don’t think the strategy can be at fault because it does nothing. Attached are the exported indicator and strategy. Any help will be much appreciated.
              if (BarsPeriod.Id == PeriodType.Day) //Illogically, FirstBarOfSession
              //is designed to always returns false for a day bar even though
              //it is the 1st [and only] bar, so it must be handled differently.
              {
              Print("PeriodType is Day");
              sessionCount++;
              if (sessionCount <= 3) return;
              }
              // else if (Bars.FirstBarOfSession) //not a day bar, so can use FirstBarOfSession
              // {
              // Print("PeriodType is not Day");
              // sessionCount++;
              // if (sessionCount <= 3) return;
              // }
              else //THIS 'ELSE' IS FOR DEBUGGING FOR WHEN PERIODTYPE IS HOURLY, NOT DAILY, BARS. // IT TEMPORARILY REPLACES THE ABOVE 'ELSE IF'
              if (CurrentBar < 72) return;//72 is 3 days worth of 1 hour bars
              Attached Files

              Comment


                #22
                more comments

                I added a “sessionCount=0;” statement to the initialize region of the indicator, resulting in sessionCount resetting as expected to zero instead of just increasing in value with each successive Strategy Analyzer rerun. The output window is not displaying expected results. In spite of that, however, the day bar runs appear to be valid at first glance. I inserted some debug print statements in the code showing that sessionCount resets unexpectedly to zero during a run? Hourly bar runs continue to run endlessly until forcefully ended via the system task manager?
                Is there an output window file somewhere which I can attach to a Forum post? I have been unable to find such a file.

                Comment


                  #23
                  Hello,

                  Sorry I wasn't aware you were using a strategy in conjunction with an indicator that did this check.

                  The reason for this issue is likely due to your bars required check. When bars required is applied to a strategy it will cause it to wait X bars before calculating. When it's used for indicators it only halts plotting for X bars.

                  If you run the strategy that has this sort of filter in place you couldset bars required to 0 since you have the internal logic in place to tell it to wait. (this is set when running the strategy, the default value can also be hard coded) http://www.ninjatrader.com/support/h...srequired2.htm
                  LanceNinjaTrader Customer Service

                  Comment


                    #24
                    I added "BarsRequired = 0;" to the initialize region of the strategy, resulting in no trades for daily bars [rather than many trades, as before] and no change in endless loop performance for hourly bars? Please advise.

                    Comment


                      #25
                      I would suggest starting as simple as possible.

                      Start with either just an indicator or just a strategy by itself.

                      Use the code you already created at the start of the OnBarUpdate()

                      Code:
                      if (BarsPeriod.Id == PeriodType.Day)
                      {
                        Print("PeriodType is Day");
                        sessionCount++;
                        if (sessionCount <= 3) return;
                      }
                       else if (Bars.FirstBarOfSession) 
                       {
                         Print("PeriodType is not Day");
                        sessionCount++;
                        if (sessionCount <= 3) return;
                      }
                      
                      //if we make it 3 sessions, or three day bars in
                      Print(Time[0] + " made it past three days or sessions");

                      Don't worry about the follow up logic until you're certain you have the correct print outs to your output

                      Also, in regards to BarsRequired, changing this in initialize will not change the existing strategy. You will have to change the settings on the strategy tab/window OR will need to re-add the strategy.
                      LanceNinjaTrader Customer Service

                      Comment


                        #26
                        Thanks Lance, but I have to rethink this. It sounded like a good idea at the time in post #4 to pursue the idea but I am getting into complications that are far beyond the reach of my understanding and available time. For now I think I will try returning to my not automatic, but more simple, approach of setting BarsInaDay. Hopefully that still works. More later, after I play around with that.

                        Comment


                          #27
                          Ok let us know if you need further assistance.

                          Alternatively if you would prefer to have the script created for you. You can send a note to support[at]ninjatrader[dot]com requesting custom development.
                          LanceNinjaTrader Customer Service

                          Comment


                            #28
                            Thanks Lance.
                            Is there a charge for custom development?

                            Comment


                              #29
                              There is.

                              Price will depend on script complexity
                              LanceNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              369 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              573 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              575 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X