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

Exposed/share variable between strategies

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

    Exposed/share variable between strategies

    My aim: To share variables between different NT8 Strategy scripts.
    I've look through this forum, samples on exposing variables from Indicator to Strategy, which doesn't seem to work between strategies.
    I've tried public static bool test in strat1 & reading it from strat2. The 2 strats script compiled ok, but reading test in strat2 is unreliable, i.e. sometimes the read value is correct, but many times it's incorrect. How to reliably share variables between 2 strategies?

    Thanks for your help.
    Last edited by Tiang; 11-19-2018, 03:37 AM.

    #2
    Hello Tiang,

    Thank you for the post.

    In general, there is not a specific/reliable way to share data between strategies specifically as strategies are intended on being isolated from everything else. Can you provide more detail on your end goal so that I can try to provide the best solution here? Is this just a single bool value you want each strategy to read? Would this be a setting which they read which and do not set, or would this be a value each strategy has control over? When would the value be set, would this be based on some strategy condition or by your choosing?

    You may have success in a few different ways depending on the scope of what scripts need access to the value. This will also depend on what you are trying to do, as noted there is not a standard way to share data between strategies but there are C# ways to accomplish that outside of what NinjaScript provides. A partial class may be used to define constants or other shared variables/methods for common types like Strategy. You may also have success using a static class from an addon, it really depends on the overall goal.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      My goal: Run Strat1 on instrument1 & Strat2 on instrument2. Instrument2 is a tradable instrument that is not instrument1. Let's call the shared bool variable test. Would like both Strat1 & Strat2 to have read & write access to test, but would settle for if Strat1 can write & Strat2 can only read. So Strat1 via its logic, set test, & when Strat2 reads it, it then programmatically place ATM strategy order which I would then manually managed there on.
      As mentioned in my 1st post, I've defined a "public static bool test" in Strat1 & am able to access it in Strat2. But the read is unreliable, i.e. when Strat1 set test=true, Start2 would sometime read it as false, sometime as true (but it's true within Strat1 itself). Is there a an Update(), like the one described in your Sample example for exposing variable in Indicator script? If there is, then that is what I need.
      I hope you can give me more specific pointers to achieve this.

      Thanks.

      Comment


        #4
        Hello Tiang,

        Thank you for the additional details.

        Based on your description, it sounds like you would want just a single strategy for this use case. Is there a specific reason you are using two separate scripts here instead of just one script with an added secondary series? As noted there is no means to share data between two strategies that are reliable so my suggestion will be to combine the logic into a single script. You could look into other C# ways to share data but I really couldn't suggest them for the described use case. The sharing that indicators provide would not be able to be replicated in the same way with two strategies as strategies are not intended to be accessed from other scripts. Indicators are a special item in NinjaScript as the internal's of NinjaTrader creates instances of indicators for you and extra code to link them correctly. A strategy does not have the same mechanics in place as you need to enable it manually.




        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          I haven't done a strategy script with a secondary series. I like to ask this before looking at the secondary series option: Can one run a strategy on instrument1 chart & submit ATM Strategy order for instrument2, which is the sec series in the strategy? Note specifically it's a ATM order and will this order appear on another chart window of instrument2 for me to manually manage?

          Thanks.

          Comment


            #6
            Hello Tiang,

            As ATM strategies are only loosely associated with NinjaScript strategies, it would appear in the platform wherever you can see ATM's such as chart trader or the DOM. Any ATM's the strategy submits would be shown in those tools if the account and instrument selected is that of the submitted ATM.

            I would suggest that you try modifying the SampleATMStrategy that comes with the platform to further explore these concepts to see how the platform displays the orders.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              HI Jesse,

              That sounds good. Thanks very much for your help.

              Comment


                #8
                Hi Jesse,

                I've a question after looking at multi-instrument script doc, especially on AtmStrategyCreate(). So I run my Strategy on instrument1 chart (with instrument2 as sec series) & want the ATM order on instrument2. But AtmStrategyCreate() does NOT give me the option to specify the trading instrument. If I use AtmStrategyCreate(), the order would be for instrument1, right?, which isn't what I want. I want the order on instrument2.
                You might ask why not run the strategy script on instrument2 then (with instrument1 as sec series). I can't do that as I need to manually interact with the script on instrument1.

                Thanks.

                Comment


                  #9
                  Hello Tiang,

                  This would depend on what series called OnBarUpdate at that time, as this would be a multi-series script it would also apply to multi-series concepts like BarsInProgress. If you were to modify the sample to be a multi-instrument strategy, you could use BarsInProgress to filter when instrument 1 and 2 submit orders. You can read about multi-instrument scripts in the following link: https://ninjatrader.com/support/help...multi%2Bseries

                  You are also correct as there is no way to specify the instrument, so it would be limited to the filtering you use. If instrument 1 is a trigger to submit orders to instrument 2, you would need to work that out in your logic rather than specifying an instrument to trade to. For example, setting a bool value to true from instrument 1's BarsInProgress and then reading that bool in instrument 2 BarsInprogress.



                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Jesse,

                    I think 1 last question. Can instrument1 be from Account1/Broker1 & instrument2 from Acc2/Broker2? Note that I've a multi-broker NT license.

                    Thanks..
                    Last edited by Tiang; 11-20-2018, 08:33 AM.

                    Comment


                      #11
                      Hi Jesse,

                      With your help, I've a better understanding of the issues. I'm able to proceed with my NT8 scripts. Thanks for your help & patience with a novice programmer.
                      You have a great day.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by rocketman7, Today, 02:12 AM
                      5 responses
                      22 views
                      0 likes
                      Last Post rocketman7  
                      Started by trilliantrader, 04-18-2024, 08:16 AM
                      7 responses
                      28 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by samish18, 04-17-2024, 08:57 AM
                      17 responses
                      66 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Started by briansaul, Today, 05:31 AM
                      1 response
                      15 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by PaulMohn, Today, 03:49 AM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X