Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing a variable for a strategy target

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

    Accessing a variable for a strategy target

    I have made a calculation in an indicator that gives me an integer value. This value is referenced by other indicators by assigning it as a variable (private double target' - this is then 'set' in on bar update ( Target = target obviously the calculation is done before this, and I have used the following under properties:

    [Browsable(false)] //***
    [XmlIgnore()]
    public double Target
    {
    // We need to call the Update() method to ensure our exposed variable is up-to-date.
    get { Update(); return target; }
    }

    I can read this variable in other indicators, draw it on screen etc - but I can't access the value for a strategy using the strategy builder, I think it's because it is not a data series. Does anybody have any ideas please - all I want to do is reference the value to set a target.

    Ben.

    #2
    Right - think I'v found the answer but it relates to 6.5 - Is there still a problem with the 'Calculate on Bar Close' ?

    From the thread and posted by Bertrand -

    Yes, this is correct - there's a known bug in NinjaTrader 6.5 where set CalculateOnBarClose values would not be overridden as expected, so as workaround we advise to set this only in the 'mother' strategy and remove any references to this in the called indicators.

    Thread here - http://www.ninjatrader.com/support/f...ad.php?t=18653

    Ben.

    Comment


      #3
      stocktraderbmp, for the wizard, please ensure it's a plot you try to access. The CalculateOnBarClose matter is still current, for indicator please don't assign a setting in the Initialize() so it could be overwritten by the caller script as needed.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks B -

        I have not put anything in the initialize () but I am trying to access an integer not a plot. I will code it manually if it can't be done through the wizard - I am assuming that as I can access the number from other indicators I will be able to access it for the strategy - would I be correct in assuming that?

        Comment


          #5
          Just create an indicator then that would plot this value calculated for visualization, this could then be accessed in your wizard strategy.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by stocktraderbmp View Post
            Thanks B -

            I have not put anything in the initialize () but I am trying to access an integer not a plot. I will code it manually if it can't be done through the wizard - I am assuming that as I can access the number from other indicators I will be able to access it for the strategy - would I be correct in assuming that?
            STbmp - I was able to do this tonight. Took a while of hacking around. I'm not even sure if it is efficient. lol.

            In the indicator, I expose the variables I want as public. (no big deal to me).

            In the strategy, I define a variable of the indicator name in the Initialize.

            In OnStartUp, I assign to the variable the indicator call, as messy as it may be.

            Then in the OnBarUpdate, variable.value works like a champ.

            Comment


              #7
              Originally posted by sledge View Post
              STbmp - I was able to do this tonight. Took a while of hacking around. I'm not even sure if it is efficient. lol.

              In the indicator, I expose the variables I want as public. (no big deal to me).

              In the strategy, I define a variable of the indicator name in the Initialize.

              In OnStartUp, I assign to the variable the indicator call, as messy as it may be.

              Then in the OnBarUpdate, variable.value works like a champ.

              Sledge... I need some more clarification here...

              When you say... "I define a variable of the indicator name in the Initialize"... I don't know what you mean. Are you actually calling Strategy.Add(IndicatorName) in Initilize or merely creating a new variable of type 'IndicatorName'?

              Secondly... you say... "In ONstartup, I assign to the variable the indicator call"... can you please provide an example of this... I can't decipher what you've done here.

              Some thoughts. Merely creating an IndicatorName object inside of the Strategy won't cause that objects OnBarUpdate() or Plot() overrides to be called. For this reason, if you want to get at some IndicatorName values that are updated at some point, you *must* use Strategy.Add() inside of Initialize(). I would think.

              All that having been said, I'm really interested in exactly what the case was where you got this working. I will tell you that I was able to get it working in my case. I'm just wondering if there is a simpler way.

              In my case, I require access to Min and Max which are provided ONLY in the Plot() override of the Indicator class. Plot() is not a member of the Strategy Base class...

              Since Plot() only gets called in an indicator when the indicator is running, I have the requirement that the indicator be running. To achieve this from within my Strategy... I call Add(IndicatrName) from the Strategy.Initialize() function.

              So now I have my indicator running... but I don't have a reference to the object that NT created during the Add(). Is there an easy way to get at this object? I couldn't find one...

              The question then becomes, I have an object which is updating with the information that I want, but I have no way to access the object cuz I didn't create it.

              My solution to this major problem was to create another instance of the object from within my Strategy and assign that instance to a class variable. The problem here is this 2nd instance will never get its OnUpdateBar or Plot functions called. NT knows nothing about it.

              To make a long story longer... I simply made the member variables within the Indicator 'static'. That way they are shared across all instances of the class... I could then simply use my created InstanceName object to access the variables, even though they are being updated via the object created by NT during the Add() call.

              A bit of a hack... no doubt... tell what I'm doing wrong... your approach seems more straightforward, but I don't know the exact use-case you were working with.

              Any feedback would be appreciated.

              Thanks,
              Dave

              Comment


                #8
                Originally posted by BigWaveDave View Post
                Sledge... I need some more clarification here...

                When you say... "I define a variable of the indicator name in the Initialize"... I don't know what you mean. Are you actually calling Strategy.Add(IndicatorName) in Initilize or merely creating a new variable of type 'IndicatorName'?

                Secondly... you say... "In ONstartup, I assign to the variable the indicator call"... can you please provide an example of this... I can't decipher what you've done here.

                Some thoughts. Merely creating an IndicatorName object inside of the Strategy won't cause that objects OnBarUpdate() or Plot() overrides to be called. For this reason, if you want to get at some IndicatorName values that are updated at some point, you *must* use Strategy.Add() inside of Initialize(). I would think.

                All that having been said, I'm really interested in exactly what the case was where you got this working. I will tell you that I was able to get it working in my case. I'm just wondering if there is a simpler way.

                In my case, I require access to Min and Max which are provided ONLY in the Plot() override of the Indicator class. Plot() is not a member of the Strategy Base class...

                Since Plot() only gets called in an indicator when the indicator is running, I have the requirement that the indicator be running. To achieve this from within my Strategy... I call Add(IndicatrName) from the Strategy.Initialize() function.

                So now I have my indicator running... but I don't have a reference to the object that NT created during the Add(). Is there an easy way to get at this object? I couldn't find one...

                The question then becomes, I have an object which is updating with the information that I want, but I have no way to access the object cuz I didn't create it.

                My solution to this major problem was to create another instance of the object from within my Strategy and assign that instance to a class variable. The problem here is this 2nd instance will never get its OnUpdateBar or Plot functions called. NT knows nothing about it.

                To make a long story longer... I simply made the member variables within the Indicator 'static'. That way they are shared across all instances of the class... I could then simply use my created InstanceName object to access the variables, even though they are being updated via the object created by NT during the Add() call.

                A bit of a hack... no doubt... tell what I'm doing wrong... your approach seems more straightforward, but I don't know the exact use-case you were working with.

                Any feedback would be appreciated.

                Thanks,
                Dave
                check out this document which I found here browsing some old random threads...

                Comment


                  #9
                  Originally posted by BigWaveDave View Post
                  Sledge... I need some more clarification here...

                  Any feedback would be appreciated.

                  Thanks,
                  Dave

                  More specifically--


                  ---

                  Indicator1

                  Variables

                  public int myVariable1;

                  OnBarUpdate()

                  myVariable1 = some complicated logic;

                  ----


                  Strategy1:

                  Variables Region

                  private myIndicator1 Indicator1;

                  OnStartUp()

                  myIndicator1 = Indicator1(BarsArray[0], Color.Orange, DashStyle.Solid, 5, 4, 3 );

                  OnBarUpdate()

                  if ( myIndicator1.myVariable1 > 2 )
                  {

                  }


                  Find the constructor in your indicator code at the bottom in the hidden region of "do not modify, nt generated code"

                  public Indicator.Indicator1 Indicator1(Data.IDataSeries input, Color lineColor, DashStyle lineStyle, int something0, int something1, int something2);

                  Comment


                    #10
                    Forget it. Found the answer in this thread:




                    So, you must use Add(IndicatorName()).

                    The question of how to reference that created object is this...

                    ....
                    double chartMin = IndicatorName().Min;

                    That's the piece I was missing. I'm new to C# and I'm not sure why that works... Or maybe this is a NT thing?

                    I dunno. Either way it works around the whole 'static' member with a 2nd object instance issue.

                    This works for me.

                    Thanks for all the help.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bmartz, 03-12-2024, 06:12 AM
                    4 responses
                    31 views
                    0 likes
                    Last Post bmartz
                    by bmartz
                     
                    Started by Aviram Y, Today, 05:29 AM
                    4 responses
                    12 views
                    0 likes
                    Last Post Aviram Y  
                    Started by algospoke, 04-17-2024, 06:40 PM
                    3 responses
                    28 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by gentlebenthebear, Today, 01:30 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by cls71, Today, 04:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X