hi there,
I've had lots of great help from this forum and I hope you guys can come through with this one! Attached/below is the Donchian channel with an offset of 1, which I use to ID trailing (any period) breaks, for entries and sometimes exits. I've tried to place the simple alert in the code without sucess. Here is what I want it to do. Once one of the channel lines are broken, give me an alert, ONLY ONE TIME, posted in the alert trigger list and a sound. (it's already giving a color bar when triggered). I had placed the alert string right after the following if and else statements,
if(high() > hh)
setPriceBarColor(Color.lime);
else if(low() < ll)
setPriceBarColor(Color.red)
else
setPriceBarColor(Color.black)
which worked but alerts kept repeating with each new price.
Thanks for your help,
chris...
//////////////////////////////////////////////////////////////
//This is the Donchian channel with offset of 1
//alert test
function preMain() {
setStudyTitle("Chris HHLL alert");
setCursorLabelName("Highest High", 0);
setCursorLabelName("Lowest Low", 1);
setPriceStudy(true);
setColorPriceBars(true);
}
var bIsLong = false;
var bIsShort = false;
function main(nInputLength) {
if(nInputLength == null)
nInputLength = 2;
var nLength = nInputLength + 1;
var i;
var hh = 0;
var ll = 0;
var vLow = low(0, -nLength);
var vHigh = high(0, -nLength);
if(vHigh == null || vLow ==null)
return null;
for(i = 1; i < nLength; i++) {
hh = Math.max(hh, vHigh[i]);
if(i == 1)
ll = vLow[i];
else
ll = Math.min(ll, vLow[i]);
}
if(high() > hh)
setPriceBarColor(Color.lime);
else if(low() < ll)
setPriceBarColor(Color.red)
else
setPriceBarColor(Color.black)
return new Array(hh,ll);
//set popup on alert list and sound
if(high() > hh) {
if(!bIsLong) {
Alert.addToList(getSymbol(), "Highest High", Color.black, Color.green);
Alert.playSound("swoosh.wav");
bIsLong = true;
bIsShort = false;
}
} else {
//set popup on alert list and sound
if(low() < ll) {
if(!bIsShort) {
Alert.addToList(getSymbol(), "Lowest Low", Color.blue, Color.red);
Alert.playSound("train.wav");
bIsLong = false;
bIsShort = true;
}
}
}
}
//////////////////////////////////////////
I've had lots of great help from this forum and I hope you guys can come through with this one! Attached/below is the Donchian channel with an offset of 1, which I use to ID trailing (any period) breaks, for entries and sometimes exits. I've tried to place the simple alert in the code without sucess. Here is what I want it to do. Once one of the channel lines are broken, give me an alert, ONLY ONE TIME, posted in the alert trigger list and a sound. (it's already giving a color bar when triggered). I had placed the alert string right after the following if and else statements,
if(high() > hh)
setPriceBarColor(Color.lime);
else if(low() < ll)
setPriceBarColor(Color.red)
else
setPriceBarColor(Color.black)
which worked but alerts kept repeating with each new price.
Thanks for your help,
chris...
//////////////////////////////////////////////////////////////
//This is the Donchian channel with offset of 1
//alert test
function preMain() {
setStudyTitle("Chris HHLL alert");
setCursorLabelName("Highest High", 0);
setCursorLabelName("Lowest Low", 1);
setPriceStudy(true);
setColorPriceBars(true);
}
var bIsLong = false;
var bIsShort = false;
function main(nInputLength) {
if(nInputLength == null)
nInputLength = 2;
var nLength = nInputLength + 1;
var i;
var hh = 0;
var ll = 0;
var vLow = low(0, -nLength);
var vHigh = high(0, -nLength);
if(vHigh == null || vLow ==null)
return null;
for(i = 1; i < nLength; i++) {
hh = Math.max(hh, vHigh[i]);
if(i == 1)
ll = vLow[i];
else
ll = Math.min(ll, vLow[i]);
}
if(high() > hh)
setPriceBarColor(Color.lime);
else if(low() < ll)
setPriceBarColor(Color.red)
else
setPriceBarColor(Color.black)
return new Array(hh,ll);
//set popup on alert list and sound
if(high() > hh) {
if(!bIsLong) {
Alert.addToList(getSymbol(), "Highest High", Color.black, Color.green);
Alert.playSound("swoosh.wav");
bIsLong = true;
bIsShort = false;
}
} else {
//set popup on alert list and sound
if(low() < ll) {
if(!bIsShort) {
Alert.addToList(getSymbol(), "Lowest Low", Color.blue, Color.red);
Alert.playSound("train.wav");
bIsLong = false;
bIsShort = true;
}
}
}
}
//////////////////////////////////////////
Comment