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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X