Hi,
I've attempted to make a "signal strength" indicator for MACD, Stochastics and RSI.
I make rules for the position of the indicators (RSI away from 50, k/d difference and MACd histogram) and then add them together for a simple strength indicator which is plotted as a line.
The problem is that the value of the line today is the value of the indicators yesterday. (for example, when all the indicators are "negative" the buy strength should be 0 but it only goes to zero on the next day)
Any help with this would be much appreciated.
var study = null;
var study2 = null;
var study3 = null;
var vHistS = 0;
var vRSIS = 0;
var vHistM = 0;
var vMACDS = 0;
var vTOTS = 0;
var fpArray = new Array()
function preMain() {
setStudyTitle("Euro Sell Strength");
setCursorLabelName("Sell Strength Absolute");
setShowTitleParameters(false);
setComputeOnClose(true);
addBand(0, PS_DASH, 1, Color.black);
addBand(300, PS_DASH, 1, Color.black);
addBand(150, PS_DASH, 1, Color.black);
/*addBand(100, PS_DASH, 1, Color.black);
addBand(50, PS_DASH, 1, Color.black);*/
setDefaultBarFgColor(Color.black);
setPlotType(PLOTTYPE_LINE);
var x =0;
fpArray[x] = new FunctionParameter("nInputPercentK1",FunctionParame ter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("nInputPercentK2",FunctionParame ter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(6);
}
fpArray[x] = new FunctionParameter("nInputPercentD",FunctionParamet er.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("nInputRSI",FunctionParameter.NU MBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(30);
}
fpArray[x] = new FunctionParameter("nMACD1",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("nMACD2",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(52);
}
fpArray[x] = new FunctionParameter("nMACD3",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(15);
}
}
function main(nInputPercentK1, nInputPercentK2, nInputPercentD, nInputRSI, nMACD1, nMACD2, nMACD3) {
if (nInputPercentK1 == null) {
nInputPercentK1 = 10;
}
else {
nInputPercentK1 = Math.round(nInputPercentK1);
}
if (nInputPercentK2 == null) {
nInputPercentK2 = 6;
}
else {
nInputPercentK2 = Math.round(nInputPercentK2);
}
if (nInputPercentD == null) {
nInputPercentD = 3;
}
else {
nInputPercentD = Math.round(nInputPercentD);
}
if (nInputRSI == null) {
nInputRSI = 21;
}
else {
nInputRSI = Math.round(nInputRSI);
}
if(nMACD1 == null) {
nMACD1 = 12;
}
else {
nMACD1 == Math.round(nMACD1)
}
if(nMACD2 == null) {
nMACD2 = 26;
}
else {
nMACD2 == Math.round(nMACD2)
}
if(nMACD3 == null) {
nMACD3 = 9;
}
else {
nMACD3 == Math.round(nMACD3)
}
if( getCurrentBarCount() <=35 ) return;
if (study == null) study = new StochStudy(nInputPercentK1, nInputPercentK2, nInputPercentD);
if (study2 == null) study2 = new RSIStudy(nInputRSI);
if (study3 == null) study3 = new MACDStudy(nMACD1,nMACD2,nMACD3, "Close", false);
var vFast = study.getValue(StochStudy.FAST);
var vSlow = study.getValue(StochStudy.SLOW);
var vRSI = study2.getValue(0);
var vMACD = study3.getValue(MACDStudy.HIST);
var vTOTS = vHistS + vRSIS + vMACDS;
var vHist = vFast - vSlow;
if(vHist >= 0) vHistS = 0;
if(vHist < 0 && vHist >= -2.79) vHistS = 12.5;
if(vHist < -2.79 && vHist >= -4.78) vHistS = 37.5;
if(vHist < -4.78 && vHist >= -8.38) vHistS = 75;
if(vHist < -8.38 && vHist >= -14.28) vHistS = 100;
if(vHist < -14.28) vHistS = 75;
if(vRSI >= 50) vRSIS = 0;
if(vRSI < 50 && vRSI >= 47.56) vRSIS = 12.5;
if(vRSI < 47.56 && vRSI >= 42.89) vRSIS = 37.5;
if(vRSI < 42.89 && vRSI >= 37.77) vRSIS = 75;
if(vRSI < 37.77 && vRSI >= 21.26 ) vRSIS = 100;
if(vRSI < 21.26 ) vRSIS = 75;
if(vMACD >= 0) vMACDS = 0;
if(vMACD < 0 && vMACD >= -3.8287) vMACDS = 12.5;
if(vMACD < -3.8287 && vMACD >= -13.1095) vMACDS = 37.5;
if(vMACD < -13.1095 && vMACD >= -24.51) vMACDS = 75;
if(vMACD < -24.51 && vMACD >= -81.62) vMACDS = 100;
if(vMACD < -81.62) vMACDS = 75;
if (vTOTS >= 0) {
setBarFgColor(Color.red);
} else {
setBarFgColor(Color.black);
}
return vTOTS;
}
I've attempted to make a "signal strength" indicator for MACD, Stochastics and RSI.
I make rules for the position of the indicators (RSI away from 50, k/d difference and MACd histogram) and then add them together for a simple strength indicator which is plotted as a line.
The problem is that the value of the line today is the value of the indicators yesterday. (for example, when all the indicators are "negative" the buy strength should be 0 but it only goes to zero on the next day)
Any help with this would be much appreciated.
var study = null;
var study2 = null;
var study3 = null;
var vHistS = 0;
var vRSIS = 0;
var vHistM = 0;
var vMACDS = 0;
var vTOTS = 0;
var fpArray = new Array()
function preMain() {
setStudyTitle("Euro Sell Strength");
setCursorLabelName("Sell Strength Absolute");
setShowTitleParameters(false);
setComputeOnClose(true);
addBand(0, PS_DASH, 1, Color.black);
addBand(300, PS_DASH, 1, Color.black);
addBand(150, PS_DASH, 1, Color.black);
/*addBand(100, PS_DASH, 1, Color.black);
addBand(50, PS_DASH, 1, Color.black);*/
setDefaultBarFgColor(Color.black);
setPlotType(PLOTTYPE_LINE);
var x =0;
fpArray[x] = new FunctionParameter("nInputPercentK1",FunctionParame ter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("nInputPercentK2",FunctionParame ter.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(6);
}
fpArray[x] = new FunctionParameter("nInputPercentD",FunctionParamet er.NUMBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("nInputRSI",FunctionParameter.NU MBER);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(30);
}
fpArray[x] = new FunctionParameter("nMACD1",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(26);
}
fpArray[x] = new FunctionParameter("nMACD2",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(52);
}
fpArray[x] = new FunctionParameter("nMACD3",FunctionParameter.NUMBE R);
with(fpArray[x++]) {
setLowerLimit(1);
setDefault(15);
}
}
function main(nInputPercentK1, nInputPercentK2, nInputPercentD, nInputRSI, nMACD1, nMACD2, nMACD3) {
if (nInputPercentK1 == null) {
nInputPercentK1 = 10;
}
else {
nInputPercentK1 = Math.round(nInputPercentK1);
}
if (nInputPercentK2 == null) {
nInputPercentK2 = 6;
}
else {
nInputPercentK2 = Math.round(nInputPercentK2);
}
if (nInputPercentD == null) {
nInputPercentD = 3;
}
else {
nInputPercentD = Math.round(nInputPercentD);
}
if (nInputRSI == null) {
nInputRSI = 21;
}
else {
nInputRSI = Math.round(nInputRSI);
}
if(nMACD1 == null) {
nMACD1 = 12;
}
else {
nMACD1 == Math.round(nMACD1)
}
if(nMACD2 == null) {
nMACD2 = 26;
}
else {
nMACD2 == Math.round(nMACD2)
}
if(nMACD3 == null) {
nMACD3 = 9;
}
else {
nMACD3 == Math.round(nMACD3)
}
if( getCurrentBarCount() <=35 ) return;
if (study == null) study = new StochStudy(nInputPercentK1, nInputPercentK2, nInputPercentD);
if (study2 == null) study2 = new RSIStudy(nInputRSI);
if (study3 == null) study3 = new MACDStudy(nMACD1,nMACD2,nMACD3, "Close", false);
var vFast = study.getValue(StochStudy.FAST);
var vSlow = study.getValue(StochStudy.SLOW);
var vRSI = study2.getValue(0);
var vMACD = study3.getValue(MACDStudy.HIST);
var vTOTS = vHistS + vRSIS + vMACDS;
var vHist = vFast - vSlow;
if(vHist >= 0) vHistS = 0;
if(vHist < 0 && vHist >= -2.79) vHistS = 12.5;
if(vHist < -2.79 && vHist >= -4.78) vHistS = 37.5;
if(vHist < -4.78 && vHist >= -8.38) vHistS = 75;
if(vHist < -8.38 && vHist >= -14.28) vHistS = 100;
if(vHist < -14.28) vHistS = 75;
if(vRSI >= 50) vRSIS = 0;
if(vRSI < 50 && vRSI >= 47.56) vRSIS = 12.5;
if(vRSI < 47.56 && vRSI >= 42.89) vRSIS = 37.5;
if(vRSI < 42.89 && vRSI >= 37.77) vRSIS = 75;
if(vRSI < 37.77 && vRSI >= 21.26 ) vRSIS = 100;
if(vRSI < 21.26 ) vRSIS = 75;
if(vMACD >= 0) vMACDS = 0;
if(vMACD < 0 && vMACD >= -3.8287) vMACDS = 12.5;
if(vMACD < -3.8287 && vMACD >= -13.1095) vMACDS = 37.5;
if(vMACD < -13.1095 && vMACD >= -24.51) vMACDS = 75;
if(vMACD < -24.51 && vMACD >= -81.62) vMACDS = 100;
if(vMACD < -81.62) vMACDS = 75;
if (vTOTS >= 0) {
setBarFgColor(Color.red);
} else {
setBarFgColor(Color.black);
}
return vTOTS;
}
Comment