Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last Bar of Session.

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

    Last Bar of Session.

    Top of the Day.

    I am strugling with the proper method to identify the Close of the Bar prior to the Open of the last bar.

    I am developing under : CalculateOnBarClose = true; using Time Bar Charts
    I would like to know that the open of the next bar is the last bar in the session and not take a position.


    I am able to find the session end time and session length via:

    private DateTime sessionBegin;
    private DateTime sessionEnd;

    Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
    int TimeSpan = ToTime(sessionEnd) - ToTime(sessionBegin);


    I am able to determine the Chart timeframe via:
    Bars.Period.Value


    From there I am unable to calculate whether or not the:

    Time[0] of the current bar is equal to sessionEnd time less the Bars.Period.Value.

    Any and all help would be greatly appreciated.
    Regards.
    Larry

    #2
    Litter.

    Bars.Period.Value will just be a value of the period for the chart series type. For example if its second, then Bars.Period.Value may be 15 seconds. Its not necessarily easily compared to a ToTime().

    We have a reference sample on using time filters.



    Could you post more of your code, i.e. the last comparison as well?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Sorry,

      That is as much as I have.
      that is why I was asking for help on the board.

      I am running 15 min / 30 min charts on Futures Contracts.
      I am selecting a session template from those supplied by NT

      All my other attempts to subtact the bars.period.value from any combination of the date time variables either does not compile due to errors or ... subtracting 30 from 4:15 will not yield 3:45.

      Again I am attempting to identifiy if the the current bar close[0] is equal to the last session bar minus one.

      Summary:

      My intentions are to obtain the session end time and subtract the bar chart value (15min) to obtain the ending time of my bar in question.

      Comment


        #4
        Litter,

        You can use DateTime objects.

        Represents an instant in time, typically expressed as a date and time of day.


        I.e.

        DateTime TimeToCompareTo = sessionEnd.AddMinutes( -somevalue );

        Then compare to this date time with Time[0] as follows.

        If ( DateTime.Compare(Time[0],TimeToCompareTo) > 0)
        {
        //do something
        }

        DateTime.Compare : http://msdn.microsoft.com/en-us/libr...e.compare.aspx

        DateTime.AddMinutes : http://msdn.microsoft.com/en-us/libr...ddminutes.aspx

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Great !

          Your direction / suggestions work perfectly for me.
          Thank You for your Help.

          Larry.

          Comment


            #6
            Prior Day Close indicator modification

            By modifying the PriorDayOHLC indicator code, how can you plot the "Close" value of x bars before the prior day session closing bar? For example on the current session chart plot the closing value of 3 bars before the prior day session closing bar.

            Thanks

            Comment


              #7
              everington,

              Just looking quickly at it, I believe you could modify lines 95-98 to have instead of :

              // Initilize the current day settings to the new days data
              currentOpen = Open[0];
              currentHigh = High[0];
              currentLow = Low[0];
              currentClose = Close[0];

              Something like :

              // Initilize the current day settings to the new days data
              currentOpen = Open[x];
              currentHigh = High[x];
              currentLow = Low[x];
              currentClose = Close[x];

              For x bars into the past from the closing of that day.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Ok thanks have tried that and it does not plot....

                Comment


                  #9
                  everington,

                  How are you defining x?

                  Please check your log tab for error messages.

                  Also, you will want to check that CurrentBar isn't less than 4 in our case.

                  if ( CurrentBar < 4 )
                  {
                  return;
                  }
                  Adam P.NinjaTrader Customer Service

                  Comment


                    #10
                    Simply putting a number where you have X.

                    currentOpen = Open[x];
                    currentHigh = High[x];
                    currentLow = Low[x];
                    currentClose = Close[3];

                    Comment


                      #11
                      everington,

                      Please also check your log tab, as well as the current bar as I mentioned in my prior post.
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks that currentbar code makes the difference. Thankyou very much for you imput.

                        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
                        108 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        572 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X