BidAskAnalysis.efs
File Name: BidAskAnalysis.efs
Description:
This study is set up to analyze Bid Ask data in a variety of ways, which can be configured by the user through the Edit Studies option. The study can be used to analyze tick or volume data for each bar or on a cumulative basis. The displayed results can also be viewed as the raw outputs or on a relative percentage basis to the total.
Formula Parameters:
- Analysis: Bar [Bar, Cumulative]
- Study Output: Raw Data [Relative Percent, Raw Data]
- Source: Volume [Tick, Volume]
- Trade Volume Filter: 0
- Ask Color: green
- Inside Color: black
- Bid Color: red
- Total Color: lime
- Ask Thickness: 8
- Inside Thickness: 6
- Bid Thickness: 4
- Display Ask: Yes [Yes, No]
- Display Inside: Yes [Yes, No]
- Display Bid: Yes [Yes, No]
- Display Total: Yes [Yes, No]
Notes:
This study only processes real time data. Historical Bid/Ask information is not currently exposed for historical processing in EFS. The study will collect and display its results going forward in time from bar zero after it has been applied to the Advanced chart.
Some other possible combinations include:
- Raw Data: Volume (Cumulative)
- Raw Data: Tick (Bar)
- Raw Data: Tick (Cumulative)
- Relative Percent: Volume (Bar)
- Relative Percent: Volume (Cumulative)
- Relative Percent: Tick (Bar)
- Relative Percent: Tick (Cumulative)
Version 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.
Download File:
BidAskAnalysis.efs
EFS Code:
/***************************************************************** Provided By : eSignal (c) Copyright 2004 Description: Bid/Ask Analysis Version 2.0 Notes: *** 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 Bar [Bar, Cumulative] Study Output Raw Data [Relative Percent, Raw Data] Source Volume [Tick, Volume] Trade Volume Filter 0 Ask Color green Inside Color black Bid Color red Total Color lime Ask Thickness 8 Inside Thickness 6 Bid Thickness 4 Display Ask Yes [Yes, No] Display Inside Yes [Yes, No] Display Bid Yes [Yes, No] Display Total Yes [Yes, No] *****************************************************************/ function preMain() { setStudyTitle("Bid\/Ask Analysis "); setCursorLabelName("Total", 0); setCursorLabelName("Ask %", 1); setCursorLabelName("Inside %", 2); setCursorLabelName("Bid %", 3); setDefaultBarFgColor(Color.lime, 0); setDefaultBarFgColor(Color.green, 1); setDefaultBarFgColor(Color.black, 2); setDefaultBarFgColor(Color.red, 3); setDefaultBarThickness(8, 0); setDefaultBarThickness(8, 1); setDefaultBarThickness(6, 2); setDefaultBarThickness(4, 3); setPlotType(PLOTTYPE_HISTOGRAM, 0); setPlotType(PLOTTYPE_HISTOGRAM, 1); setPlotType(PLOTTYPE_HISTOGRAM, 2); setPlotType(PLOTTYPE_HISTOGRAM, 3); setShowTitleParameters(false); setStudyMin(0); var fp0 = new FunctionParameter("sType", FunctionParameter.STRING); fp0.setName("Analysis"); fp0.addOption("Bar"); fp0.addOption("Cumulative"); fp0.setDefault("Bar"); var fp1 = new FunctionParameter("sOutput", FunctionParameter.STRING); fp1.setName("Study Output"); fp1.addOption("Relative Percent"); fp1.addOption("Raw Data"); fp1.setDefault("Raw Data"); 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("cAsk", FunctionParameter.COLOR); fp3.setName("Ask Color"); fp3.setDefault(Color.green); var fp4 = new FunctionParameter("cInside", FunctionParameter.COLOR); fp4.setName("Inside Color"); fp4.setDefault(Color.black); var fp5 = new FunctionParameter("cBid", FunctionParameter.COLOR); fp5.setName("Bid Color"); fp5.setDefault(Color.red); var fp6 = new FunctionParameter("cTotal", FunctionParameter.COLOR); fp6.setName("Total Color"); fp6.setDefault(Color.lime); var fp7 = new FunctionParameter("nAskThickness", FunctionParameter.NUMBER); fp7.setName("Ask Thickness"); fp7.setDefault(8); var fp8 = new FunctionParameter("nInsideThickness", FunctionParameter.NUMBER); fp8.setName("Inside Thickness"); fp8.setDefault(6); var fp9 = new FunctionParameter("nBidThickness", FunctionParameter.NUMBER); fp9.setName("Bid Thickness"); fp9.setDefault(4); var fp10 = new FunctionParameter("sAskDisplay", FunctionParameter.STRING); fp10.setName("Display Ask"); fp10.addOption("Yes"); fp10.addOption("No"); fp10.setDefault("Yes"); var fp11 = new FunctionParameter("sInsideDisplay", FunctionParameter.STRING); fp11.setName("Display Inside"); fp11.addOption("Yes"); fp11.addOption("No"); fp11.setDefault("Yes"); var fp12 = new FunctionParameter("sBidDisplay", FunctionParameter.STRING); fp12.setName("Display Bid"); fp12.addOption("Yes"); fp12.addOption("No"); fp12.setDefault("Yes"); var fp13 = new FunctionParameter("sTotalDisplay", FunctionParameter.STRING); fp13.setName("Display Total"); fp13.addOption("Yes"); fp13.addOption("No"); fp13.setDefault("Yes"); } var nAsk = null; var nBid = null; var nMax = 0; var aReturn = new Array(4); // return array; // Volume var nBidVol = 0; var nInsideVol = 0; var nAskVol = 0; var nTotalVol = 0; var vVol = null; var bPrimed = false; // Tick var nBidTick = 0; var nInsideTick = 0; var nAskTick = 0; var nTotalTick = 0; var bEdit = true; function main(sType, sOutput, sSource, nFilter, cAsk, cInside, cBid, nAskThickness, nInsideThickness, nBidThickness, sAskDisplay, sInsideDisplay, sBidDisplay, sTotalDisplay) { if (getCurrentBarIndex() < 0) return; if (bEdit == true) { setStudyTitle("Bid\/Ask " + sOutput + ": " + sSource + " (" + sType + ")"); setDefaultBarFgColor(cAsk, 1); setDefaultBarFgColor(cInside, 2); setDefaultBarFgColor(cBid, 3); setDefaultBarThickness(nAskThickness, 1); setDefaultBarThickness(nInsideThickness, 2); setDefaultBarThickness(nBidThickness, 3); setDefaultBarThickness(Math.max(nAskThickness, nInsideThickness, nBidThickness), 0); if (sOutput == "Raw Data") { setCursorLabelName("Ask Total", 1); setCursorLabelName("Inside Total", 2); setCursorLabelName("Bid Total", 3); removeBand("0"); removeBand("25"); removeBand("50"); removeBand("75"); removeBand("100"); nMax = 0; } else { // Percent setCursorLabelName("Ask %", 1); setCursorLabelName("Inside %", 2); setCursorLabelName("Bid %", 3); addBand(0, PS_SOLID, 1, Color.black, "0"); addBand(25, PS_SOLID, 1, Color.black, "25"); addBand(50, PS_SOLID, 1, Color.black, "50"); addBand(75, PS_SOLID, 1, Color.black, "75"); addBand(100, PS_SOLID, 1, Color.black, "100"); setStudyMax(115); } bEdit = false; } var nState = getBarState(); if (nState == BARSTATE_NEWBAR && getDay(0) != getDay(-1)) nMax = 0; 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; aReturn[1] = 0; aReturn[2] = 0; aReturn[3] = 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; aReturn[1] = 0; aReturn[2] = 0; aReturn[3] = 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 nDtotal; var nDask; var nDinside; var nDbid; if (sSource == "Volume") { if (sOutput == "Relative Percent") { nDtotal = 100; if (sTotalDisplay == "No") nDtotal = nDtotal+""; nDask = (nAskVol/nTotalVol)*100; if (sAskDisplay == "No") nDask = nDask.toFixed(4); nDinside = (nInsideVol/nTotalVol)*100; if (sInsideDisplay == "No") nDinside = nDinside.toFixed(4); nDbid = (nBidVol/nTotalVol)*100; if (sBidDisplay == "No") nDbid = nDbid.toFixed(4); //return new Array(100, (nAskVol/nTotalVol)*100, (nInsideVol/nTotalVol)*100, (nBidVol/nTotalVol)*100); } else if (sOutput == "Raw Data") { nMax = Math.max(nMax, nTotalVol); setStudyMax(nMax); nDtotal = nTotalVol; if (sTotalDisplay == "No") nDtotal = nDtotal+""; nDask = nAskVol; if (sAskDisplay == "No") nDask = nDask.toFixed(4); nDinside = nInsideVol; if (sInsideDisplay == "No") nDinside = nDinside.toFixed(4); nDbid = nBidVol; if (sBidDisplay == "No") nDbid = nDbid.toFixed(4); //return new Array(nTotalVol, nAskVol, nInsideVol, nBidVol); } } else if (sSource == "Tick") { if (sOutput == "Relative Percent") { nDtotal = 100; if (sTotalDisplay == "No") nDtotal = nDtotal+""; nDask = (nAskTick/nTotalTick)*100; if (sAskDisplay == "No") nDask = nDask.toFixed(4); nDinside = (nInsideTick/nTotalTick)*100; if (sInsideDisplay == "No") nDinside = nDinside.toFixed(4); nDbid = (nBidTick/nTotalTick)*100; if (sBidDisplay == "No") nDbid = nDbid.toFixed(4); //return new Array(100, (nAskTick/nTotalTick)*100, (nInsideTick/nTotalTick)*100, (nBidTick/nTotalTick)*100); } else if (sOutput == "Raw Data") { nMax = Math.max(nMax, nTotalTick); setStudyMax(nMax); nDtotal = nTotalTick; if (sTotalDisplay == "No") nDtotal = nDtotal+""; nDask = nAskTick; if (sAskDisplay == "No") nDask = nDask.toFixed(4); nDinside = nInsideTick; if (sInsideDisplay == "No") nDinside = nDinside.toFixed(4); nDbid = nBidTick; if (sBidDisplay == "No") nDbid = nDbid.toFixed(4); //return new Array(nTotalTick, nAskTick, nInsideTick, nBidTick); } } aReturn[0] = nDtotal; aReturn[1] = nDask; aReturn[2] = nDinside; aReturn[3] = nDbid; return new Array(nDtotal, nDask, nDinside, nDbid); }