Announcement

Collapse
No announcement yet.

Using efsInternal()

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

  • Using efsInternal()

    This script is intended to chart simultaneously the RSI of up volume and the RSI of down volumn. However, it doesn't work -- apparently because efsInternal() isn't being handled correctly.

    /*Based on "RSI of 3bar Vol" by Alex Montenegro, 4-4-05 and
    adapted 5-15-05 by Steven Miller for the purpose of showing RSI of both up and down volume.
    */

    // Global Variables
    var upVolRSI = 0;
    var dnVolRSI = 0;
    var DnVolAray = null;
    var UpVolAray = null;
    var upVol = 0;
    var dnVol = 0;

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("RSIof2Vol");
    setCursorLabelName("RSI2vol", 0);
    setStudyMin(0);
    setStudyMax(100);
    setDefaultBarFgColor(Color.lime,0);
    setDefaultBarFgColor(Color.red,1);
    setPlotType( PLOTTYPE_LINE, 0);
    setPlotType( PLOTTYPE_LINE, 1);
    addBand(50, PS_DASH, 1, Color.yellow);
    }

    function main(nLength) {

    if(nLength==null) nLength = 4;

    if(DnVolAray==null) DnVolAray = new Array(nLength);
    if(UpVolAray==null) UpVolAray = new Array(nLength);

    rawVol = getValue("Volume");

    if(getBarState() == BARSTATE_NEWBAR) {
    if(open(-1) > close(-1)) { // Alexis C. Montenegro had open(-1) etc.
    DnVolAray.pop(-1);
    dnVol = volume(-1);
    DnVolAray.unshift(dnVol);

    }
    if(open(-1)< close(-1)) {
    UpVolAray.pop(-1);
    upVol = volume(-1);
    UpVolAray.unshift(upVol);

    }
    } else
    return;

    upVolRSI = getvolsum(1);
    dnVolRSI = getvolsum(0);

    /*
    */
    if(upVolRSI <= 50) {
    setDefaultBarThickness( 1, 0 );
    setDefaultBarFgColor(Color.lightgrey,0);
    } else if(upVolRSI > 50) {
    setDefaultBarThickness( 4, 0 );
    setDefaultBarFgColor(Color.lime,0);
    }
    if(dnVolRSI <= 50) {
    setDefaultBarThickness( 1, 1 );
    setDefaultBarFgColor(Color.lightgrey,0);
    } else if(dnVolRSI > 50) {
    setDefaultBarThickness( 4, 1 );
    setDefaultBarFgColor(Color.red,0);
    }

    return new Array(upVolRSI, dnVolRSI );
    }

    function getvolsum(n){

    var volsum = 0;

    if (n == 0) {
    volsum = DnVolAray[0]+DnVolAray[1]+DnVolAray[2];
    debugPrintln("Down volsum: " + volsum);
    debugPrintln();
    }
    else if (n == 1) {
    volsum = UpVolAray[0]+UpVolAray[1]+UpVolAray[2];
    debugPrintln("Up volsum: " + volsum);
    debugPrintln();
    }
    return rsi(14,efsInternal("volsum"));
    Last edited by Steven Miller; 05-15-2005, 09:16 PM.

  • #2
    Steven
    The efsInternal("volsum") call that you are using as the source for the rsi() study is calling a variable contained in the same function which is not the proper usage. The efsInternal() function should be used to call a separate function contained in the same script.
    You may want to go through this thread that shows how to use efs() and efsInternal() functions.
    Also when posting code please make sure that it is properly aligned by enclosing it in the [ p h p ] and [ / p h p ] or [ c o d e ] and [ / c o d e ] tags
    Alex

    Comment

    Working...
    X