I'm trying to make the AlertMA script that esignal comes with into a real time alert. That is it doesn't wait for a new bar to close above the MA to alert you, it will alert you immediately when it goes above and below the MA. I tried to change BARSTATE_NEWBAR to BARSTATE_CURRENTBAR but that didn't work. I suck at scripting so help would be appreciated thank you.
Announcement
Collapse
No announcement yet.
How to make alerts in real time?
Collapse
X
-
Here is the script:
/************************************************** **************************************************
Copyright © eSignal, a division of Interactive Data Corporation. 2006. All rights reserved.
This sample eSignal Formula Script (EFS) may be modified and saved under a new
filename; however, eSignal is no longer responsible for the functionality once modified.
eSignal reserves the right to modify and overwrite this EFS file with each new release.
************************************************** ************************************************** */
function preMain() {
setPriceStudy(true);
setStudyTitle("Alert MA");
setCursorLabelName("sma");
var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(10);
}
var bIsLong = false;
var bIsShort = false;
var xMA = null;
function main(nLength) {
if (xMA == null) xMA = ema(nLength);
var nState = getBarState();
var v = ema(nLength, -1);
if(v == null) return;
if (nState == BARSTATE_CURRENTBAR) {
if(close(-1) >= v) {
if(!bIsLong) {
Alert.addToList(getSymbol(), "Price is >= 10 Bar MA", Color.black, Color.green);
Alert.playSound("swoosh.wav");
bIsLong = true;
bIsShort = false;
}
} else {
if(!bIsShort) {
Alert.addToList(getSymbol(), "Price is < 10 Bar MA", Color.black, Color.red);
Alert.playSound("train.wav");
bIsLong = false;
bIsShort = true;
}
}
}
return xMA.getValue(0);
}
Comment