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

Exchange data between strategies

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

    Exchange data between strategies

    Hello my friends,

    I was looking for a way to get data from a strategy to be used in other one. For example I am running robot1 in simulated account and the trades results are stored in a dataseries var (DeltaSeries). Also I am running a robot2 in a real money account that needs data from that robot1 dataseries.
    I tried to access via public class but it looks like it is inside - protected override void OnPositionUpdate - and not able to reach.
    This is one of the error messages:
    'NinjaTrader.Strategy.RoBot1.DeltaSeries' is inaccessible due to its protection level

    Any help appreciated.

    Thanks
    mcosta72
    NinjaTrader Ecosystem Vendor - Quant-Wise

    #2
    Hello mcosta72,

    Thank you for your note.

    You could use streamreader/writer to write to a text file and have the strategy reference this file. Please see the sample,


    An unsupported approach would be to use a static class. I’ve attached an example that shows how to use a static class in the NinjaTrader namespace that would allow you to pass objects between your scripts.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      HI Alan,
      Thank you for your help. I am thinking about time to access/reading and stream file. Do you think it would take an extra second to process it? Also, do you know if "File.ReadAllLines" allows me simultaneous access?
      I've used txt files for other strategy but it isn't accessed by trigger. Hard to time the response.

      Be well
      mcosta72
      NinjaTrader Ecosystem Vendor - Quant-Wise

      Comment


        #4
        Hello mcosta72,

        I'm replying on behalf of Alan who is out of the office today.

        File.ReadAllLines will simply read all of the contents of the file at that time and put it in a string array. It would not allow simultaneous access of the file. This would be restricted by the operating system. You may place logic in try catches to have a NinjaScript re-attempt reading the file if it hits a file access violation. Another idea would be to use a timer to time your reads and writes. An example NinjaScript using a timer can be seen in SampleLevel2Book.

        In theory, there would be a delay in writing to a file, but this delay would likely be less than a second and would vary between the read/write speeds of your HDD or SSD and the contents you are writing to the file. We would be talking about a very small delay. If this delay is important for you to address, you could try the unsupported approach presented by Alan.

        SampleLevel2Book - https://ninjatrader.com/support/foru...ead.php?t=3478

        If there is anything else we can do to assist, please let us know.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        7 responses
        32 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by merzo, 06-25-2023, 02:19 AM
        10 responses
        823 views
        1 like
        Last Post NinjaTrader_ChristopherJ  
        Started by frankthearm, Today, 09:08 AM
        5 responses
        21 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        43 views
        0 likes
        Last Post jeronymite  
        Working...
        X