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

Can I access Public Indicator Variables from Strategy

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

    Can I access Public Indicator Variables from Strategy

    Hello Gurus

    I have an Indicator with following public variables defined in the indicator


    MyIndicator
    {
    public double CurrentHI
    public double CurrentLO
    // Followed by some calcuation to decide the values of these two.
    // in the onbarupdate method
    // I AM NOT PLOTTING THESE ON THE INDICATOR. I am plotting some other things
    } //end My Indicator



    In MyStrategy I need to access these two variables for making some decision and my code is looking somehting like following

    MyStrategy
    {

    initialize
    {
    Add(MyIndicator) // This takes care of plotting part which is working fine
    } //end initialize

    onbarupdate
    {

    if (MyIndicator().CurrentHI >= 1000)
    {
    //do something i.e. Enter long
    }//end if

    } // end onbarupdate

    } //end my strategy

    The thing is ..
    there is no compilation error and strategy compile perfectly..
    but when I run it, Anything Inside of the IF doesnt get executed...
    I am wondering why .

    Tried this twice with two different indicators.. doesnt work..
    HOWEVER.. when I copy paste all the code from indicator into the strategy ... the execution works.. NOW THAT TAKES AWAY the capability to plot the other things I wanna plot..

    HELP HELP HELP

    Thanks
    R

    #2
    Instead of using public variables, use private variables and access them through a public property. In the getter of the property, call the Update() method.

    Code:
    get
    {
        Update();
        return currentHi;
    }
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks Ray. I will try that. One Question again.

      For each of the variables, I need to define a public property?

      This will get pretty lenghty if I have 10 Variables that need to be accessed from outside.. Is there any simpler way?

      You guys rock. Amazingly fast response.

      Comment


        #4
        The other option is storing the data in any IDataSeries implemented series such as DataSeries, IntSeries etc...This still requires a public property but you might not need to call the Update() method.

        The issue is when you don't store values as plot values, then NT does not internally trigger OnBarUpdate() if a tick does not come in, such as in a backtest thus you need to call Update() to force the indicator to be updated at the time you access the property value.
        RayNinjaTrader Customer Service

        Comment


          #5
          Great Help!!! Thank you so much!!

          Comment


            #6
            Hmm, I am trying to do this but where exactly is the Update() method? Am I missing an include?

            Code:
                    [Description("")]
                    [Category("Parameters")]		
            		public double LegAStdDev
            		{
            			get 
            			{ 
            				Update();
            				return legAStdDev;
            			}
            		}

            Comment


              #7
              Oh wait, is this the Update() method from the IndicatorBase class? I am trying to expose a double from a strategy, so that my indicator can plot it. Essentially avoiding StrategyPlot.

              Originally posted by Tight Face View Post
              Hmm, I am trying to do this but where exactly is the Update() method? Am I missing an include?

              Code:
                      [Description("")]
                      [Category("Parameters")]		
              		public double LegAStdDev
              		{
              			get 
              			{ 
              				Update();
              				return legAStdDev;
              			}
              		}

              Comment


                #8

                It is more for NinjaScript Strategies.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  OK. So I can get values from an indicator, but not from a strategy. Correct?

                  So the question then becomes, why don't I just put the indicator logic in an indicator. It was originally, but I can't seem to calculate a multi-instrument from within an indicator, which is why I dragged the code in to a strategy where it now works correctly.

                  Comment


                    #10
                    From what we can offer support for, yeah. Multi-instrument or multi-time framed indicators will be available in NT7 and then all of these workaround techniques will not be needed anymore. Thank you for your patience in this matter.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Glad to hear. Cant wait til the beta is released.

                      Comment


                        #12
                        Any time frame for NT7 Beta release date?

                        Comment


                          #13
                          I meant to ask whether it is December 08 or november 08 .. or jan 09 or feb 09.....
                          I have read that it is scheduled for later in 08... but we are almost in the later 08 part so i am waiting eagerly

                          Comment


                            #14
                            End of year time frame is all I can provide.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jclose, Today, 09:37 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post jclose
                            by jclose
                             
                            Started by WeyldFalcon, 08-07-2020, 06:13 AM
                            10 responses
                            1,414 views
                            0 likes
                            Last Post Traderontheroad  
                            Started by firefoxforum12, Today, 08:53 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post firefoxforum12  
                            Started by stafe, Today, 08:34 PM
                            0 responses
                            11 views
                            0 likes
                            Last Post stafe
                            by stafe
                             
                            Started by sastrades, 01-31-2024, 10:19 PM
                            11 responses
                            169 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X