Announcement

Collapse
No announcement yet.

RSI Bands hlc3 source

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

  • RSI Bands hlc3 source

    This is a section of script for RSI Bands. I'd like to make the source price "hlc3" rather than close?

    I'm happy with adding the addoption and functionparameter (string) but need a little help where to add the "source" within the funtion main.

    PHP Code:
    function main(nPeriodsnUppernLowercColorUcColorLnThickbClamp) {
        var 
    nState getBarState();
        var 
    nIndex getCurrentBarIndex();
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        
        
        if (
    bInit == false) {
            
    setStudyTitle("RSI Bands (" nPeriods ", " nUpper ", " nLower ")");
            
    setCursorLabelName("RSIB"+nUpper0);
            
    setCursorLabelName("RSIB"+nLower1);
            
    setDefaultBarFgColor(cColorU0);
            
    setDefaultBarFgColor(cColorL1);
            
    setDefaultBarThickness(nThick0);
            
    setDefaultBarThickness(nThick1);
            
            
    xUpperRSI efsInternal("RSI_Band"nPeriodsnUpperbClamp );
            
    xLowerRSI efsInternal("RSI_Band"nPeriodsnLowerbClamp );
            
            
    bInit true;
        }
        
        var 
    nUpperRSI xUpperRSI.getValue(0);
        var 
    nLowerRSI xLowerRSI.getValue(0);
        if (
    nUpperRSI == null || nLowerRSI == null) return;
        
        return new Array(
    nUpperRSInLowerRSI);    


  • #2
    Re: RSI Bands hlc3 source

    James88
    You need to pass the source to the external function through the efsInternal() calls eg
    xUpperRSI = efsInternal("RSI_Band", nPeriods, nUpper, bClamp, hlc3() );
    xLowerRSI = efsInternal("RSI_Band", nPeriods, nLower, bClamp, hlc3() );

    and then in the called function you need to add the variable to the arguments of that function eg
    function RSI_Band(param1, param2, param3, mySource)
    and replace the existing source with the variable to which you will assign the source you are passing (in the above example it would be mySource).
    See this thread for a detailed example of how to accomplish this [note that in the example I am referring I use efsExternal() but the logic and syntax are identical when using efsInternal()]
    Alex


    Originally posted by James 88
    This is a section of script for RSI Bands. I'd like to make the source price "hlc3" rather than close?

    I'm happy with adding the addoption and functionparameter (string) but need a little help where to add the "source" within the funtion main.

    PHP Code:
    function main(nPeriodsnUppernLowercColorUcColorLnThickbClamp) {
        var 
    nState getBarState();
        var 
    nIndex getCurrentBarIndex();
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;    
        
        
        if (
    bInit == false) {
            
    setStudyTitle("RSI Bands (" nPeriods ", " nUpper ", " nLower ")");
            
    setCursorLabelName("RSIB"+nUpper0);
            
    setCursorLabelName("RSIB"+nLower1);
            
    setDefaultBarFgColor(cColorU0);
            
    setDefaultBarFgColor(cColorL1);
            
    setDefaultBarThickness(nThick0);
            
    setDefaultBarThickness(nThick1);
            
            
    xUpperRSI efsInternal("RSI_Band"nPeriodsnUpperbClamp );
            
    xLowerRSI efsInternal("RSI_Band"nPeriodsnLowerbClamp );
            
            
    bInit true;
        }
        
        var 
    nUpperRSI xUpperRSI.getValue(0);
        var 
    nLowerRSI xLowerRSI.getValue(0);
        if (
    nUpperRSI == null || nLowerRSI == null) return;
        
        return new Array(
    nUpperRSInLowerRSI);    

    Comment


    • #3
      I've added the source to the external func thru the internal call and added the variable to the ext argument with a string func parameter. I'm not 100% sure about replacing the original source - will that be replacing the "close" with "sSource"?

      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("RSI Bands ");
          
      setCursorLabelName("RSIB70"0);
          
      setCursorLabelName("RSIB30"1);
          
      setShowTitleParameters(false);

          var 
      fp1 = new FunctionParameter("nPeriods"FunctionParameter.NUMBER);
              
      fp1.setName("Periods");
              
      fp1.setLowerLimit(0);
              
      fp1.setDefault(13);
          var 
      fp2 = new FunctionParameter("nUpper"FunctionParameter.NUMBER);
              
      fp2.setName("Upper Band");
              
      fp2.setLowerLimit(0);
              
      fp2.setDefault(70);
          var 
      fp3 = new FunctionParameter("nLower"FunctionParameter.NUMBER);
              
      fp3.setName("Lower Band");
              
      fp3.setLowerLimit(0);
              
      fp3.setDefault(30);
          var 
      fp4 = new FunctionParameter("cColor"FunctionParameter.COLOR);
              
      fp4.setName("Band Color");
              
      fp4.setDefault(Color.blue);
          var 
      fp5 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
              
      fp5.setName("Band Thickness");
              
      fp5.setLowerLimit(1);
              
      fp5.setDefault(1);
          var 
      fp6 = new FunctionParameter("bClamp"FunctionParameter.BOOLEAN);
              
      fp6.setName("Enable Clamping");
              
      fp6.setDefault(false);
          var 
      fp7 = new FunctionParameter("sSource"FunctionParameter.STRING);   //new STRING sSource
              
      fp7.setName("Source");
              
      fp7.addoption("hlc3");
              
      fp7.addoption("close");
              
      fp7.setDefault("hlc3");
      }


      // Global Variables
      var bVersion  null;    // Version flag
      var bInit     false;   // Initialization flag

      var xUpperRSI null;
      var 
      xLowerRSI null;

      function 
      main(nPeriodsnUppernLowercColornThickbClampsSource) {  //added sSource
          
      var nState getBarState();
          var 
      nIndex getCurrentBarIndex();
          if (
      bVersion == nullbVersion verify();
          if (
      bVersion == false) return;    
          
          
          if (
      bInit == false) {
              
      setStudyTitle("RSI Bands (" nPeriods ", " nUpper ", " nLower ")");
              
      setCursorLabelName("RSIB"+nUpper0);
              
      setCursorLabelName("RSIB"+nLower1);
              
      setDefaultBarFgColor(cColor0);
              
      setDefaultBarFgColor(cColor1);
              
      setDefaultBarThickness(nThick0);
              
      setDefaultBarThickness(nThick1);
              
              
      xUpperRSI efsInternal("RSI_Band"nPeriodsnUpperbClamp hlc3() );
              
      xLowerRSI efsInternal("RSI_Band"nPeriodsnLowerbClamp hlc3() );
              
              
      bInit true;
          }
          
          var 
      nUpperRSI xUpperRSI.getValue(0);
          var 
      nLowerRSI xLowerRSI.getValue(0);
          if (
      nUpperRSI == null || nLowerRSI == null) return;
          
          return new Array(
      nUpperRSInLowerRSI);    
      }


      var 
      result null;
      var 
      result_1 null;
      var 
      0;
      var 
      0;
      var 
      P_1 0;
      var 
      N_1 0;

      function 
      RSI_BandperiodTargetRSILevelclampsSource) {    //added sSource
          
      var diff null;
          var 
      HypotheticalCloseToMatchRSITarget 0;
          var 
      nState getBarState();

          if (
      nState == BARSTATE_NEWBAR) {
              
      result_1 result;
              
      P_1 P;
              
      N_1 N;
          }
          
          if (
      close(-period) == null) return; //close original variable to be replaced??

          
      var 0;
          var 
      0;
          var 
      diff close(0) - close(-1);
          if( 
      diff diff;
          if( 
      diff = -diff;
          
      // Compute the hypothetical price close to reach the target RSI level
          // based on yesterday’s RSI and close
          // Depending on if we would need the price to increase or decrease,
          // we use a different formula
          
      if (result_1 != null && result_1 close(-1)) {
              
      HypotheticalCloseToMatchRSITarget close(-1)+P_1-P_1*period-((N_1*period)-N_1)*TargetRSILevel /(TargetRSILevel 100);
          } else {
              
      HypotheticalCloseToMatchRSITarget close(-1)-N_1-P_1+N_1*period+P_1*period+(100*P_1)/TargetRSILevel -(100*P_1*period)/TargetRSILevel;
          }
          
          if (
      clamp == true) {
              
      // Optional clamping code
              // Enable the clamping option in Edit Studies if parameters used cause too much volatility.
              // (generally caused by using a very short period) This will keep the RSI Bands
              // within roughly 10% of the price
              
      if ( (HypotheticalCloseToMatchRSITarget close(-1)) > 0.1*close(-1)) {
                  
      HypotheticalCloseToMatchRSITarget close(-1)*1.1;
              } else if ( (
      HypotheticalCloseToMatchRSITarget close(-1)) < -0.1*close(-1)) {
                  
      HypotheticalCloseToMatchRSITarget close(-1)*0.9;
              }
              
      // Resume standard RSI code to update the running P and N averages
          
      }
          
          
      = ( ( period -) * P_1 ) / period;
          
      = ( ( period -) * N_1 ) / period;

          if (
      getCurrentBarCount() >= period) {
              
      result HypotheticalCloseToMatchRSITarget;
              return 
      result;
          } else {
              return 
      null;
          }
      }


      function 
      verify() {
          var 
      false;
          if (
      getBuildNumber() < 779) {
              
      drawTextAbsolute(535"This study requires version 8.0 or later."
                  
      Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                  
      null13"error");
              
      drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                  
      Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                  
      null13"upgrade");
              return 
      b;
          } else {
              
      true;
          }
          
          return 
      b;

      Comment


      • #4
        James88
        In the external function you will need to replace each instance of close(n) ie where you are retrieving a specific value of the source being passed with sSource.getValue(n)
        Alex


        Originally posted by James 88
        I've added the source to the external func thru the internal call and added the variable to the ext argument with a string func parameter. I'm not 100% sure about replacing the original source - will that be replacing the "close" with "sSource"?

        Comment


        • #5
          That works, however my func para string option of close or hlc3 doesn't? Is the string pointless in this case?

          PHP Code:
           var fp7 = new FunctionParameter("sSource"FunctionParameter.STRING);   //new STRING sSource
                  
          fp7.setName("Source");
                  
          fp7.addoption("hlc3");
                  
          fp7.addoption("close");
                  
          fp7.setDefault("hlc3");
          }


          // Global Variables
          var bVersion  null;    // Version flag
          var bInit     false;   // Initialization flag

          var xUpperRSI null;
          var 
          xLowerRSI null;

          function 
          main(nPeriodsnUppernLowercColorUcColorLnThickbClampsSource) {
              var 
          nState getBarState();
              var 
          nIndex getCurrentBarIndex();
              if (
          bVersion == nullbVersion verify();
              if (
          bVersion == false) return;    
              
              
              if (
          bInit == false) {
                  
          setStudyTitle("RSI Bands (" nPeriods ", " nUpper ", " nLower ")");
                  
          setCursorLabelName("RSIB"+nUpper0);
                  
          setCursorLabelName("RSIB"+nLower1);
                  
          setDefaultBarFgColor(cColorU0);
                  
          setDefaultBarFgColor(cColorL1);
                  
          setDefaultBarThickness(nThick0);
                  
          setDefaultBarThickness(nThick1);
                  
                  
          xUpperRSI efsInternal("RSI_Band"nPeriodsnUpperbClamp hlc3() );//hlc3 added
                  
          xLowerRSI efsInternal("RSI_Band"nPeriodsnLowerbClamp hlc3() );
                  
                  
          bInit true;
              }
              
              var 
          nUpperRSI xUpperRSI.getValue(0);
              var 
          nLowerRSI xLowerRSI.getValue(0);
              if (
          nUpperRSI == null || nLowerRSI == null) return;
              
              return new Array(
          nUpperRSInLowerRSI);    
          }


          var 
          result null;
          var 
          result_1 null;
          var 
          0;
          var 
          0;
          var 
          P_1 0;
          var 
          N_1 0;

          function 
          RSI_BandperiodTargetRSILevelclampsSource) {//argument added
              
          var diff null;
              var 
          HypotheticalCloseToMatchRSITarget 0;
              var 
          nState getBarState();

              if (
          nState == BARSTATE_NEWBAR) {
                  
          result_1 result;
                  
          P_1 P;
                  
          N_1 N;
              }
              
              if (
          sSource.getValue(-period) == null) return;//source added 

          Comment


          • #6
            James88
            It is not working because you are not passing the user selectable source as a parameter of the efsInternal() call. At this time you are just passing hlc3() which is a hard coded in the efsInternal() call. You may want to review the example I linked in my first reply.
            Alex


            Originally posted by James 88
            That works, however my func para string option of close or hlc3 doesn't? Is the string pointless in this case?

            Comment


            • #7
              Alex

              Thank you very much for your help - I've achieved my objective to use hlc3 with your help. Script below if anyone would like it.

              I studied the link you made ref to, and tried to include the variable parameter but must have been doing something wrong.

              Of interest (as I would like to know), do you have to put a variable in the func main internal call? I left the hlc3 and tried to put variable source in the external and sources below that, also tried a variable in the internal - but missed something.

              Kind Regards, James

              PHP Code:
              function preMain() {
                  
              setPriceStudy(true);
                  
              setStudyTitle("RSI Bands ");
                  
              setCursorLabelName("RSIB70"0);
                  
              setCursorLabelName("RSIB30"1);
                  
              setShowTitleParameters(true);

                  var 
              fp1 = new FunctionParameter("nPeriods"FunctionParameter.NUMBER);
                      
              fp1.setName("Periods");
                      
              fp1.setLowerLimit(0);
                      
              fp1.setDefault(13);
                  var 
              fp2 = new FunctionParameter("nUpper"FunctionParameter.NUMBER);
                      
              fp2.setName("Upper Band");
                      
              fp2.setLowerLimit(0);
                      
              fp2.setDefault(70);
                  var 
              fp3 = new FunctionParameter("nLower"FunctionParameter.NUMBER);
                      
              fp3.setName("Lower Band");
                      
              fp3.setLowerLimit(0);
                      
              fp3.setDefault(30);
                  var 
              fp4 = new FunctionParameter("cColorU"FunctionParameter.COLOR);
                      
              fp4.setName("U/Band Color");
                      
              fp4.setDefault(Color.green);
                  var 
              fp5 = new FunctionParameter("cColorL"FunctionParameter.COLOR);
                      
              fp5.setName("L/Band Color");
                      
              fp5.setDefault(Color.red);
                  var 
              fp6 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
                      
              fp6.setName("Band Thickness");
                      
              fp6.setLowerLimit(1);
                      
              fp6.setDefault(1);
                  var 
              fp7 = new FunctionParameter("bClamp"FunctionParameter.BOOLEAN);
                      
              fp7.setName("Enable Clamping");
                      
              fp7.setDefault(false);
              }


              // Global Variables
              var bVersion  null;    // Version flag
              var bInit     false;   // Initialization flag

              var xUpperRSI null;
              var 
              xLowerRSI null;

              function 
              main(nPeriodsnUppernLowercColorUcColorLnThickbClamp) {
                  var 
              nState getBarState();
                  var 
              nIndex getCurrentBarIndex();
                  if (
              bVersion == nullbVersion verify();
                  if (
              bVersion == false) return;    
                  
                  
                  if (
              bInit == false) {
                      
              setStudyTitle("RSI Bands (" nPeriods ", " nUpper ", " nLower ")");
                      
              setCursorLabelName("RSIB"+nUpper0);
                      
              setCursorLabelName("RSIB"+nLower1);
                      
              setDefaultBarFgColor(cColorU0);
                      
              setDefaultBarFgColor(cColorL1);
                      
              setDefaultBarThickness(nThick0);
                      
              setDefaultBarThickness(nThick1);
                      
                      
              xUpperRSI efsInternal("RSI_Band"nPeriodsnUpperbClamp hlc3() );
                      
              xLowerRSI efsInternal("RSI_Band"nPeriodsnLowerbClamp hlc3() );
                      
                      
              bInit true;
                  }
                  
                  var 
              nUpperRSI xUpperRSI.getValue(0);
                  var 
              nLowerRSI xLowerRSI.getValue(0);
                  if (
              nUpperRSI == null || nLowerRSI == null) return;
                  
                  return new Array(
              nUpperRSInLowerRSI);    
              }


              var 
              result null;
              var 
              result_1 null;
              var 
              0;
              var 
              0;
              var 
              P_1 0;
              var 
              N_1 0;

              function 
              RSI_BandperiodTargetRSILevelclampsource) {
                  var 
              diff null;
                  var 
              HypotheticalCloseToMatchRSITarget 0;
                  var 
              nState getBarState();

                  if (
              nState == BARSTATE_NEWBAR) {
                      
              result_1 result;
                      
              P_1 P;
                      
              N_1 N;
                  }
                  
                  if (
              source.getValue(-period) == null) return;

                  var 
              0;
                  var 
              0;
                  var 
              diff source.getValue(0) - source.getValue(-1);
                  if( 
              diff diff;
                  if( 
              diff = -diff;
                  
              // Compute the hypothetical price hlc3 to reach the target RSI level
                  // based on yesterday’s RSI and hlc3
                  // Depending on if we would need the price to increase or decrease,
                  // we use a different formula
                  
              if (result_1 != null && result_1 source.getValue(-1)) {
                      
              Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)+P_1-P_1*period-((N_1*period)-N_1)*TargetRSILevel /(TargetRSILevel 100);
                  } else {
                      
              Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)-N_1-P_1+N_1*period+P_1*period+(100*P_1)/TargetRSILevel -(100*P_1*period)/TargetRSILevel;
                  }
                  
                  if (
              clamp == true) {
                      
              // Optional clamping code
                      // Enable the clamping option in Edit Studies if parameters used cause too much volatility.
                      // (generally caused by using a very short period) This will keep the RSI Bands
                      // within roughly 10% of the price
                      
              if ( (Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)) > 0.1*source.getValue(-1)) {
                          
              Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)*1.1;
                      } else if ( (
              Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)) < -0.1*source.getValue(-1)) {
                          
              Hypotheticalhlc3ToMatchRSITarget source.getValue(-1)*0.9;
                      }
                      
              // Resume standard RSI code to update the running P and N averages
                  
              }
                  
                  
              = ( ( period -) * P_1 ) / period;
                  
              = ( ( period -) * N_1 ) / period;

                  if (
              getCurrentBarCount() >= period) {
                      
              result Hypotheticalhlc3ToMatchRSITarget;
                      return 
              result;
                  } else {
                      return 
              null;
                  }
              }


              function 
              verify() {
                  var 
              false;
                  if (
              getBuildNumber() < 779) {
                      
              drawTextAbsolute(535"This study requires version 8.0 or later."
                          
              Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                          
              null13"error");
                      
              drawTextAbsolute(520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                          
              Color.whiteColor.blueText.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT,
                          
              null13"upgrade");
                      return 
              b;
                  } else {
                      
              true;
                  }
                  
                  return 
              b;

              Comment


              • #8
                James
                You are most welcome
                With regards to your question - assuming I understood correctly what you are asking - the answer is yes you would need to use the variable [that references the source you want to pass] in the efsInternal() call
                Alex


                Originally posted by James 88
                Alex

                Thank you very much for your help - I've achieved my objective to use hlc3 with your help. Script below if anyone would like it.

                I studied the link you made ref to, and tried to include the variable parameter but must have been doing something wrong.

                Of interest (as I would like to know), do you have to put a variable in the func main internal call? I left the hlc3 and tried to put variable source in the external and sources below that, also tried a variable in the internal - but missed something.

                Kind Regards, James

                Comment

                Working...
                X