• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to gain access to the properties of a foreign indicator in a strategy?

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

    How to gain access to the properties of a foreign indicator in a strategy?

    Using the inherent indicators in Ninjatrader, I can easily access to their properties. For example,
    private Stochastics Stochastics1;
    then I define,
    Stochastics1 = Stochastics(Close, 11, 11, 1);
    In the body of my strategy I can gain access to the D value of the stochastics by something like
    if (Stochastics1.D[0] == Close[0])

    But when it comes to the attachment uploaded, I came across "'NinjaTrader.NinjaScript.Indicators.FractalPivots .highval' is inaccessible due to its protection level" when I tried to use some of the variables in the foreign indicator.
    In the attachment I upload, from where can I identify what the usable variables(like Stochastics1.D in Stochastics) are and how can I lower the protection level so that I can make use of it in my strategy?

    GREAT THX!
    Attached Files

    #2
    Hello alantse123,

    Thank you for the post.

    I see that in the indicator, the highval variable is not exposed or made public so the error would be correct. You cannot access private variables from outside the class of the indicator. To access this value, you would need to make a public property and expose the value in a correct way for that purpose.

    We have a sample that goes over exposing values that are not plots in the following guide: https://ninjatrader.com/support/help...alues_that.htm

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello alantse123,

      Thank you for the post.

      I see that in the indicator, the highval variable is not exposed or made public so the error would be correct. You cannot access private variables from outside the class of the indicator. To access this value, you would need to make a public property and expose the value in a correct way for that purpose.

      We have a sample that goes over exposing values that are not plots in the following guide: https://ninjatrader.com/support/help...alues_that.htm

      I look forward to being of further assistance.
      I tried my best but still failed. Could you directly help me to modify the following file so that I can see Fractals1.HighPivot[0] and Fractals1.LowPivot[0] in the output window. ( given that I have defined "private Fractals Fractals1;") THANK YOU VERY MUCH if you could help!

      Comment


        #4
        Hello alantse123,

        While our support cannot make direct edits for you, we can try to assist with questions you may have surrounding what you are trying. With that being said, can you provide more detail on what you tried and what result you had seen? I won't be able to assist without the information surrounding what you tried, with more information or error messages we may be able to work out what you were doing wrong to provide a solution.

        In regard to changing the private variable to expose it, If you need to access this value from outside the script you can change the property to be public, but you would likely need to do it in the way described in the prior link I had provided. The variable only has context while being used in that indicator, from outside the indicator the value has no relation to a specific point in time like a Plot. A Plot or Series could be used to store values over time which also gives other scripts access which is relevant toward specific bars. If you just need to access the value at any given time with no context of what that value accounts for, you can make it public and use the Update() method.

        https://ninjatrader.com/support/help...-us/update.htm



        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello alantse123,

          While our support cannot make direct edits for you, we can try to assist with questions you may have surrounding what you are trying. With that being said, can you provide more detail on what you tried and what result you had seen? I won't be able to assist without the information surrounding what you tried, with more information or error messages we may be able to work out what you were doing wrong to provide a solution.

          In regard to changing the private variable to expose it, If you need to access this value from outside the script you can change the property to be public, but you would likely need to do it in the way described in the prior link I had provided. The variable only has context while being used in that indicator, from outside the indicator the value has no relation to a specific point in time like a Plot. A Plot or Series could be used to store values over time which also gives other scripts access which is relevant toward specific bars. If you just need to access the value at any given time with no context of what that value accounts for, you can make it public and use the Update() method.

          https://ninjatrader.com/support/help...-us/update.htm



          Please let me know if I may be of further assistance.
          Let me explain the image first. Inside the white circle, the dots are the "Fractal" of my indicator. You can the they are attached to specific prices/values. I try to access those values so that I can do something like if the price goes up and is higher than the latest dot, then enter long. But the Fractals1.LowPivot[0] always equals 0.

          If you cannot make direct edits for me, could you please tell me how I can edit the Fractals.cs so that I can do something like if the price goes up and is higher than the latest dot, then enter long?

          THANK YOU VERY MUCH.

          Comment


            #6
            Hello alantse123,

            Thank you for the reply.

            I reviewed the changes you made to this file and I can see that you have added some plots. It looks like those are also working at displaying some points on the chart. I did notice you used Dot type plots and see that the plots are only being set occasionally meaning it is not a continuous plot. Another factor is that you are not setting the current bars value for the plot, this is where the disconnect is between the two scripts.

            The print being used is printing the 0 BarsAgo value which is always 0 based on how the Fractals is programmed. The Fractals is setting the bar of period ago:
            Code:
             LowPivot[period] = Low[period]-tick_multiply*TickSize;
            From an outside script, it has no context of where in BarsAgo a value was set, you would need to know what period was used to access the data for that BarsAgo from a different script.

            There are a few ways to approach this. You could experiment with setting the Current bars value instead of period:
            Code:
             LowPivot[0] =
            however as this is not a continuous plot you will still see a lot of zeros and occasionally the pivot value with your print. The other alternative would be to rework the indicators logic so that it sets a continuous pivot value to the plot until a new pivot is found and so on. The continuous value is the important part, this is what would allow another script to use the [0] bars ago to access a price easily for the current bar.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello alantse123,

              Thank you for the reply.

              I reviewed the changes you made to this file and I can see that you have added some plots. It looks like those are also working at displaying some points on the chart. I did notice you used Dot type plots and see that the plots are only being set occasionally meaning it is not a continuous plot. Another factor is that you are not setting the current bars value for the plot, this is where the disconnect is between the two scripts.

              The print being used is printing the 0 BarsAgo value which is always 0 based on how the Fractals is programmed. The Fractals is setting the bar of period ago:
              Code:
               LowPivot[period] = Low[period]-tick_multiply*TickSize;
              From an outside script, it has no context of where in BarsAgo a value was set, you would need to know what period was used to access the data for that BarsAgo from a different script.

              There are a few ways to approach this. You could experiment with setting the Current bars value instead of period:
              Code:
               LowPivot[0] =
              however as this is not a continuous plot you will still see a lot of zeros and occasionally the pivot value with your print. The other alternative would be to rework the indicators logic so that it sets a continuous pivot value to the plot until a new pivot is found and so on. The continuous value is the important part, this is what would allow another script to use the [0] bars ago to access a price easily for the current bar.

              I look forward to being of further assistance.
              Oh yes! I made it! THANK YOU SO MUCH, Jesse!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by chrismcdermut, Yesterday, 01:46 PM
              3 responses
              19 views
              0 likes
              Last Post MojoJojo  
              Started by Bricolico, Yesterday, 09:28 PM
              0 responses
              5 views
              0 likes
              Last Post Bricolico  
              Started by Tradwell385, Yesterday, 08:51 PM
              0 responses
              7 views
              0 likes
              Last Post Tradwell385  
              Started by dvcpro4, Yesterday, 07:08 PM
              0 responses
              22 views
              0 likes
              Last Post dvcpro4
              by dvcpro4
               
              Started by pennywise, Yesterday, 06:40 PM
              0 responses
              8 views
              0 likes
              Last Post pennywise  
              Working...
              X