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

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.





        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.





          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 andrewtrades, Today, 04:57 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by chbruno, Today, 04:10 PM
              0 responses
              3 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by josh18955, 03-25-2023, 11:16 AM
              6 responses
              436 views
              0 likes
              Last Post Delerium  
              Started by FAQtrader, Today, 03:35 PM
              0 responses
              7 views
              0 likes
              Last Post FAQtrader  
              Started by rocketman7, Today, 09:41 AM
              5 responses
              19 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X