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

Declaring and Setting a Public Variable

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

    Declaring and Setting a Public Variable

    I'd like to create a new Public variable, in an Indicator, that my Strategy can call. I need to look back on previous bars for this variable, so I’m trying to use the DataSeries method as described in the NT Users Guide. So far, I’ve not been successful in doing this. Is there detailed discussion or thread that would help me Declare this variable and properly Set it in my Indicator?

    #2
    Hello DenMan,

    Thanks for the post and welcome to the NinjaTrader forums! Easiest way is to structure the value as a plot, and then you can access it without additional code.

    If you want to maintain it as data series only, it should be declared as private and all calculations use the private variable. Then, in properties region, link this private variable to a public one. There is a reference sample available here that can help with this technique:


    You would need to setup your data series the same as the BoolSeries in that example.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      The script works great! I opted to use an Integer Series rather than a Boolian Series where 1=Bull & 2=Bear. That way I only need 1 Series to represent both conditions. Thanks for your help!

      Comment


        #4
        Glad that did the trick for you, Denman. Thanks for the follow up.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          What is the best way to use a variable (that is type double) from an indicator and call it in a strategy?

          I want to use the variables from the indicator and delete the duplicate code in the strategy, its too hard to manage.

          IntSeries class only takes int.
          I have used a DataSeries in the past successfully but will require convert in the strategy.

          I thought about using float but then I would have to declare float in the indicator...

          Both don't seem that efficient to me.

          Any ideas?

          Comment


            #6
            Hello ij001,

            You can access a double in an indicator from a strategy. Will need to follow the structure used in this sample:


            The double in this sample is named ExposedVariable.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_RyanM View Post
              Hello ij001,

              You can access a double in an indicator from a strategy. Will need to follow the structure used in this sample:


              The double in this sample is named ExposedVariable.
              Oh ok.

              So looks like no need for DataSeries class etc.

              It compiled in the strategy after a simple an assignment with

              Long = SampleBoolSeries().ExposedVariable;

              Hopefully it works with the rest of the code.

              Thx

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cre8able, Yesterday, 01:16 PM
              3 responses
              11 views
              0 likes
              Last Post cre8able  
              Started by ChartTourist, Today, 08:22 AM
              0 responses
              4 views
              0 likes
              Last Post ChartTourist  
              Started by LiamTwine, Today, 08:10 AM
              0 responses
              2 views
              0 likes
              Last Post LiamTwine  
              Started by Balage0922, Today, 07:38 AM
              0 responses
              5 views
              0 likes
              Last Post Balage0922  
              Started by JoMoon2024, Today, 06:56 AM
              0 responses
              6 views
              0 likes
              Last Post JoMoon2024  
              Working...
              X