Hi,
I have written a simple trading system that when certain indicators kick in together, a square is drawn on the screen indicating to go long or short.
I have also created a simple signal strength indicator in another file that tells me how strong the signal is.
What I want to do is get the signal strength to print over the square on the screen. I have written (below) what i think it should be however it only shows the strength on the last two signals.
Any help would be much appreciated:
(code for trade signals)
var fpArray = new Array();
var bInit = false;
var xRSI = null;
var xStoch = null;
var xMACD = null;
var SSB = null;
var SSS = null;
var vLastAlert = -1;
var i=0;
var j=0;
function preMain() {
setPriceStudy(true);
setStudyTitle("Daily Dot");
setColorPriceBars(true);
setComputeOnClose(true);
setDefaultPriceBarColor(Color.black);
setShowTitleParameters(false);
setCursorLabelName("Daily Strategy",0);
var x =0;
fpArray[x] = new FunctionParameter("RSILength",FunctionParameter.NU MBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(30);
}
fpArray[x] = new FunctionParameter("Stoch1",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("Stoch2",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(9);
}
fpArray[x] = new FunctionParameter("Stoch3",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("MACD1",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("MACD2",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(52);
}
fpArray[x] = new FunctionParameter("MACD3",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(9);
}
fpArray[x] = new FunctionParameter("RSIUPPER",FunctionParameter.NUM BER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(40);
}
fpArray[x] = new FunctionParameter("RSILOWER",FunctionParameter.NUM BER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(60);
}
}
function main(RSILength,Stoch1,Stoch2,Stoch3,MACD1,MACD2,MA CD3,RSIUPPER,RSILOWER) {
var nBarState = getBarState();
if (nBarState == BARSTATE_ALLBARS) { //BARSTATE_ALLBARS I think is the first bar on the screen
if (RSILength == null) RSILength = 30;
if (Stoch1 == null) Stoch1 = 26;
if (Stoch2 == null) Stoch2 = 9;
if (Stoch3 == null) Stoch3 = 3;
if (MACD1 == null) MACD1 = 26;
if (MACD2 == null) MACD2 = 52;
if (MACD3 == null) MACD3 = 9;
if (RSILOWER == null) RSILOWER = 40;
if (RSIUPPER == null) RSIUPPER = 60;
}
if (bInit == false) {
xRSI = rsi(RSILength);
xStoch = new StochStudy(Stoch1,Stoch2,Stoch3);
xMACD = new MACDStudy(MACD1, MACD2, MACD3, "Close", false);
SSB = efsExternal("ESSB.efs");
SSS = efsExternal("ESSS.efs");
bInit = true;
}
if(getCurrentBarIndex() == 0) return;
if(xRSI.getValue(0) == null) return;
if(xStoch.getValue(0) == null) return;
if(xMACD.getValue(0) == null) return;
if(SSB.getValue(0) == null) return;
if(SSS.getValue(0) == null) return;
for ( i =0 ; i >= -25 ; i-- ) {
for ( j=0 ; j >= -30 ; j-- ) {
if (
xStoch.getValue(StochStudy.FAST,i) > xStoch.getValue(StochStudy.SLOW,i) &&
xStoch.getValue(StochStudy.FAST,i-1) < xStoch.getValue(StochStudy.SLOW,i-1) &&
xMACD.getValue(MACDStudy.HIST,j) > 0 &&
xMACD.getValue(MACDStudy.HIST,j-1) < 0 &&
xRSI.getValue(0) > RSILOWER
)
onAction1()
else if (
xStoch.getValue(StochStudy.FAST,i) < xStoch.getValue(StochStudy.SLOW,i) &&
xStoch.getValue(StochStudy.FAST,i-1) > xStoch.getValue(StochStudy.SLOW,i-1) &&
xMACD.getValue(MACDStudy.HIST,j) < 0 &&
xMACD.getValue(MACDStudy.HIST,j-1) > 0 &&
xRSI.getValue(0) < RSIUPPER
)
onAction2()
}};
/*if(Strategy.isLong())
setPriceBarColor(Color.green);
else if(Strategy.isShort())
setPriceBarColor(Color.red);*/
return /*vLastAlert*/;
}
function postMain() {
}
function onAction1() {
if (Strategy.isLong() == false) {
Strategy.doLong("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
debugPrintln("Buy" + "//" + getSymbol() + "//" + "close = " + close() + "//" );
drawShapeRelative(0, low() - (low()-low()*0.99), Shape.SQUARE, "", Color.RGB(0,0,255), Shape.LEFT);
//Alert.playSound("train.wav");
Alert.addToList(getSymbol(),"Buy=" + getSymbol() + "@" + close(), Color.black, Color.green );
debugPrintln("Buy Strength:" +" "+ Math.round(SSB.getValue(0)/3) + "%");
debugPrintln();
drawTextRelative(0, low() - (low()-low()*0.98), Math.round(SSB.getValue(0)/3) + "%", Color.blue, null,
Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Buy Strength");
vLastAlert = 1;
}}
function onAction2() {
if (Strategy.isShort() == false) {
Strategy.doShort("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
drawShapeRelative(0, high() + (high()-high()*0.99), Shape.SQUARE, "", Color.RGB(255,0,0), Shape.LEFT);
debugPrintln( "Sell" + "//" + getSymbol() + "//" + "close = " + close() + "//" );
debugPrintln("Sell Strength:" +" "+ Math.round(SSS.getValue(0)/3) + "%");
debugPrintln();
drawTextRelative(0, high() + (high()-high()*0.98), Math.round(SSS.getValue(0)/3) + "%", Color.red, null,
Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Sell Strength");
//Alert.playSound("train.wav");
Alert.addToList(getSymbol(),"Sell=" + getSymbol() + "@" + close(), Color.black, Color.red);
vLastAlert = -1;
}}
I have written a simple trading system that when certain indicators kick in together, a square is drawn on the screen indicating to go long or short.
I have also created a simple signal strength indicator in another file that tells me how strong the signal is.
What I want to do is get the signal strength to print over the square on the screen. I have written (below) what i think it should be however it only shows the strength on the last two signals.
Any help would be much appreciated:
(code for trade signals)
var fpArray = new Array();
var bInit = false;
var xRSI = null;
var xStoch = null;
var xMACD = null;
var SSB = null;
var SSS = null;
var vLastAlert = -1;
var i=0;
var j=0;
function preMain() {
setPriceStudy(true);
setStudyTitle("Daily Dot");
setColorPriceBars(true);
setComputeOnClose(true);
setDefaultPriceBarColor(Color.black);
setShowTitleParameters(false);
setCursorLabelName("Daily Strategy",0);
var x =0;
fpArray[x] = new FunctionParameter("RSILength",FunctionParameter.NU MBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(30);
}
fpArray[x] = new FunctionParameter("Stoch1",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("Stoch2",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(9);
}
fpArray[x] = new FunctionParameter("Stoch3",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("MACD1",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("MACD2",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(52);
}
fpArray[x] = new FunctionParameter("MACD3",FunctionParameter.NUMBER );
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(9);
}
fpArray[x] = new FunctionParameter("RSIUPPER",FunctionParameter.NUM BER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(40);
}
fpArray[x] = new FunctionParameter("RSILOWER",FunctionParameter.NUM BER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(60);
}
}
function main(RSILength,Stoch1,Stoch2,Stoch3,MACD1,MACD2,MA CD3,RSIUPPER,RSILOWER) {
var nBarState = getBarState();
if (nBarState == BARSTATE_ALLBARS) { //BARSTATE_ALLBARS I think is the first bar on the screen
if (RSILength == null) RSILength = 30;
if (Stoch1 == null) Stoch1 = 26;
if (Stoch2 == null) Stoch2 = 9;
if (Stoch3 == null) Stoch3 = 3;
if (MACD1 == null) MACD1 = 26;
if (MACD2 == null) MACD2 = 52;
if (MACD3 == null) MACD3 = 9;
if (RSILOWER == null) RSILOWER = 40;
if (RSIUPPER == null) RSIUPPER = 60;
}
if (bInit == false) {
xRSI = rsi(RSILength);
xStoch = new StochStudy(Stoch1,Stoch2,Stoch3);
xMACD = new MACDStudy(MACD1, MACD2, MACD3, "Close", false);
SSB = efsExternal("ESSB.efs");
SSS = efsExternal("ESSS.efs");
bInit = true;
}
if(getCurrentBarIndex() == 0) return;
if(xRSI.getValue(0) == null) return;
if(xStoch.getValue(0) == null) return;
if(xMACD.getValue(0) == null) return;
if(SSB.getValue(0) == null) return;
if(SSS.getValue(0) == null) return;
for ( i =0 ; i >= -25 ; i-- ) {
for ( j=0 ; j >= -30 ; j-- ) {
if (
xStoch.getValue(StochStudy.FAST,i) > xStoch.getValue(StochStudy.SLOW,i) &&
xStoch.getValue(StochStudy.FAST,i-1) < xStoch.getValue(StochStudy.SLOW,i-1) &&
xMACD.getValue(MACDStudy.HIST,j) > 0 &&
xMACD.getValue(MACDStudy.HIST,j-1) < 0 &&
xRSI.getValue(0) > RSILOWER
)
onAction1()
else if (
xStoch.getValue(StochStudy.FAST,i) < xStoch.getValue(StochStudy.SLOW,i) &&
xStoch.getValue(StochStudy.FAST,i-1) > xStoch.getValue(StochStudy.SLOW,i-1) &&
xMACD.getValue(MACDStudy.HIST,j) < 0 &&
xMACD.getValue(MACDStudy.HIST,j-1) > 0 &&
xRSI.getValue(0) < RSIUPPER
)
onAction2()
}};
/*if(Strategy.isLong())
setPriceBarColor(Color.green);
else if(Strategy.isShort())
setPriceBarColor(Color.red);*/
return /*vLastAlert*/;
}
function postMain() {
}
function onAction1() {
if (Strategy.isLong() == false) {
Strategy.doLong("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
debugPrintln("Buy" + "//" + getSymbol() + "//" + "close = " + close() + "//" );
drawShapeRelative(0, low() - (low()-low()*0.99), Shape.SQUARE, "", Color.RGB(0,0,255), Shape.LEFT);
//Alert.playSound("train.wav");
Alert.addToList(getSymbol(),"Buy=" + getSymbol() + "@" + close(), Color.black, Color.green );
debugPrintln("Buy Strength:" +" "+ Math.round(SSB.getValue(0)/3) + "%");
debugPrintln();
drawTextRelative(0, low() - (low()-low()*0.98), Math.round(SSB.getValue(0)/3) + "%", Color.blue, null,
Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Buy Strength");
vLastAlert = 1;
}}
function onAction2() {
if (Strategy.isShort() == false) {
Strategy.doShort("", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT, 0);
drawShapeRelative(0, high() + (high()-high()*0.99), Shape.SQUARE, "", Color.RGB(255,0,0), Shape.LEFT);
debugPrintln( "Sell" + "//" + getSymbol() + "//" + "close = " + close() + "//" );
debugPrintln("Sell Strength:" +" "+ Math.round(SSS.getValue(0)/3) + "%");
debugPrintln();
drawTextRelative(0, high() + (high()-high()*0.98), Math.round(SSS.getValue(0)/3) + "%", Color.red, null,
Text.BOLD|Text.BOTTOM|Text.FRAME, null, 10, "Sell Strength");
//Alert.playSound("train.wav");
Alert.addToList(getSymbol(),"Sell=" + getSymbol() + "@" + close(), Color.black, Color.red);
vLastAlert = -1;
}}
Comment