I am trying to add an alert to the built-in DiNapoli Stochastic so when the fast Stochastic reaches the 20 or 80 level my computer will beep.
I have tried to program it myself but it does not seem to work. Can someone please help me and let me know what I am doing wrong.
I have tried to program it myself but it does not seem to work. Can someone please help me and let me know what I am doing wrong.
PHP Code:
addBand(80, PS_SOLID, 1, Color.grey, "Upper");
addBand(20, PS_SOLID, 1, Color.grey, "Lower");
function preMain()
{
setStudyTitle("Stochastic Alert");
setCursorLabelName("percentK", 0);
setCursorLabelName("percentD", 1);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
}
var MAVt = null;
var MAVt1 = null;
var MAVt_1 = 0;
var MAVt1_1 = 0;
function main(nLength, nSmoothing, nSmoothings) {
if(nLength == null)
nLength = 8;
if(nSmoothing == null)
nSmoothing = 3;
if(nSmoothings == null)
nSmoothings = 3;
var percentK;
var ll = 0, hh = 0;
var sum = 0;
var vHigh = getValue("High", 0, -nLength);
var vLow = getValue("Low", 0, -nLength);
var temp = 0;
if(vHigh == null || vLow == null)
return;
for(j = 0; j < nLength; j++) {
if(j == 0) {
ll = vLow[j];
hh = vHigh[j];
} else {
hh = Math.max(hh, vHigh[j]);
ll = Math.min(ll, vLow[j]);
}
}
percentK = ((close() - ll) / (hh - ll)) * 100;
if (isNaN(percentK) == false) MAVt = MAVt_1 + (percentK - MAVt_1) / nSmoothing;
if (getBarState() == BARSTATE_NEWBAR) MAVt_1 = MAVt;
if (isNaN(percentK) == false) MAVt1 = MAVt1_1 + (MAVt - MAVt1_1) / nSmoothings;
if (getBarState() == BARSTATE_NEWBAR) MAVt1_1 = MAVt1;
return new Array(MAVt,MAVt1);
/*********************************************
ALERTS
**********************************************/
if(getBarState()==BARSTATE_NEWBAR){
if(MAVt.getValue(MAVt,-2) < Upper && MAVt.getValue(MAVt,-1)>Upper){
Alert.playSound("ding.wav");
if(MAVt.getValue(MAVt,-2) > Lower && MAVt.getValue(MAVt,-1)<Lower){
Alert.playSound("ding.wav");
}
}}
}
Comment