Announcement

Collapse
No announcement yet.

Help with watchlist

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with watchlist

    I modified an existing efs example and have not been able to get the code when used in a watch list to"
    1. Change the color of the watch list bar when the condition is true or
    2. Add a sound alert when the condition is true.

    If anyone can help with suggestions I am posting the code below:

    Thanks for any help in advance:

    /************************************************** *******
    Alexis C. Montenegro © April 2004
    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.
    ************************************************** ********/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("X");

    var vLastAlert = -1;

    var fp1 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp1.addOption("close() - sma(50)");

    fp1.addOption("");
    fp1.setDefault("close() - sma(50)");

    var fp2 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp2.setLowerLimit(1);
    fp2.setDefault(135);

    }

    var aValue = null;

    function main(Source,Length) {



    var i;
    var hh = 0;
    var ll = 0;

    var vPlot1 = eval(Source);//if using your own study replace eval(Source) with the returned value
    //form your study or the expression

    if (aValue == null) {
    aValue = new Array(Length);
    }
    if (getBarState() == BARSTATE_NEWBAR) {
    aValue.pop();
    aValue.unshift(vPlot1);
    } else {
    aValue[0] = vPlot1;
    }
    for(i = 0; i < Length; i++) {
    if(i == 0) {
    hh = aValue[i];
    ll = aValue[i];
    } else {
    hh = Math.max(hh, aValue[i]);
    ll = Math.min(ll, aValue[i]);
    }
    }


    if((high() > (hh + sma(50))))

    onAction1()



    else if((low() < (ll + sma(50))))

    onAction2();


    return null;

    function onAction1() {
    setBarBgColor(Color.RGB(0,128,0));
    vLastAlert = 1;
    }
    function onAction2() {
    setBarBgColor(Color.RGB(255,0,0));
    vLastAlert = 2;


    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    function onAction1() {
    setBarBgColor(Color.RGB(0,128,0));
    Alert.playSound("C:\\Users\\HOME\\Documents\\Inter active Data\\Sounds\\Ding.wav");

    vLastAlert = 1;
    }
    function onAction2() {
    setBarBgColor(Color.RGB(255,0,0));
    Alert.playSound("C:\\Users\\HOME\\Documents\\Inter active Data\\Sounds\\Ding.wav");
    vLastAlert = 2;
    Last edited by cosbyva; 06-03-2012, 08:08 PM.

  • #2
    Re: Help with watchlist

    cosbyva
    The script is missing the closing curly brackets for the main() and onAction2() functions. You may also want to remove either one of the duplicate onAction1() and onAction2() functions
    Once you resolve the above the script should work as expected
    Alex


    Originally posted by cosbyva
    I modified an existing efs example and have not been able to get the code when used in a watch list to"
    1. Change the color of the watch list bar when the condition is true or
    2. Add a sound alert when the condition is true.

    If anyone can help with suggestions I am posting the code below:

    Thanks for any help in advance:

    /************************************************** *******
    Alexis C. Montenegro © April 2004
    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.
    ************************************************** ********/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("X");

    var vLastAlert = -1;

    var fp1 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp1.addOption("close() - sma(50)");

    fp1.addOption("");
    fp1.setDefault("close() - sma(50)");

    var fp2 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp2.setLowerLimit(1);
    fp2.setDefault(135);

    }

    var aValue = null;

    function main(Source,Length) {



    var i;
    var hh = 0;
    var ll = 0;

    var vPlot1 = eval(Source);//if using your own study replace eval(Source) with the returned value
    //form your study or the expression

    if (aValue == null) {
    aValue = new Array(Length);
    }
    if (getBarState() == BARSTATE_NEWBAR) {
    aValue.pop();
    aValue.unshift(vPlot1);
    } else {
    aValue[0] = vPlot1;
    }
    for(i = 0; i < Length; i++) {
    if(i == 0) {
    hh = aValue[i];
    ll = aValue[i];
    } else {
    hh = Math.max(hh, aValue[i]);
    ll = Math.min(ll, aValue[i]);
    }
    }


    if((high() > (hh + sma(50))))

    onAction1()



    else if((low() < (ll + sma(50))))

    onAction2();


    return null;

    function onAction1() {
    setBarBgColor(Color.RGB(0,128,0));
    vLastAlert = 1;
    }
    function onAction2() {
    setBarBgColor(Color.RGB(255,0,0));
    vLastAlert = 2;


    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

    function onAction1() {
    setBarBgColor(Color.RGB(0,128,0));
    Alert.playSound("C:\\Users\\HOME\\Documents\\Inter active Data\\Sounds\\Ding.wav");

    vLastAlert = 1;
    }
    function onAction2() {
    setBarBgColor(Color.RGB(255,0,0));
    Alert.playSound("C:\\Users\\HOME\\Documents\\Inter active Data\\Sounds\\Ding.wav");
    vLastAlert = 2;

    Comment


    • #3
      Alex, Thanks for the help!

      Comment


      • #4
        cosbyva
        You are welcome
        Alex


        Originally posted by cosbyva View Post
        Alex, Thanks for the help!

        Comment

        Working...
        X