Announcement

Collapse
No announcement yet.

adding alert to amtriangular

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

  • adding alert to amtriangular

    Alex-
    I've been using your AM Triangular MA.
    Is there a way to have a sound alert and pop-up when price bar touches/crosses this ma?
    Thanks for your help.
    dido


    var fpArray = new Array();

    function preMain() {

    setPriceStudy(true);
    setStudyTitle("Triangular MA");
    setCursorLabelName("TMA",0);
    setDefaultBarFgColor(Color.blue,0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    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("Offset", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setDefault(0);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var amLib = addLibrary("amStudies.efsLib");
    var bInit = false;
    var xTMA = null;

    function main(Length,Source,Symbol,Interval,Offset,Params) {

    if(bInit == false){
    with( amLib ) {
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xTMA = offsetSeries(amTMA(Length,eval(Source)(sym(vSymbol ))),Offset);
    setShowTitleParameters(eval(Params));
    bInit = true;
    }
    }

    return getSeries(xTMA);

  • #2
    dido
    There are many ways of triggeering alerts and the one shown here is just one of them.
    Create a global variable called for example alertTriggered and set it to false.



    Then in function main before you set the conditions for the alerts create a BARSTATE_NEWBAR condition that is used to reset the alertTriggered flag to false (see following image)



    At this point you can add your conditions. These will check if the High of the prior bar was below the average and if the High of the current bar is above. It also checks if the alertTriggered flag is equal to false.
    If the conditions are true then it triggers the alerts and sets the alertTriggerd flag to true so that only one alert will be triggered per event.



    At this point you can add the reverse logic to trigger the alerts when prices cross the average from above to below. You will need to check that at the prior bar the Low was higher than the average and that at the current bart it is lower. Also check for the alertTriggered flag to be equal to false. Lastly add the required commands using the ones I show above as examples.
    FWIW one of the reasons why all the studies contained in the amStudies function library are written the way they are is so that they can be used exactly as the eSignal builtin studies. Hence the logic and the syntax required to trigger alerts, signals, etc is just the same as what you would use with any of the eSignal studies. This means that most of the examples that are available in these forums are applicable to any one of the amStudies.
    Alex

    Comment


    • #3
      thanks

      thanks alex, i'll give it a try.

      Comment

      Working...
      X