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

Need advice. blocked file. async await

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

    Need advice. blocked file. async await

    hi all.
    my goal to get a last OHLC bar and upload it to a file.
    then in my program(java) i want take data from this file and write some code.
    my problem: this file is blocked by writer from ninjatrader. and i can't read data from file.
    i have tryed to create a new thread and to wrote OHLC data from this thread with some Thread.sleep(50). but ninjatrade make crashdown all time.
    i have tryed to use async method but indicator don't compile. cause don't to see async and await.
    has anybody who can to give my good advice how resolve it?
    ps. NT_7 .NET 4.5.2

    #2
    Hello ansgrecho, thanks for writing in.

    Any external application outside of NinjaTrader goes out of the scope of support we could provide. Use the StreamWriter class to open the file, then make sure to call StreamWriter.Close() when the file writing is done. If the application outside of NinjaTrader can not access the file, it needs special exception handling that will wait until the file is available to be opened. We do not reccomend using Thread.Sleep within the NinjaScript as this can cause stability issues in the NinjaTrader system as a whole. An async Task is not supported in NinjaTrader 7 as it requires .Net 4 and NinjaTrader 7 uses .Net 3.5

    There is an example of using the Streamwriter here:



    Kind regards,
    ChrisL

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris.
      This example don't resolve my problem.
      can I create new threads in the editor window? if so, what control words(sleep,wait,notify,yield) does the ninjatrader support? cause i can to get a full control on writer only from my thread, but not base thread.
      i need to get data in my application from a blocked file. but i don't achive it. does NT_8 support .Net 4.5?
      in this article from your site to wrote "Due to the asynchronous nature of this indicator" TIPS. and why is here async to use and i can't to use async in nt_7 https://ninjatrader.com/support/help...o_write_to.htm , https://gyazo.com/35a26ed37ac852af7c2d05f897e23346?
      Last edited by ansgrecho; 09-24-2020, 02:13 AM.

      Comment


        #4
        Hello ansgrecho, thanks for your reply.

        The file is being blocked because it is open, not because it's running on the UI thread of NinjaTrader. In the NinjaTrader 8 example, the stream writer is closed at the end of the writing procedure. This should be sufficient to allow another program to access the file. This should be tested thoroughly.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          ok. Thanks for you help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cre8able, Today, 03:20 PM
          1 response
          9 views
          0 likes
          Last Post cre8able  
          Started by fiddich, Today, 05:25 PM
          0 responses
          3 views
          0 likes
          Last Post fiddich
          by fiddich
           
          Started by gemify, 11-11-2022, 11:52 AM
          6 responses
          804 views
          2 likes
          Last Post ultls
          by ultls
           
          Started by ScottWalsh, Today, 04:52 PM
          0 responses
          4 views
          0 likes
          Last Post ScottWalsh  
          Started by ScottWalsh, Today, 04:29 PM
          0 responses
          9 views
          0 likes
          Last Post ScottWalsh  
          Working...
          X