Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

saving last bar data using stram writer

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

    saving last bar data using stram writer

    Dear friends.
    I have create strategy which save last bar data to file (only one row OHCL data), but it working slow and unstable. I move code from this strategy to indicator and indicator works better. Than I find sample stream writer indicator which write ohcl data to file. But I need only one row in file only last bar data, I don't need all history from chart. So how should I fix stream writer indicator for saving only last bar data?

    #2
    daglas, using System IO here would be liklely better performing for your task - http://www.ninjatrader.com/support/f...ad.php?t=48902

    You can simply move the if (Historical) return; statement you see, so it would only save current realtime data going forward for example, currently it would store all historical data as well in the sample and then output the RT saved data to the output window.

    Comment


      #3
      I prefer such solution
      if (CurrentBar>Bars.Count-100)
      {

      File.WriteAllText(path, Open[0]);

      }

      Comment


        #4
        Now I have such trouble. If my program which periodically read this file cause collision (read the file when nt7 try to save data to this file), indicator stops and I have error message in log windows. Something like indicator can't access to file ****. How can I write some exception in body of indicator, to retry reading file after collision or something also which help to write data even after errors.

        Comment


          #5
          daglas, you would need to look into locking the file to ensure no concurrent access is possible - for ideas you can check into this link - http://stackoverflow.com/questions/7...ed-environment

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          134 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          75 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          119 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          114 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          92 views
          0 likes
          Last Post CarlTrading  
          Working...
          X