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

Using indicator values

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

    Using indicator values

    How would I go about assigning indicator plot values to a variable in a strategy? Currently I have an indicator that provides/plots an entry level. However the actual entry will only occur when that level is pierced, which normally happens a few bars after the plot.

    So what I am asking is how I can store a value derived from an indicator in a strategy and once price breaks that value, a trade is entered.

    As you can see in the picture, the indicator fires at 18:15, however, the buy zone (between the blue dots) is only pierced at 18:30.

    I have tried using the examples for using an indicator's plots in a strategy and these do not work as I think that it has to occur on the same bar, which this is not.

    Any ideas would be most helpful.
    Attached Files

    #2
    Code:
    storeValue = myIndicator()[0];
    Then you can do something like:
    Code:
    if (Close[0] >= storeValue)
         EnterLong();
    or any other logic you may want to use.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Much appreciated

      Thanks for the quick response, will give it a go once the markets close. Thx again.

      Comment


        #4
        Taking this a step further

        Where would I put my variable from the indicator in the code that you pprovided ...

        storeValue = myIndicator()[0];

        Would it be ...

        storeValue = GartleyRobotBull(BullDa)[0];

        where GartleyRobotBull is the indicator and BullDa is the variable within the indicator that contains the value that I need?

        Comment


          #5
          traderT,

          You need to first create the storeValue variable as a double in the Variables region of your code.
          Code:
          private double storeValue = 0;
          Then you would use the code inside the OnBarUpdate() method. I do not know how your indicator works and how to access the particular variables for your indicator. I suggest you ask the original author of it.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            The original author is useless

            I am the orginal author ;-)

            I understand that storeValue would need to be defined.

            Within my indicator I have the following line...

            privatedouble BullDa(){return (BullCa() + (1.27 * (BullB() - BullCa())));}

            So, in my strategy, I want to set storeValue = myIndicator.BullDa

            And then have ...

            if (Low[0] <= storeValue)
            EnterLong();


            What I need to know is the syntax for myIndicator.BullDa if it is possible, or, if not, then what type of syntax would I need.

            I have only been doing c# for a couple of months so I am still fudging my way through stuff and have managed to write a few indicators (You and the team have helped me quite a bit with the indicators that I wrote (Gartley and deMark indicators), but am now want to incorporate them into strategies, which I have not done as yet, hence the dumb questions ( I promise to make them more complicated as I learn more ;-)

            Comment


              #7
              You need to expose your indicator variable then. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4991
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                So something like this wouldn't work ...

                if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
                {
                (storeValue = (GartleyRobotBull(
                5, 2, 65).BullDa[0]))
                }

                Am having a look at the sample stuff now

                Comment


                  #9
                  Originally posted by traderT View Post
                  if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
                  {
                  (storeValue = (GartleyRobotBull(
                  5, 2, 65).BullDa[0]))
                  }

                  Am having a look at the sample stuff now
                  Yea, that wouldn't work because you closed the if-statement too early. You need to watch your parenthesis placement.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    So what do I need to change to make this work?

                    if (GartleyRobotBull(5, 2, 65).BullDa[0]) > 0
                    {
                    (storeValue = (GartleyRobotBull(
                    5, 2, 65).BullDa[0]))
                    }


                    Comment


                      #11
                      Code:
                      if (condition[SIZE=4][B][COLOR=Red])[/COLOR][/B][/SIZE]
                      {
                         // code[SIZE=5][COLOR=Red];[/COLOR][/SIZE]
                      }
                      Lines need to end with ;
                      This is C# programming. I suggest you go to MSDN or google some resources for a starters guide to C# programming.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        if ((GartleyRobotBull(5, 2, 65).BullDa[0]) > 0)
                        {
                        storeValue = GartleyRobotBull(
                        5, 2, 65).BullDa[0];
                        }

                        Sorry, I figured that out, however (hopefully last question), now I get a protection level error. Do I have to declare BullDa as a public variable in my indicator?

                        Comment


                          #13
                          Please see the reference sample for how to expose the variable via a public property.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          40 views
                          0 likes
                          Last Post alifarahani  
                          Started by Waxavi, Today, 02:10 AM
                          1 response
                          18 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Started by Kaledus, Today, 01:29 PM
                          5 responses
                          15 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X