FWIW, since I coded for the previous individual bid/ask value as well, I'm posting the completed efs.
Wayne
PHP Code:
function preMain() {
//setStudyTitle("Bid/Ask Volume ");
setCursorLabelName("Ask Vol", 0);
setCursorLabelName("Inside Vol", 1);
setCursorLabelName("Bid Vol", 2);
setDefaultBarFgColor(Color.green, 0);
setDefaultBarFgColor(Color.black, 1);
setDefaultBarFgColor(Color.red, 2);
setDefaultBarThickness(8, 0);
setDefaultBarThickness(6, 1);
setDefaultBarThickness(4, 2);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
setPlotType(PLOTTYPE_HISTOGRAM, 2);
var fp0 = new FunctionParameter("sType", FunctionParameter.STRING);
fp0.setName("Analysis");
fp0.addOption("Bar");
fp0.addOption("Cumulative");
fp0.setDefault("Bar");
}
var nBidVol = null;
var nInsideVol = null;
var nAskVol = null;
var nBidVol_1 = null;
var nInsideVol_1 = null;
var nAskVol_1 = null;
var vVol = null;
var bPrimed = false;
var nAsk = null;
var nBid = null;
var bEdit = true;
var ddeup = null;
var ddedown = null;
var ddeInside = null;
var ddeup_1 = null;
var ddedown_1 = null;
var ddeInside_1 = null;
var ddeup_1Tick = null;
var ddedown_1Tick = null;
var ddeInside_1Tick = null;
var vTradeVol_1 = null;
var nBidVol_LastTick = null;
var nInsideVol_LastTick = null;
var nAskVol_LastTick = null;
function main(sType) {
var vPrevVol = null;
var nTempAsk = null;
var nTempBid = null;
if (getCurrentBarIndex() < 0) return;
if (bEdit == true) {
var symb = getSymbol();
symb = symb.replace(" #F", "");
symb = symb.replace(" ", "_");debugPrintln("symb; "+symb);
ddeup = new DDEOutput(symb + "ask0_" + getInterval());
ddedown = new DDEOutput(symb + "bid0_" + getInterval());
ddeInside = new DDEOutput(symb + "Inside0_" + getInterval());
ddeup_1 = new DDEOutput(symb + "ask1_" + getInterval());
ddedown_1 = new DDEOutput(symb + "bid1_" + getInterval());
ddeInside_1 = new DDEOutput(symb + "Inside1_" + getInterval());
ddeup_1Tick = new DDEOutput(symb + "ask1T_" + getInterval());
ddedown_1Tick = new DDEOutput(symb + "bid1T_" + getInterval());
ddeInside_1Tick = new DDEOutput(symb + "Inside1T_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "ask0_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "bid0_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "Inside0_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "ask1_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "bid1_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "Inside1_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "ask1T_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "bid1T_" + getInterval());
debugPrintln("Example DDE link: '=eSignal|EFS!" + symb + "Inside1T_" + getInterval());
bEdit = false;
}
var nState = getBarState();
if (nState == BARSTATE_NEWBAR) {
if (sType == "Bar" || day(0) != day(-1)) {//resets values to 0
nBidVol = 0;
nInsideVol = 0;
nAskVol = 0;
nBidVol_1 = 0;
nInsideVol_1 = 0;
nAskVol_1 = 0;
}
vVol = 0;
}
if (vVol != null && bPrimed == true) vPrevVol = vVol;
nTempAsk = getMostRecentAsk();
nTempBid = getMostRecentBid();
if (nTempAsk != null && nTempAsk != 0) nAsk = nTempAsk;
if (nTempBid != null && nTempBid != 0) nBid = nTempBid;
var vClose = close(0);
vVol = volume(0);
var vTradeVol = vVol - vPrevVol;//changed "vTradeVol" to global scope
if (bPrimed == false && vVol != null) {
bPrimed = true;
return;
} else {
if (vClose <= nBid) {
nBidVol_1 = nBidVol;//previous cummulative bid value
nBidVol += vTradeVol;//current cummulative bid value
nBidVol_LastTick = vTradeVol_1;//previous single bid value
//for every bar each of these with "+=" adds the previous total to the incoming value and
//all are reset above under the code with "BARSTATE_NEWBAR"
} else if (vClose >= nAsk) {
nAskVol_1 = nAskVol;//previous cummulative ask value
nAskVol += vTradeVol;//current cummulative ask value
nAskVol_LastTick = vTradeVol_1;//previous single ask value
} else {
nInsideVol_1 = nInsideVol;//previous cummulative inside value
nInsideVol += vTradeVol;//current cummulative inside value
nInsideVol_LastTick = vTradeVol_1;//previous single inside value
}
}
if (nAskVol != null) ddeup.set(nAskVol);
if (nBidVol != null) ddedown.set(nBidVol);
if (nInsideVol != null) ddeInside.set(nInsideVol);
if (nAskVol_1 != null) ddeup_1.set(nAskVol_1);
if (nBidVol_1 != null) ddedown_1.set(nBidVol_1);
if (nInsideVol_1 != null) ddeInside_1.set(nInsideVol_1);
if (nAskVol_LastTick != null) ddeup_1Tick.set(nAskVol_LastTick);
if (nBidVol_LastTick != null) ddedown_1Tick.set(nBidVol_LastTick);
if (nInsideVol_LastTick != null) ddeInside_1Tick.set(nInsideVol_LastTick);
//debugPrintln("0000: "+nAskVol+", "+nInsideVol+", "+nBidVol);
//debugPrintln("1111: "+nAskVol_1+", "+nInsideVol_1+", "+nBidVol_1);
//debugPrintln("2222: "+nAskVol_LastTick+", "+nInsideVol_LastTick+", "+nBidVol_LastTick);
vTradeVol_1 = vTradeVol;//added to capture last "vTradeVol"
return new Array(nAskVol, nInsideVol, nBidVol);
}
Comment