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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      72 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      39 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X