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

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.
    JimNinjaTrader Customer Service

    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("");
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Started by yertle, Today, 08:38 AM
          5 responses
          16 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by adeelshahzad, Today, 03:54 AM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X