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

Share Variable Between Two Strategies

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

    Share Variable Between Two Strategies

    Hi there,

    I have 2 different strategies that I'm looking to share a variable between. By that, I mean that I'd like to be able to update this variable in either strategy and then have that value be reflected when the other strategy uses the variable.

    Example:
    If I have a variable named 'sharedVariable' that I update in Strategy 1 to a value of '5', I want to be able to access that in Strategy 2 and have it be a value of '5' when called there. I then may change it to a value of '3' in Strategy 2 and want that to be reflected within the variable when called again back in Strategy 1.

    Is that possible? Any help on how to define and then access this variable would be very much appreciated.

    Thanks.

    #2
    Originally posted by fiddich View Post
    Hi there,

    I have 2 different strategies that I'm looking to share a variable between. By that, I mean that I'd like to be able to update this variable in either strategy and then have that value be reflected when the other strategy uses the variable.

    Example:
    If I have a variable named 'sharedVariable' that I update in Strategy 1 to a value of '5', I want to be able to access that in Strategy 2 and have it be a value of '5' when called there. I then may change it to a value of '3' in Strategy 2 and want that to be reflected within the variable when called again back in Strategy 1.

    Is that possible? Any help on how to define and then access this variable would be very much appreciated.

    Thanks.
    Use a static variable, either in a static class, or in the Indicator class, by using a partial class to extend the Indicator class.

    ref: https://docs.microsoft.com/en-us/dot...eywords/static

    Comment


      #3
      Thanks for opening the thread fiddich, and thank you for your response koganam.

      You can find an example script that demonstrates here: https://ninjatrader.com/support/foru...04&postcount=2

      Please let us know if if there is anything else we can do to help.
      JimNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by junkone, Today, 11:37 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by frankthearm, Yesterday, 09:08 AM
      11 responses
      42 views
      0 likes
      Last Post frankthearm  
      Started by quantismo, 04-17-2024, 05:13 PM
      5 responses
      35 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by proptrade13, Today, 11:06 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      35 views
      0 likes
      Last Post love2code2trade  
      Working...
      X