Announcement

Collapse
No announcement yet.

MA MOM Arrows and Alert

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

  • MA MOM Arrows and Alert

    Can someone help me?

    Here is Alex's efs for the MA of the MOM.
    I'm just trying to get it to draw an arrow on the price chart with an audible alert. when the MOM goes south of the MA.
    Thanks for your time...Greg


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

    var fpArray = new Array();

    function preMain() {

    setStudyTitle("MAofMOM");
    setCursorLabelName("MOM", 0);
    setCursorLabelName("MAofMOM", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(10);
    }
    fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("open");
    addOption("high");
    addOption("low");
    addOption("close");
    addOption("hl2");
    addOption("hlc3");
    addOption("ohlc4");
    setDefault("close");
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("MAType", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("sma");
    addOption("ema");
    addOption("wma");
    setDefault("sma");
    }
    fpArray[x] = new FunctionParameter("MALength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(10);
    }
    fpArray[x] = new FunctionParameter("LineColor1", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("Color1");
    setDefault(Color.blue);
    }
    fpArray[x] = new FunctionParameter("LineColor2", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("Color2");
    setDefault(Color.red);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var xMOM = null;
    var xMAofMOM = null;

    function main(Length,Source,Symbol,Interval,MAType,MALength ,LineColor1,LineColor2,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xMOM = mom(Length,eval(Source)(sym(vSymbol)));
    xMAofMOM = eval(MAType)(MALength,mom(Length,eval(Source)(sym( vSymbol))));
    setDefaultBarFgColor(LineColor1,0);
    setDefaultBarFgColor(LineColor2,1);
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return new Array (getSeries(xMOM),getSeries(xMAofMOM));

    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).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    drawTextRelative(0, high(), "ê", Color.red, null, Text.BOTTOM|Text.CENTER|Text.BOLD, "Wingdings", 10);
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ohno.wav");
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions
    }

  • #2
    Greg
    First of all you need to remove the closing bracket } which is at the very end of your script and add one in the line immediately following return new Array (getSeries(xMOM),getSeries(xMAofMOM));
    Then in the line immediately above return new Array (getSeries(xMOM),getSeries(xMAofMOM)); insert the following lines of code
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR){
            if(
    xMOM.getValue(-2) >= xMAofMOM.getValue(-2) && xMOM.getValue(-1) < xMAofMOM.getValue(-1)){
                
    onAction1();
            }
        } 
    This is the condition that determines when the Momentum closes below its moving average. When that event occurrs it calls the function onAction1() which you added at the end of the script. Note that this condition is evaluated only at the completion of a bar
    Lastly replace the following line
    PHP Code:
    drawTextRelative(0high(), "ê"Color.rednullText.BOTTOM|Text.CENTER|Text.BOLD"Wingdings"10); 
    with the following
    PHP Code:
    drawTextRelative(-1xMAofMOM.getValue(-1), "ê"Color.rednullText.BOTTOM|Text.CENTER|Text.BOLD"Wingdings"10); 
    Because an efs cannot draw/plot in two separate panes at the same time I replaced the parameter high() in that command with xMAofMOM.getValue(-1) so that the arrow gets drawn at the appropriate location in the indicator pane.
    If you encounter any problems post the efs as you have modified it and I or someone else can help you fix it
    Alex

    Comment


    • #3
      MA MOM

      Alex;
      Thanks once again.
      That worked perfectly.
      Have a great week...
      Greg

      Comment


      • #4
        Greg
        My pleasure and a great week to you too
        Alex

        Comment

        Working...
        X