Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Debugging (custom) BarsType?

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

    Debugging (custom) BarsType?

    Hi,
    I am trying to debug/develop custom BarsType code, but Print() does not seem to be printing anywhere even if PrintTo = PrintTo.OutputTab1
    Please suggest how to print debugging data from a BarsType code?

    Thanks!

    #2
    Hello momchi,

    Thanks for your question.

    We have to remember that BarsTypes create bars and store them in the bar cache in Documents\NinjaTrader 8\db\cache\. If the bars are cached and loaded in memory, they would be fetched there, thus skipping any prints made in OnDataPoint.

    As a tip, using the Playback Connection can be helpful when developing BarsTypes since the bar cache would not be used. You would then just need to close and reopen your chart to re-test.

    Some general information on developing BarsTypes is included here as well.

    Developing BarsTypes general information

    BarsTypes are actually quite simple, but there are some items we should note so their development can be better understood.
    1. BarsTypes build bars from underlying tick, minute, or daily data given by the data provider
    2. Once the bars are built they are cached
    BarsTypes use 3 methods in OnDataPoint to create bars from the requested data: AddBar, UpdateBar, and RemoveLastBar.

    RemoveLastBar is used in Renko and LineBreak bars to repaint their Open.

    UpdateBar is used to update a bar's High, Low, Close and Volume. AddBar is used to create a new bar with Open, High, Low, Close, and Volume values.

    When debugging BarsTypes, it is best to add prints before the AddBar/UpdateBar/RemoveLastBar functions. I also recommend testing on charts with 0 Bars To Load so you can focus on the bars that are being developed and to ignore the cached bars. You could also clear the NinjaTrader 8\db\cache\ folder to clear the cached bars and have clean tests with each change to your BarsType. Using Playback also can help to see your changes.

    When creating new BarsTypes, the BarsType must create a unique BarsPeriodType index in State.Configure when the BarsPeriod is created. See line 39 of the UniRenko BarsType to see how that BarsType creates its BarsPeriod.

    https://ninjatraderecosystem.com/use...nko-bartype-8/

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

    We look forward to asistsing.

    Comment


      #3
      H Jim,
      thank you - very informative!!!
      I was using the example Renko code for illustration, but explanations are better than reverse-engineering ...
      and, I had no idea you were caching the bars... Thank you!

      Comment


        #4
        Hi Jim,

        follow up question - what is the meaning of bars.GetVolume() in a Renko type bars? I see some non-sensical numbers... and was wondering -

        Documentation says that the index is the "absolute bar index", but then I see that the bar series has a period of 2 (as that's sufficient to build it)...
        The puzzling thing is that I see the "volume" increase for bars.GetVolume(0) steadily, but then it caps at some number (e.g 3619), and bars.GetVolume(1) stays at 0...

        Could you please help me understand the volume of the bars for this type, please?

        Comment


          #5
          Hello momchi,

          Renko bars will use bars.GetVolume(bars.Count - 1) when it needs to store the volume from the last bar it was building.

          This is done particularly when the Renko bar preforms the RemoveLastBar behavior where it removes the last bar and repaints the open. (This is needed for reversal functionality.)

          When setting up prints, it helps to set them up specifically when you monitor UpdateBar and AddBar, otherwise the output can get tricky to follow.

          I would also suggest making sure you are testing one chart at a time, and it helps to clear cache and restart to keep development clean. (Developing custom BarsTypes can encounter cache issues since changes to the bar logic are frequently made.)

          These tips in mind, when I test on a modified 1 minute BarsType that does not have RemoveLastBar behavior where any bars would change, I see the first and second bar's volume.

          Code:
           if (bars.Count < 2)
              return;
          Print(bars.GetVolume(0));
          Print(bars.GetVolume(1));
          Print("");

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          587 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          341 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          555 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X