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

defining an indicator type variable

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

    defining an indicator type variable

    In a Strategy, I can define a variable of an Indicator.
    private Indicator.ERG_Trade T_ERG;

    which makes it very easy to access and set Exposed Variables:
    T_ERG.AlertSound = gong.wav;

    Unfortunately, this does not appear to work in another indicator. Why not?
    Is a different syntax used?

    #2
    OK, it compiles if I remove the Indicator. and just write
    private ERG_Trade T_ERG;

    But if I then use T_ERG in OnStartUp() or OnBarUpdate(), I get another error =
    The name T_ERG does not exit in the current context.

    Other variable types do not cause this error, so something is still missing...

    Comment


      #3
      Hello,

      Thanks for the note.

      To be honost I never have used that setup to reference indicators and its not a supported method in our NinjaScript guide. Not sure where you're instantiating the object however this error most likely comes from the fact that its private and the method does not have access to that private object. Which means declaring the object and moving it down into Initialize also which would use up more system resources or trying it as a public.

      The supported method to do this is to expose indicator values that are not plots using this guide here.



      Let me know if I can be of further assistance.

      Comment


        #4
        Originally posted by Lost Trader View Post
        OK, it compiles if I remove the Indicator. and just write
        private ERG_Trade T_ERG;

        But if I then use T_ERG in OnStartUp() or OnBarUpdate(), I get another error =
        The name T_ERG does not exit in the current context.

        Other variable types do not cause this error, so something is still missing...
        After declaring it, you must initiate an instance, then access that instance.

        See example here: http://www.ninjatrader.com/support/f...06&postcount=1

        Comment


          #5
          OK, the error was because I left the () on the T_ERG -- that was just a stupid mistake.
          This works in a Strategy and so it should work in an Indicator.

          I am familiar with that SampBoolSeries example. It does not illustrate one indicator calling/embedding another indicator and its exposed variables and therefore does not help in this instance. It does illustrate a simple version of a Strategy reading an Indicator's exposed variables.

          You may want to update it or add another example for an Indicator both reading and setting another Indicator's exposed variables.

          Comment


            #6
            That's interesting, koganam! I had the instantiation in Initialize() because that's the way it worked in the Strategy, and put the variable setting in OnStartUp() to ensure that User Input changes would get picked up (I've been burned before because if a User changes an input via the Indicator panel on a chart, Initialize() will not see that change.)
            I do wish for more code consistency between Indicator & Strategy...

            So in the Indicator, I moved all statements to OnStartUp() :
            T_ERG = ERG_Trade(Input);
            T_ERG.BasePrime = BasePrime; T_ERG.M3 = m3;

            It certainly changed the behavior. Now I've got another idiot mistake somewhere:
            ERG_Trade: Object reference not set to an instance of an object. It is interesting because the error is generated by the Called Indicator T_ERG = ERG_Trade() and not when ERG_Trade is placed on a chart. Hmmm...

            Comment


              #7
              Well silly me. I found the code error:
              Code:
              if (enLTSBarColor)    
                              if (ChartControl.ChartStyleType == ChartStyleType.CandleStick) CandleOutlineColor = ltsColor;
                              else BarColor = ltsColor;
              Since calling the Indicator has no Chart, this spit up.
              Changing the condition check to if (enLTSBarColor && ChartControl!=null) fixed it.

              Comment


                #8
                Actually I meant the earliest part of the indicator, when values can be unstable. For example, if you have a calculation which accesses a bar 6 bars ago, and you do not escape the first 6 bars, with: if (CurrentBar < 6) return; you are likely going to have a problem.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                3 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                6 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Working...
                X