Announcement

Collapse
No announcement yet.

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.

    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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      22 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X