Announcement

Collapse
No announcement yet.

2003 Oct: The Bull And Bear Balance Indicator (BullBearBalance.efs)

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2003 Oct: The Bull And Bear Balance Indicator (BullBearBalance.efs)

    File Name: BullBearBalance.efs

    Description:
    This indicator is based on Bull And Bear Balance Indicator by Vadim Gimelfarb, which appeared in the October 2003 issue of Stocks & Commodities.

    Formula Parameters:
    Smoothing Length: 2
    Thickness: 2
    Bull Color: Color.blue
    Bear Color: Color.red
    Graph Type: Lines [Lines, Histogram]

    Notes:
    The formula is applied twice in the chart image to show the two types of display options. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.


    Download File:
    BullBearBalance.efs



    EFS Code:
    PHP Code:
    /*****************************************************************
    Provided By : eSignal. (c) Copyright 2004
    Study:        Bull And Bear Balance Indicator, by Vadim Gimelfarb
    Version:      2.0

    9/8/2004

    Notes:

    Formula Parameters:                 Default:
        Smoothing Length                2
        Thickness                       2
        Bull Color                      Color.blue
        Bear Color                      Color.red
        Graph Type                      Lines
            [Lines, Histogram]
    *****************************************************************/

    function preMain() {
        
    setStudyTitle("Bull And Bear Balance ");
        
    setShowTitleParameters(false);
        
    setCursorLabelName("Bull"0);
        
    setCursorLabelName("Bear"1);
        
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1);
        
        
    addBand(0PS_SOLID1Color.grey"zero");
        
        
        var 
    fp1 = new FunctionParameter("nLength"FunctionParameter.NUMBER);
        
    fp1.setName("Smoothing Length");
        
    fp1.setLowerLimit(1);
        
    fp1.setDefault(2);
        
        var 
    fp2 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
        
    fp2.setName("Thickness");
        
    fp2.setLowerLimit(1);
        
    fp2.setDefault(2);

        var 
    fp3 = new FunctionParameter("cColor0"FunctionParameter.COLOR);
        
    fp3.setName("Bull Color");
        
    fp3.setDefault(Color.blue);

        var 
    fp4 = new FunctionParameter("cColor1"FunctionParameter.COLOR);
        
    fp4.setName("Bear Color");
        
    fp4.setDefault(Color.red);

        var 
    fp5 = new FunctionParameter("sType"FunctionParameter.STRING);
        
    fp5.setName("Graph Type");
        
    fp5.addOption("Lines");
        
    fp5.addOption("Histogram");
        
    fp5.setDefault("Lines");
    }

    var 
    bEdit true;
    var 
    nCntr 0;
    var 
    bNew false;
    var 
    nPB null;
    var 
    nPB1 null;
    var 
    nBull null;
    var 
    nBear null;
    var 
    nBullMA null;
    var 
    nBearMA null;
    var 
    nBullMA1 null;
    var 
    nBearMA1 null;
    var 
    aBull null
    var 
    aBear null;


    function 
    main(nLengthnThickcColor0cColor1sType) {
        if (
    bEdit == true) {
            
    aBull = new Array(nLength);
            
    aBear = new Array(nLength);
            
    setDefaultBarThickness(nThick0);
            
    setDefaultBarThickness(nThick1);
            
    setDefaultBarFgColor(cColor00);
            
    setDefaultBarFgColor(cColor11);
            switch (
    sType) {
                case 
    "Lines" :
                    
    setCursorLabelName("Bull"0);
                    
    setCursorLabelName("Bear"1);
                    
    setPlotType(PLOTTYPE_LINE0);
                    
    setPlotType(PLOTTYPE_LINE1);
                    break;
                case 
    "Histogram" :
                    
    setCursorLabelName("Power Balance"0);
                    
    setCursorLabelName("Power Balance"1);
                    
    setPlotType(PLOTTYPE_INSTANTCOLORLINE0);
                    
    setPlotType(PLOTTYPE_HISTOGRAM1);
                    break;
            }
            
    bEdit false;
        }

        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    nPB1 nPB;
            
    nBullMA1 nBullMA;
            
    nBearMA1 nBearMA;
            if (
    nBull != null) {
                
    aBull.pop();
                
    aBull.unshift(nBull);
            }
            if (
    nBear != null) {
                
    aBear.pop();
                
    aBear.unshift(nBear);
            }
            
    nCntr++;
            if (
    nCntr 200nCntr 0;
        }

        var 
    close(0);
        var 
    open(0);
        var 
    high(0);
        var 
    low(0);
        
        var 
    C1 close(-1);
        if (
    C1 == null) return;
        
        
    //Bull Power
        
    nBull null;
        if (
    O) {
            if (
    C1 O) {
                
    nBull Math.max(H-C1C-L);
            } else {
                
    nBull Math.max(H-OC-L);
            }
        } else if (
    O) {
            if (
    C1 O) {
                
    nBull = (H-L);
            } else {
                
    nBull Math.max(O-C1H-L);
            }
        } else if (
    H-C-L) {
            if (
    C1 O) {
                
    nBull Math.max(H-C1C-L);
            } else {
                
    nBull = (H-O);
            }
        } else if (
    H-C-L) {
            if (
    C1 O) {
                
    nBull = (H-L);
            } else {
                
    nBull Math.max(O-C1H-L);
            }
        } else if (
    C1 O) {
            
    nBull Math.max(H-OC-L);
        } else if (
    C1 O) {
            
    nBull Math.max(O-C1H-L);
        } else {
            
    nBull Math.max(O-C1H-L);
        }
        
    aBull[0] = nBull;
        
        
    //Bear Power
        
    nBear null;
        if (
    O) {
            if (
    C1 O) {
                
    nBear Math.max(C1-OH-L);
            } else {
                
    nBear = (H-L);
            }
        } else if (
    O) {
            if (
    C1 O) {
                
    nBear Math.max(C1-LH-C);
            } else {
                
    nBear Math.max(O-LH-C);
            }
        } else if (
    H-C-L) {
            if (
    C1 O) {
                
    nBear Math.max(C1-OH-L);
            } else {
                
    nBear = (H-L);
            }
        } else if (
    H-C-L) {
            if (
    C1 O) {
                
    nBear Math.max(C1-LH-C);
            } else {
                
    nBear = (O-L);
            }
        } else if (
    C1 O) {
            
    nBear Math.max(C1-OH-L);
        } else if (
    C1 O) {
            
    nBear Math.max(O-LH-C);
        } else {
            
    nBear = (H-L);
        }
        
    aBear[0] = nBear;
        
        
    // Smoothing
        
    var dSumBull 0;
        var 
    dSumBear 0;
        for (var 
    0nLengthi++) {
            
    dSumBull += aBull[i];
            
    dSumBear += aBear[i];
        }
        
    nBullMA dSumBull/nLength;
        
    nBearMA dSumBear/nLength;
        
        
    // Alert Arrows
        
    if (sType == "Histogram") {
            
    nPB = (nBullMA nBearMA);
            
    nBullMA nBearMA nPB;
            if (
    nPB >= 0) {
                
    setBarFgColor(cColor00);
                
    setBarFgColor(cColor01);
            } else {
                
    setBarFgColor(cColor10);
                
    setBarFgColor(cColor11);
            }
            if (
    nPB >= && nPB1 0) {
                
    bNew true;
                
    drawShapeRelative(05Shape.UPARROWnullColor.greenShape.TOP|Shape.RELATIVETOTOP"up"+nCntr);
            } else if (
    bNew == true) {
                
    removeShape("up"+nCntr);
            }
            if (
    nPB <= && nPB1 0) {
                
    bNew true;
                
    drawShapeRelative(05Shape.DOWNARROWnullColor.redShape.BOTTOM|Shape.RELATIVETOBOTTOM"dn"+nCntr);
            } else if (
    bNew == true) {
                
    removeShape("dn"+nCntr);
            }
        } else {
            if (
    nBullMA >= nBearMA && nBullMA1 nBearMA1) {
                
    bNew true;
                
    drawShapeRelative(05Shape.UPARROWnullColor.greenShape.TOP|Shape.RELATIVETOTOP"up"+nCntr);
            } else if (
    bNew == true) {
                
    removeShape("up"+nCntr);
            }
            if (
    nBullMA <= nBearMA && nBullMA1 nBearMA1) {
                
    bNew true;
                
    drawShapeRelative(05Shape.DOWNARROWnullColor.redShape.BOTTOM|Shape.RELATIVETOBOTTOM"dn"+nCntr);
            } else if (
    bNew == true) {
                
    removeShape("dn"+nCntr);
            }
        }
        
        return new Array(
    nBullMAnBearMA);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X