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

Print Statements Repeating on Every Bar

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

    Print Statements Repeating on Every Bar

    Hello,

    I am having a strange problem with either Print Statements or when using StreamWriter where Print / WriteToFile statements are being repeating many times over. Eventhough, I am using BarsInProgress to segregate logic and I am sure the Prints / WriteToFile should not be repeating.

    After adding some additional Print statements that DO get executed each bar the issue goes away.

    Therefore I believe that what is happening is that the bars where no Print statement should be executing seems to be printing the last message.

    This is for a Multi Data Series Strategy and if I include the following which prints messages each bar all seems to go as expected:
    Code:
                    if (BarsInProgress == 0)
                    {
                        message = string.Format("{0:dd/MM/yyyy H:mm:ss.ffff} Bar: {1} | MTC Bar : O: {2} H: {3} L: {4} C: {5} ",
                            dt, CurrentBars[BarsInProgress], Open[0], High[0], Low[0], Close[0]);
                        //WriteToFile(message, pathToWrite);
                        Print(message);
                    }
                    else if (BarsInProgress == 1)
                    {
                        message = string.Format("{0:dd/MM/yyyy H:mm:ss.ffff} Bar: {1} | STC Bar : O: {2} H: {3} L: {4} C: {5} ", dt, CurrentBars[BarsInProgress], Open[0], High[0], Low[0], Close[0]);
                        //WriteToFile(message, pathToWrite);
                        Print(message);
                    }
    Not Including Prints for each bar I get messages that repeat the prior print statement for Bars where no Print statements should be executed.

    I am on 8.0.21.1 64-bit, testing with Strategy Analyzer, all Data Sources are Tick based, All Indicators and Strategy are Calculate.OnBarClose.

    Thanks,
    ATC
    Last edited by tornadoatc; 05-04-2020, 12:09 PM.

    #2
    Hello tornadoatc,

    Thank you for your post.

    Would you be able to give an example of the code where you were trying not to print something on a bar where it wasn't working? My guess is the previous message is being maintained from the prior bar, but I would need to see the code that isn't executing as you expect.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello tornadoatc,

      Just wanted to check in to see if you'd had a chance to provide the code you had that wasn't working.

      Thanks in advance; I look forward to assisting you further.
      Kate W.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      5 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X