Announcement

Collapse
No announcement yet.

Audio alert not working/Backroud color change?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Audio alert not working/Backroud color change?

    Im trying to configure an alert system that shows the triangle on my chart and fires off the ding.wav when a linear reg band is broken - Im using the following code and can get the triangles to appear, but not getting any sound - does anyone know what is wrong with it?

    *on a side note, does anyone have code to change the backround color of the chart for an alert? Meaning, if one of my linear reg bands are broke, i would like the chart color to change to red or something....


    /************************************************** *******
    Alexis C. Montenegro © July 2003
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/

    /************************************************** ***********************************
    This EFS plots a Linear Regression Channel of HLC/3 over 64 periods with 2 Std Dev.
    It sounds an audio alert and plots a red or blue triangle at the top and bottom of the
    chart when prices touch the upper or lower bands respectively.
    Defaults are Source = HLC/3, Length = 64, Std Dev = 2.
    Source, Length and Std Dev can be modified using Edit Studies.
    Source inputs can be "Close", "High", "Low", "HL/2", "HLC/3".
    Note: Do NOT use this script as an example to build other scripts as it contains some
    code specific to this formula.
    This EFS requires build 564 or higher and is enabled for auto-update (checkVersion)
    ************************************************** ************************************/

    var vLinReg = null;
    var vLastAlert = -1;
    var vLastCount = null;

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("LinReg");
    setCursorLabelName("LRup", 0);
    setCursorLabelName("LRlo", 1);
    setCursorLabelName("LRb",2);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarStyle(PS_SOLID, 2);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.black, 2);
    setDefaultBarThickness(1, 0);
    setDefaultBarThickness(1, 1);
    setDefaultBarThickness(1, 2);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    setPlotType(PLOTTYPE_LINE, 2);
    checkVersion(2,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/LinReg.efs");

    var fp1 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp1.setName("Source");
    fp1.addOption("Close");
    fp1.addOption("High");
    fp1.addOption("Low");
    fp1.addOption("HL/2");
    fp1.addOption("HLC/3");
    fp1.setDefault("HLC/3");

    var fp2 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp2.setLowerLimit(2);
    fp2.setDefault(64);

    var fp3 = new FunctionParameter("StdDev", FunctionParameter.NUMBER);
    fp3.setLowerLimit(0);
    fp3.setDefault(2);

    }

    function main(Source,Length,StdDev) {

    if(vLastCount == null)
    vLastCount = getNumBars();
    if(vLastCount != getNumBars()) {
    vLastCount = getNumBars();
    reloadEFS();
    return;
    }

    if(vLinReg==null) vLinReg = new LinearRegressionStudy(Source, Length, StdDev);

    if (high() >= vLinReg.getValue(LinearRegressionStudy.UPPER) &&
    high(-1) < vLinReg.getValue(LinearRegressionStudy.UPPER,-1))
    onAction1()

    else if (low() <= vLinReg.getValue(LinearRegressionStudy.LOWER)&&
    low(-1) > vLinReg.getValue(LinearRegressionStudy.LOWER,-1))
    onAction2();


    return new Array(
    vLinReg.getValue(LinearRegressionStudy.UPPER),
    vLinReg.getValue(LinearRegressionStudy.LOWER),
    vLinReg.getValue(LinearRegressionStudy.BASIS));
    }

    function postMain() {
    }

    function onAction1() {
    drawShapeRelative(0, 5, Shape.DOWNTRIANGLE , null, Color.red, Shape.RELATIVETOTOP,1);
    //Alert.playSound("C:\\PROGRAM FILES\\ESIGNAL\\Sounds\\Ding.wav");
    vLastAlert = 1;
    }

    function onAction2() {
    drawShapeRelative(0,0, Shape.UPTRIANGLE, null, Color.blue, Shape.RELATIVETOBOTTOM,2);
    //Alert.playSound("C:\\PROGRAM FILES\\ESIGNAL\\Sounds\\Ding.wav");
    vLastAlert = 2;
    }

  • #2
    Hi Iowa,

    If you replace the "onAction#" functions with the following it should work as you intend. I removed the path for the sound file since eSignal defaults to the directory that has the sound files.

    Also the following link will take you to the knowledgebase so you can research the different functions and their syntax.

    http://kb.esignal.com/

    wayne

    PHP Code:
    function onAction1() {
    drawShapeRelative(05Shape.DOWNTRIANGLE nullColor.redShape.RELATIVETOTOP,1);
    Alert.playSound("Ding.wav");
    setBarBgColor(Color.green);
    vLastAlert 1;
    }

    function 
    onAction2() {
    drawShapeRelative(0,0Shape.UPTRIANGLEnullColor.blueShape.RELATIVETOBOTTOM,2);
    Alert.playSound("Ding.wav");
    setBarBgColor(Color.red);
    vLastAlert 2;

    If you want to limit repeated alarms of the same type (i.e., so it only alternates between a break of the top LR and the bottom LR lines instead of multiple consecutive signals of the same type, say a break of the top LR line) try this code:

    PHP Code:
    function onAction1() {
        if(
    vLastAlert !=1){
            
    drawShapeRelative(05Shape.DOWNTRIANGLE nullColor.redShape.RELATIVETOTOP,1);
            
    Alert.playSound("Ding.wav");
            
    setBarBgColor(Color.green);
            
    vLastAlert 1;
        }
    }

    function 
    onAction2() {
        if(
    vLastAlert !=2){
            
    drawShapeRelative(0,0Shape.UPTRIANGLEnullColor.blueShape.RELATIVETOBOTTOM,2);
            
    Alert.playSound("Ding.wav");
            
    setBarBgColor(Color.red);
            
    vLastAlert 2;
        }

    Last edited by waynecd; 12-23-2009, 10:28 AM.

    Comment

    Working...
    X