Announcement

Collapse
No announcement yet.

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.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      79 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      146 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      52 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      56 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X