Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Print only after last Daily bar

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

    Print only after last Daily bar

    I have a Print line that does running totals (+=) in OnBarUpdate, so i only want it to Print once. What's the most succinct way to make that happen on Daily bars?

    #2
    if (CurrentBars[0] > 0) if (Times[0][0].Date > Times[0][1].Date) Print(Times[0][0].ToString("yyyy-MM-dd") + " : Foo");
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Or perhaps you mean:

      if (CurrentBars[0] >= 0 && Bars.IsFirstBarOfSession) Print(Times[0][0].ToString("yyyy-MM-dd") + " : Foo");

      The former is the date changing. The latter is the session changing.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hi Bruce,
        Thanks for that. I'm cycling through a trade colleciton, and I want to print that line only after the last trade. I'm porting a script from a friend who works in tradestation, and he has something called "LastBarOnChart" that does the trick for him, but I haven't found anything for NT like that.
        David

        Comment


          #5
          LastBarInChart would be something crudely like: CurrentBar == Bars.Count - 1 if it's an intrabar strategy, but the best way would be in OnStateChange, in State.Transition, to set a flag that you've reached realtime trading, and then later you can just check that flag.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #6
            Hi, If your script is running Calculate.OnBarClose, the last historical bar would be:

            if ( CurrentBar == ( BarsArray[0].Count-2))
            {
            Draw.Dot(this, "LASTBAR", false, 0, High[0], Brushes.Red);
            }

            If the script is running OnEachTick, it can be written as:

            if ( CurrentBar == ( BarsArray[0].Count-1) && IsFirstTickOfBar)
            {
            Draw.Dot(this, "LASTBAR", false, 0, High[0], Brushes.Red);
            }​​

            Comment


              #7
              thanks, Chris!

              Comment


                #8
                Hi Chris,
                Is there a way to do this when I'm using State == State.Terminated inside of OnStateChange()? for instance:

                else if (State == State.Terminated)
                {
                if (SystemPerformance.AllTrades.Count > 0)
                {
                foreach (Trade lastTrade in SystemPerformance.AllTrades)
                {
                lastMfe = lastTrade.MfeCurrency



                //adjustMfe += lastMfe / (ATR(14)[0] * Bars.Instrument.MasterInstrument.PointValue); // how do I print this cumulative value only once at the end of the collection?

                }}}
                Last edited by trader3000a; 05-23-2023, 05:10 AM.

                Comment


                  #9
                  I would be reluctant personally to do this... do we know that during State.Terminated the SystemPerformance information has not already been broken down? The naming of the state "Terminated" (rather than "PreTerminate" or something like that suggests that the destruction is already underway. Still, maybe it will work if coincidentally that part is disposed later than this part? Have you tried?
                  Bruce DeVault
                  QuantKey Trading Vendor Services
                  NinjaTrader Ecosystem Vendor - QuantKey

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, 03-13-2026, 05:17 AM
                  0 responses
                  86 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  151 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  79 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  53 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  61 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X