i threw together a study so i could test sending signals to my broker, but when i load the EFS, it sends every signal that happened on historical bars, ive tried getting ti to not send signals that have already expired by using getBarState() == BARSTATE_NEWBAR, ive also tried getBarState() != BARSTATE_ALLBARS, but it still sends every single order that has already passed, does anyone know how to fix this?
PHP Code:
var State = 0;
var F = 10;
var S = 50;
function preMain() {
setPriceStudy(true);
setColorPriceBars(true);
setStudyTitle("test");
setCursorLabelName("Fast", 0);
setCursorLabelName("Slow", 1);
setCursorLabelName("State", 2);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarFgColor(Color.grey, 0);
setDefaultBarFgColor(Color.darkgrey, 1);
setDefaultBarFgColor(Color.grey, 2);
setDefaultBarThickness(4, 0);
setDefaultBarThickness(4, 1);
setDefaultBarThickness(4, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
setPlotType(PLOTTYPE_LINE, 2);
}
function main() {
if (getBarState() == BARSTATE_NEWBAR && getBarState() != BARSTATE_ALLBARS) {
if (sma(F) > ema(S) && State != 1) {
Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
buyMarket(getSymbol(), 10)
State = 1;
}
else if (sma(F) < ema(S) && State != -1) {
Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
sellShortMarket(getSymbol(), 10)
State = -1;
}
}
setPriceBarColor(Color.RGB(128,128,128))
if (State == 1) setPriceBarColor(Color.RGB(0,255,0));
if (State == -1) setPriceBarColor(Color.RGB(255,0,0));
return new Array(
sma(F),
ema(S),
String(State)
);
}
Comment