Announcement

Collapse
No announcement yet.

Facing an error in creating a Inverse Fisher transform of a smoothed RSI

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

  • Facing an error in creating a Inverse Fisher transform of a smoothed RSI

    Having an error with this code--

    var RSI = null;
    var WMA1 = null;
    var WMA2 = null;
    var WMA3 = null;
    var fpArray = new Array();

    function preMain(){
    setStudyTitle("INVERSE FISHER TRANSFORM OF RSI");
    setCursorLabelName("IFish",0);
    setDefaultBarFgColor(Color.RGB(0x00,0xc9,0x57),0);
    addBand(.75, PS_SOLID, 1, Color.black);
    addBand(-.75, PS_SOLID, 1, Color.black);
    setDefaultBarThickness(2);
    //setComputeOnClose();
    InitFunctionParameter();
    }

    function main(RSI_Length,hma_length){

    hmaLength = hma_length;//default 9
    rsiLength = RSI_Length;//default 5

    if (RSI == null) RSI = rsi(rsiLength,close());
    if (WMA1== null) WMA1 = wma(hma_length,RSI);
    if (WMA2== null) WMA2 = wma(Math.floor(hma_length/2),RSI);

    if(getCurrentBarCount() < RSI_Length + 5*hma_length) return;

    var i = 0;
    var sum =0;
    var Length = Math.floor(Math.sqrt(hma_length));
    for (i=0; i < Length; i++)
    sum = sum + (Length-i) ( 2*(WMA2.getValue(-i)) - WMA1.getValue(-i));
    Value = 2*sum/Length/(Length+1);


    var IFish = 0;

    IFish = (Math.exp(2 * Value) - 1) / (Math.exp(2 * Value) + 1);

    if(IFish > 0) setBarFgColor(Color.green)
    else setBarFgColor(Color.red);

    return IFish;


    }


    function InitFunctionParameter()
    {
    var x = 0;

    fpArray[x] = new FunctionParameter("RSI_Length", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
    setName("RSI_Length");
    setLowerLimit(1);
    setDefault(9);
    }

    fpArray[x] = new FunctionParameter("hma_length", FunctionParameter.NUMBER);
    with(fpArray[x++])
    {
    setName("hma_length");
    setLowerLimit(1);
    setDefault(5);
    }
    }
    Last edited by indus383; 05-28-2014, 01:44 AM.

  • #2
    Issue resolved, a small coding error

    sum = sum + (Length-i) ( 2*(WMA2.getValue(-i)) - WMA1.getValue(-i));

    has to be replaced with sum = sum + (Length-i) * ( 2*(WMA2.getValue(-i)) - WMA1.getValue(-i));

    Comment

    Working...
    X