Announcement

Collapse
No announcement yet.

Moving average of RSI

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

  • Moving average of RSI

    Thank you ahead of time for any help people are willing to offer. I am new to Esignal and working on the programming as much as possible.

    I am trying to make a 10 day moving average of the 20 day RSI (minus 50), with no user inputs.

    When it plots, it looks very similar to a regular 10 day ema of price...nothing to do with the RSI I want as the underlying data. Any thoughts on how I can correct this? Thanks again!

    So far I have:

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ABC");
    setCursorLabelName("ABC", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    }

    function main() {

    var RSIXYZ = rsi(20)-50;


    var ABC = ema(10,RSIXYZ);

    return ABC;
    }

  • #2
    Re: Moving average of RSI

    wallnbroad
    The reason the plot returned by your script is an exponential average rather than a derivative of the RSI is because the variable RSIXYZ is not a series as required by the ema() function for a custom source but a single value hence it is interpreted by the formula engine as the bar index parameter
    To create a series of RSI-50 you need to calculate that equation in a separate function or external efs and then retrieve the result of that calculation using the efsInternal() or efsExternal() functions. The series created by the efsInternal() or efsExternal() functions can then be used as a source for the built-in studies.
    For the description of the efsInternal() and efsExternal() functions and the required syntax see the links above which will take you to the corresponding articles in the EFS KnowledgeBase.
    Also try searching the forum as there are many more examples of studies based on custom variables as this topic has been discussed at length many times before
    That said given that calculating the exponential average of the result of the RSI study minus 50 is the same as calculating the exponential average of the RSI and then subtracting 50 from that the easiest solution would probably be to write your script as shown below
    Alex

    PHP Code:
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("ABC");
        
    setCursorLabelName("ABC"0);
        
    setDefaultBarFgColor(Color.blue0);
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setDefaultBarThickness(1,0);
    }
    var 
    xABC null;
    function 
    main() {
        if(
    getBarState()==BARSTATE_ALLBARSxABC ema(10,rsi(20));
        var 
    nABC xABC.getValue(0);
        if(
    nABC==null) return;
        return 
    nABC-50;


    Originally posted by wallnbroad
    Thank you ahead of time for any help people are willing to offer. I am new to Esignal and working on the programming as much as possible.

    I am trying to make a 10 day moving average of the 20 day RSI (minus 50), with no user inputs.

    When it plots, it looks very similar to a regular 10 day ema of price...nothing to do with the RSI I want as the underlying data. Any thoughts on how I can correct this? Thanks again!

    So far I have:

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ABC");
    setCursorLabelName("ABC", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    }

    function main() {

    var RSIXYZ = rsi(20)-50;


    var ABC = ema(10,RSIXYZ);

    return ABC;
    }

    Comment

    Working...
    X