The following efs is designed to alert intra-bar once when the criteria is met, which it does. It also alerts at the open of the next bar which it is not supposed when the criteria is not met. What did I miss in the code?
PHP Code:
var vPlaySoundb = "C:\\Program Files\\eSignal\\Sounds\\spbuy.wav";
var vPlaySoundr = "C:\\Program Files\\eSignal\\Sounds\\spsell.wav";
var fpArray = new Array();
var vFlag;
function preMain() {
setPriceStudy(true);
setStudyTitle("Buy Seller program");
setShowTitleParameters(false)
var x;
x=0;
fpArray[x] = new FunctionParameter("Buyp", FunctionParameter.NUMBER);
with(fpArray[x]){
setDefault("");
}
x++;
fpArray[x] = new FunctionParameter("Sellp", FunctionParameter.NUMBER);
with(fpArray[x]){
setDefault("");
}
fpArray[x] = new FunctionParameter( "bSound", FunctionParameter.STRING);
with(fpArray[x]){
setName("Play Sound");
addOption("true");
addOption("false");
setDefault("true");
}
fpArray[x] = new FunctionParameter( "sSound", FunctionParameter.STRING);
with(fpArray[x]){
setName("Play Sound");
addOption("true");
addOption("false");
setDefault("true");
}
fpArray[x] = new FunctionParameter("uC", FunctionParameter.COLOR);
with(fpArray[x]){
setName("Buy Text Color");
setDefault(Color.green);
}
fpArray[x] = new FunctionParameter("dC", FunctionParameter.COLOR);
with(fpArray[x]){
setName("Sell Text Color");
setDefault(Color.red);
}
}
var Cond1;
var Cond2;
var uColor;
var dColor;
function main(Buyp, Sellp, bSound, sSound, uC, dC) {
if (getCurrentBarIndex() == 0 && getBarState() == BARSTATE_NEWBAR)
vFlag = false;
uColor = uC;
dColor = dC;
var Cond1 = high(0, sym("EPREM A0") );
var Cond2 = low(0, sym("EPREM A0") );
if((getHour()*100)+getMinute() > 930 && (getHour()*100)+getMinute() < 1600){
if(Cond1 > Buyp && vFlag == false){
//drawTextRelative(0, low()-1, "PB", Color.green, Color.RGB(0,0,0), Text.BOTTOM | Text.CENTER, "Arial", 10);
drawText( "B", BottomRow1, uColor, Text.BOTTOM | Text.CENTER );
if(bSound == "true") {Alert.playSound(vPlaySoundb)};
vFlag = true;
}
if(Cond2 < Sellp && vFlag == false){
drawText( "S", TopRow1, dColor, Text.ONTOP | Text.CENTER );
if(sSound == "true") {Alert.playSound(vPlaySoundr)};
vFlag = true;
//drawTextRelative(0, high()+1, "PS", Color.red, Color.RGB(0,0,0), Text.TOP | Text.CENTER, "Arial", 10);
}
}
}
Comment