BidAskRatio.efs

ICE Data Services -


BidAskRatio.efs  EFSLibrary - Discussion Board
  

File Name: BidAskRatio.efs


Description:
Analyzes Bid/Ask tick or volume data by calculating various ratios selected by the user through the Edit Studies options.


Formula Parameters:
Analysis: Cumulative [Bar, Cumulative]
Study Output: Ask/Bid [Ask/Bid, Ask/Total, Bid/Total, Ask-Bid]
Source: Volume [Tick, Volume]
Trade Volume Filter: 0 (Exlcudes trades below specified filter)
Positive Color: blue
Negative Color: red
Thickness: 2
Plot Type: Line [Line, Histogram]

Notes:
This study may only collect and display data in real time only. It will collect and display data after the study has completely loaded. A reload of the study will start the analysis over because Bid/Ask data in not exposed to EFS for historical bars.

Download File:
BidAskRatio.efs




EFS Code:






/*********************************Provided By : eSignal (c) Copyright 2004Description: Bid/Ask RatioVersion 2.0Notes*** 2.0 - 11/26/2004 ***    - Added Trade Volume Filter.  Trade Volume less than the Filter      number will be excluded when Srouce is set to Volume.    - 5/27/05 - Fix for Trade Volume Filter.  Wasn't properly       reseting the total at new bar.      Formula Parameters:                 Defaults:Analysis                            Cumulative    [Bar, Cumulative]Study Output                        Ask/Bid    [Ask/Bid, Ask/Total, Bid/Total, Ask-Bid]Source                              Volume    [Tick, Volume]Trade Volume Filter                 0Positive Color                      blueNegative Color                      redThickness                           2Plot Type                           Line    [Line, Histogram]*********************************/function preMain() {    setStudyTitle("Bid\/Ask Ratio ");    setCursorLabelName("Ask/Bid", 0);    setDefaultBarThickness(2, 0);    setShowTitleParameters(false);        addBand(1, PS_SOLID, 1, Color.black, "even");        var fp0 = new FunctionParameter("sType", FunctionParameter.STRING);        fp0.setName("Analysis");        fp0.addOption("Bar");        fp0.addOption("Cumulative");        fp0.setDefault("Cumulative");    var fp1 = new FunctionParameter("sOutput", FunctionParameter.STRING);        fp1.setName("Study Output");        fp1.addOption("Ask/Bid");        fp1.addOption("Ask/Total");        fp1.addOption("Bid/Total");        fp1.addOption("Ask-Bid");        fp1.setDefault("Ask/Bid");    var fp2 = new FunctionParameter("sSource", FunctionParameter.STRING);        fp2.setName("Source");        fp2.addOption("Tick");        fp2.addOption("Volume");        fp2.setDefault("Volume");    var fp2a = new FunctionParameter("nFilter", FunctionParameter.NUMBER);        fp2a.setName("Trade Volume Filter");        fp2a.setLowerLimit(0);        fp2a.setDefault(0);    var fp3 = new FunctionParameter("cPos", FunctionParameter.COLOR);        fp3.setName("Positive Color");        fp3.setDefault(Color.blue);    var fp4 = new FunctionParameter("cNeg", FunctionParameter.COLOR);        fp4.setName("Negative Color");        fp4.setDefault(Color.red);    var fp5 = new FunctionParameter("nThickness", FunctionParameter.NUMBER);        fp5.setName("Thickness");        fp5.setDefault(2);    var fp6 = new FunctionParameter("sPlotType", FunctionParameter.STRING);        fp6.setName("Plot Type");        fp6.addOption("Line");        fp6.addOption("Histogram");        fp6.setDefault("Line");}var nAsk = null;var nBid = null;var nRet = 1;var aReturn = new Array(1); // return array;// Volumevar nBidVol = 0;//var nInsideVol = 0;var nAskVol = 0;var nTotalVol = 0;var vVol = null;var bPrimed = false;// Tickvar nBidTick = 0;//var nInsideTick = 0;var nAskTick = 0;var nTotalTick = 0;var bEdit = true;function main(sType, sOutput, sSource, nFilter, cPos, cNeg, nThickness, sPlotType) {    if (bEdit == true) {        setStudyTitle("BidAskRatio:   " + sOutput + ": " + sSource + " (" + sType + ")");        setDefaultBarThickness(nThickness, 0);        setCursorLabelName(sOutput, 0);        if (sPlotType == "Histogram") setPlotType(PLOTTYPE_HISTOGRAM, 0);        if (sOutput == "Ask-Bid") {            addBand(0, PS_SOLID, 1, Color.black, "even");            nRet = 0;        }        bEdit = false;    }    if (getCurrentBarIndex() < 0) return nRet;        var nState = getBarState();    if (sSource == "Volume") {        if (nState == BARSTATE_NEWBAR) {            vVol = 0;            if (sType == "Bar" || getDay(0) != getDay(-1)) {                nBidVol = 0;                //nInsideVol = 0;                nAskVol = 0;                vVol = 0;                nTotalVol = 0;                aReturn[0] = 0;            }        }                var vPrevVol = 0;        if (vVol != 0 && bPrimed == true) vPrevVol = vVol;                var nTempAsk = getMostRecentAsk();        var nTempBid = getMostRecentBid();        if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;        if (nTempBid != null && nTempBid != 0) nBid = nTempBid;        var vClose = close();        vVol = volume();                var vTradeVol = vVol - vPrevVol;        if (vTradeVol < nFilter) return aReturn;                if (bPrimed == false && vVol != null) {            bPrimed = true;            return;        } else {            nTotalVol += vTradeVol;            if (vClose <= nBid) {                nBidVol += vTradeVol;            } else if (vClose >= nAsk) {                nAskVol += vTradeVol;            } /*else {                nInsideVol += vTradeVol;            }*/        }    } else if (sSource == "Tick") {        if (nState == BARSTATE_NEWBAR) {            if (sType == "Bar" || getDay(0) != getDay(-1)) {                nBidTick = 0;                //nInsideTick = 0;                nAskTick = 0;                nTotalTick = 0;                aReturn[0] = 0;                            }        }                var nTempAsk = getMostRecentAsk();        var nTempBid = getMostRecentBid();        if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;        if (nTempBid != null && nTempBid != 0) nBid = nTempBid;        var vClose = close();                nTotalTick++;        if (vClose <= nBid) {            nBidTick++;        } else if (vClose >= nAsk) {            nAskTick++;        } /*else {            nInsideTick++;        }*/            }            // Return Data    var nReturn = 1;    switch (sSource) {        case "Volume" :            switch (sOutput) {                case "Ask/Bid" :                    if (nBidVol == 0) nReturn = 1;                    else nReturn = (nAskVol/nBidVol);                    break;                case "Ask/Total" :                    if (nTotalVol == 0) nReturn = 1;                    else nReturn = (nAskVol/nTotalVol);                    break;                case "Bid/Total" :                    if (nTotalVol == 0) nReturn = 1;                    else nReturn = (nBidVol/nTotalVol);                    break;                case "Ask-Bid" :                    nReturn = (nAskVol-nBidVol);                    break;                default : nReturn = 1;            }            break;        case "Tick" :            switch (sOutput) {                case "Ask/Bid" :                    if (nBidTick == 0) nReturn = 1;                    else nReturn = (nAskTick/nBidTick);                    break;                case "Ask/Total" :                    if (nTotalTick == 0) nReturn = 1;                    else nReturn = (nAskTick/nTotalTick);                    break;                case "Bid/Total" :                    if (nTotalTick == 0) nReturn = 1;                    else nReturn = (nBidTick/nTotalTick);                    break;                case "Ask-Bid" :                    nReturn = (nAskTick-nBidTick);                    break;                default : nReturn = 1;            }            break;        default: nReturn = 1;    }        if (nReturn >= 1) setBarFgColor(cPos, 0);    else setBarFgColor(cNeg, 0);    aReturn[0] = nReturn;    return nReturn;}