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

Indicator proportional to another

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

    Indicator proportional to another

    Perhaps I placed my concern in the wrong place. My request seems simple. I want to allow other indicators to move proportionally with one indicator that has an assigned value for optimization. For example, if I assign the value of 200 to a SMA, I would like the value of the RSI to be (SMA*.25). When the optimized value of the SMA changes, the RSI will also change without having to separately optimize it. Can anyone help me with this. I have searched the help files and videos and forums and internet to no avail. I simply want the value of the RSI to be (SMA*.25) once the value of the SMA is declared. Please advise.

    #2
    Hello birdjaguar,

    Thanks for your post.

    It sounds like then you would want to set a user parameter for the SMA value and then in the code set your RSI to that variable * .25.

    You may want to put some code in place to ensure that the RSI period would be no lower than some set minimum level. Such as RSI(Math.Max(5, value)) // uses the maximum of 5 or value if greater than 5.

    Please see our reference information on creating user defined inputs:http://ninjatrader.com/support/forum...ead.php?t=5782
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you. I am familiar with creating user defined inputs. I have a user defined input for the SMA. That doesn't help me at all, with my question. Your interpretation of the question is correct.

      "set a user parameter for the SMA value and then in the code set your RSI to that variable * .25."

      Again, how can I set the value of the RSI to a fraction of the user defined input of the SMA?

      Comment


        #4
        Hello birdjaguar,

        Thank you for your response.

        Likely you have errors because creating a fraction of a whole value is likely creating a double value seeing as the value you multiply has a decimal.

        So you need to take a few steps here. Based on the code you provided at the following thread I will provide an example below: http://ninjatrader.com/support/forum...ad.php?t=90904
        Code:
        			int RSIPeriod = Convert.ToInt32(SMAPeriod * .25);
        			MySMA = SMA(SMAPeriod);
        			MyRSI = RSI(RSIPeriod, 1);
        I recommend reviewing our educational materials as you appear to be coming over from another charting platform's programming language (based on your code in the other thread).

        Education: http://ninjatrader.com/support/helpG..._resources.htm

        Comment


          #5
          Thank you for your response. I did peruse the educational resources to no avail. There was nothing there that actually helps with this code. I also tried your code to no avail, or maybe I just don't understand where it goes. I am at a loss as to why this is difficult and I am surprised that this has no come up before. Also, the "ConvertTo." syntax doesn't even come up in the search engine. How do I get from the following code to the RSI calculating as the SMA*.25?

          #region Variables
          int sMAperiod = 200;
          int RSIPeriod = Convert.ToInt32(SMAPeriod * .25);

          #region Properties
          [Description("")]
          [GridCategory("Parameters")]
          public int SMAperiod
          {
          get { return sMAperiod; }
          set { sMAperiod = Math.Max(1, value); }
          }

          [Description("")]
          [GridCategory("Parameters")]
          public int RSIperiod
          {
          get { return rSIperiod; }
          set { rSIperiod = Math.Max(1, value); }
          }

          Comment


            #6
            Hello birdjaguar,

            ConvertTo is C#, please provide your full indicator and I will show you how to add this in.
            Your indicator file is located under Documents\NinjaTrader 7\bin\Custom\Indicators. Please attach to your response.

            Comment


              #7
              Originally posted by birdjaguar View Post
              Thank you for your response. I did peruse the educational resources to no avail. There was nothing there that actually helps with this code. I also tried your code to no avail, or maybe I just don't understand where it goes. I am at a loss as to why this is difficult and I am surprised that this has no come up before. Also, the "ConvertTo." syntax doesn't even come up in the search engine. How do I get from the following code to the RSI calculating as the SMA*.25?

              #region Variables
              int sMAperiod = 200;
              int RSIPeriod = Convert.ToInt32(SMAPeriod * .25);

              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public int SMAperiod
              {
              get { return sMAperiod; }
              set { sMAperiod = Math.Max(1, value); }
              }

              [Description("")]
              [GridCategory("Parameters")]
              public int RSIperiod
              {
              get { return rSIperiod; }
              set { rSIperiod = Math.Max(1, value); }
              }
              Code:
              #region Variables
              private int sMAperiod = 200;
              private int RSIPeriod = 0;
              
              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public int SMAperiod
              {
              get { return sMAperiod; }
              set { sMAperiod = Math.Max(1, value); 
                     RSIPeriod = Convert.ToInt32(sMAPeriod * .25);}
              }
              Remember to remove the public property for the RSI.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              36 views
              0 likes
              Last Post love2code2trade  
              Started by alifarahani, Today, 09:40 AM
              2 responses
              13 views
              0 likes
              Last Post alifarahani  
              Started by junkone, Today, 11:37 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by pickmyonlineclass, Today, 12:23 PM
              0 responses
              2 views
              0 likes
              Last Post pickmyonlineclass  
              Started by frankthearm, Yesterday, 09:08 AM
              12 responses
              44 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X