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 cmtjoancolmenero, Yesterday, 02:31 PM
      7 responses
      22 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by hdge4u, 04-29-2024, 12:23 PM
      3 responses
      19 views
      0 likes
      Last Post MisterTee  
      Started by mintos, 04-02-2024, 08:22 PM
      8 responses
      41 views
      0 likes
      Last Post mintos
      by mintos
       
      Started by PaulMohn, 04-24-2024, 03:49 AM
      5 responses
      39 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by claxxical, 05-30-2017, 12:30 PM
      38 responses
      4,482 views
      0 likes
      Last Post alancurry  
      Working...
      X