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 traderqz, Today, 12:06 AM
      9 responses
      16 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by kevinenergy, 02-17-2023, 12:42 PM
      117 responses
      2,766 views
      1 like
      Last Post jculp
      by jculp
       
      Started by Mongo, Today, 11:05 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by SightCareAubetter, Today, 12:50 PM
      0 responses
      2 views
      0 likes
      Last Post SightCareAubetter  
      Started by Skifree, Today, 03:41 AM
      5 responses
      14 views
      0 likes
      Last Post Skifree
      by Skifree
       
      Working...
      X