Announcement

Collapse
No announcement yet.

Range Ratio

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

  • Range Ratio

    I would like to have an efs2 wich computes the following:

    rsi(x,range(y)/range(z))

    For example: a 10 period RSI of the ratio between a 2 day range relative to 20 day range

    I'm not a great programmer so can anyone of you help please?

    Thank you

  • #2
    This should do it.

    Chris

    PHP Code:

    //External Variables
    var grID                0;
    var 
    nBarCounter            0;
    var 
    nStudy1                null;
    var 
    nStudy2                null;
    var 
    nStudy3                null;
    var 
    nStudy4                null;
    var 
    aFPArray            = new Array();
    var 
    bInitialized        false;


    //== PreMain function required by eSignal to set things up
    function preMain() {
    var 
    x;

        
    setPriceStudy(false);
        
    setStudyTitle("RSI of Range");
        
    setCursorLabelName("RofR"0);
        
    setDefaultBarFgColorColor.blue);
        
    setShowTitleParametersfalse );

        
    grID 0;
        
        
    //initialize formula parameters
        
    x=0
        
    aFPArray[x] = new FunctionParameter"fDays1"FunctionParameter.NUMBER);
        
    withaFPArray[x] ) {
            
    setName"Range #1 (days)" );
            
    setLowerLimit);
            
    setUpperLimit99999 );
            
    setDefault);
        }  
        
    x++; 
        
    aFPArray[x] = new FunctionParameter"fDays2"FunctionParameter.NUMBER);
        
    withaFPArray[x] ) {
            
    setName"Range #2 (days)" );
            
    setLowerLimit);
            
    setUpperLimit99999 );
            
    setDefault20 );
        }  
        
    x++; 
        
    aFPArray[x] = new FunctionParameter"fRSI"FunctionParameter.NUMBER);
        
    withaFPArray[x] ) {
            
    setName"RSI Period" );
            
    setLowerLimit);
            
    setUpperLimit99999 );
            
    setDefault10 );
        }  

    }

    //== Main processing function
    function mainfDays1fDays2fRSI ) {
    var 
    x;
    var 
    sSymb;
        
        
    //script is initializing
        
    if ( getBarState() == BARSTATE_ALLBARS ) {
            return 
    null;
        }

        if ( 
    bInitialized == false ) {
        
            
    sSymb getSymbol() + ",D";
        
            
    nStudy1 smaMath.roundfDays1 ), efsInternal"_range"symsSymb ) ) );
            
    nStudy2 smaMath.roundfDays2 ), efsInternal"_range"symsSymb ) ) );
            
    nStudy3 efsInternal"_div"nStudy1nStudy2 );
            
    nStudy4 rsiMath.roundfRSI ), nStudy3 );
        
        
            
    bInitialized true;
        }

        
    //called on each new bar
        
    if ( getBarState() == BARSTATE_NEWBAR ) {
            
            
    nBarCounter++;
            
        }

        return( 
    getSeriesnStudy4) );

    }


    function 
    _range_sym ) {
        
        return( 
    high(0)-low(0) );
        
    }

    function 
    _div_src1_src2 ) {
    var 
    xy;

        
    _src1.getValue(0);
        
    _src2.getValue(0);
        
        if ( 
    x==null || y==null ) return( null );


        return( 
    x/);
        

    Comment


    • #3
      ckryza, thanks a lot!!!

      regards

      Comment

      Working...
      X