Announcement

Collapse
No announcement yet.

Syntax error in "Cutler's RSI"

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

  • Syntax error in "Cutler's RSI"

    Hallo Forum

    I'm getting a syntax error in "Cutler's RSI". Can anyone correct my mistake?



    function main () {


    var a = efsInternal("a");

    var b = efsInternal("b");



    var Upgain = sma(10,efsInternal("a"));

    var Downgain = sma(10,efsInternal("b"));

    var RS = if (Downgain = 0 {100} [else {Upgain/Downgain} ];

    return 100 - (100/(1+RS));





    function a() {

    if (close>(close(-1)) {
    close-close(-1)
    }
    [else {
    0
    } ]


    function b() {

    if (close<(close(-1)) {
    close(-1)-close
    }
    [else {
    0
    } ]
    }
    Attached Files
    Last edited by gotan4711; 07-18-2013, 08:40 AM.

  • #2
    I don't have anything to compare it against for accuracy but try this version to see if it meets your needs.

    PHP Code:
    var SumUp SumDown 0;
    var 
    bInit=false;
    function 
    main(Periods,Length){ 
        if(
    Periods==nullPeriods=14;
        if(
    Length==nullLength=10;
        var 
    RS 100;
        var 
    i;
        if(
    Periods>getCurrentBarCount()) return;
        for(
    i=0;i<Periods;i++){
            var 
    difference close(-i) - close(-i-1);
            if (
    difference 0SumUp SumUp difference;
            if (
    difference 0SumDown SumDown Math.abs(difference);
        }
        if(
    SumDown 0){
            
    RS = (SumUp/Length) / (SumDown/Length);
        }
        return 
    100 - (100/(1+RS)); 

    Wayne
    Last edited by waynecd; 07-18-2013, 02:32 PM.

    Comment


    • #3
      Wrong script

      Originally posted by waynecd View Post
      I don't have anything to compare it against for accuracy but try this version to see if it meets your needs.

      PHP Code:
      var SumUp SumDown 0;
      var 
      bInit=false;
      function 
      main(Periods,Length){ 
          if(
      Periods==nullPeriods=14;
          if(
      Length==nullLength=10;
          var 
      RS 100;
          var 
      i;
          if(
      Periods>getCurrentBarCount()) return;
          for(
      i=0;i<Periods;i++){
              var 
      difference close(-i) - close(-i-1);
              if (
      difference 0SumUp SumUp difference;
              if (
      difference 0SumDown SumDown Math.abs(difference);
          }
          if(
      SumDown 0){
              
      RS = (SumUp/Length) / (SumDown/Length);
          }
          return 
      100 - (100/(1+RS)); 

      Wayne

      Hallo Wayne


      I am afraid your script wont do. If you take a look at my attached pic, you will see how it's suppose to look. As a matter of fact "Cutler's RSI" (or just "RSI") is shaped exactly like "Chande's momentum oscillator", which uses a scale from -100 to 100. instead of 0 to 100. Apart from that I would say, that the most important and characteristic difference between "Wilder's RSI" build into E-signal and "Cutler's RSI" is the moving averages. Cutler's uses a simpel moving average; Wilder an exponential. In your script the moving average aren't present at all.

      I still hope you can and will tell me what is wrong with my script....?



      Kind ragards

      Gotan4711
      Attached Files

      Comment


      • #4
        Mads
        FYI virtually every line of your script contains a syntax and/or construct and/or logic error
        The enclosed screenshot illustrates what these are and shows you how to correct them



        Once you implement all the suggested changes this is what the formula will return to the chart (note that there are other changes that could be implemented in the script but they are inconsequential to the issue at hand)
        As you can see the plot matches exactly that shown in your image




        Since you appear to be quite unfamiliar with programming in efs it would benefit you to learn especially if you plan on using formulas.
        To do this I would suggest that you review the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Once you have done that go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
        Alex


        Originally posted by gotan4711 View Post
        Hallo Forum

        I'm getting a syntax error in "Cutler's RSI". Can anyone correct my mistake?



        function main () {


        var a = efsInternal("a");

        var b = efsInternal("b");



        var Upgain = sma(10,efsInternal("a"));

        var Downgain = sma(10,efsInternal("b"));

        var RS = if (Downgain = 0 {100} [else {Upgain/Downgain} ];

        return 100 - (100/(1+RS));





        function a() {

        if (close>(close(-1)) {
        close-close(-1)
        }
        [else {
        0
        } ]


        function b() {

        if (close<(close(-1)) {
        close(-1)-close
        }
        [else {
        0
        } ]
        }

        Comment


        • #5
          Mads
          While waynecd's formula is not returning the correct results this is not for lack of using simple moving averages because as a matter of fact it is [using them] even though the code logic that calculates them escapes you. Perhaps you should wait to have a better understanding of efs programming prior to making comments such as yours
          As to what is wrong with your script I would say pretty much everything as you can see from my previous reply
          Alex


          Originally posted by gotan4711 View Post
          Hallo Wayne


          I am afraid your script wont do. If you take a look at my attached pic, you will see how it's suppose to look. As a matter of fact "Cutler's RSI" (or just "RSI") is shaped exactly like "Chande's momentum oscillator", which uses a scale from -100 to 100. instead of 0 to 100. Apart from that I would say, that the most important and characteristic difference between "Wilder's RSI" build into E-signal and "Cutler's RSI" is the moving averages. Cutler's uses a simpel moving average; Wilder an exponential. In your script the moving average aren't present at all.

          I still hope you can and will tell me what is wrong with my script....?



          Kind ragards

          Gotan4711

          Comment

          Working...
          X