Announcement

Collapse
No announcement yet.

Email alert

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

  • Email alert

    Hi,

    How can I get an email alert in to this trading system? I tried the code but than I get an email every second. How can I get an email one time? This is the code:
    var study = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);

    function preMain() {
    setPriceStudy(true);
    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.black);
    }

    function main() {
    var v = study.getValue(MAStudy.MA);
    if(v == null)
    return;
    if(close() >= v && !Strategy.isLong())
    Strategy.doLong("Crossing Up", Strategy.MARKET, Strategy.THISBAR);
    if(close() < v && !Strategy.isShort())
    Strategy.doShort("Crossing Down", Strategy.MARKET, Strategy.THISBAR);
    if(Strategy.isLong())
    setPriceBarColor(Color.lime);
    else if(Strategy.isShort())
    setPriceBarColor(Color.red);
    return v;
    }

  • #2
    biotoc
    First of all you may want to check the length of the MA that is currently set to 1.
    Secondly even with an MA of different length this system could whipsaw you intrabar if the Close crosses back and forth the MA. You may want to set the efs to compute on close only by adding a setComputeOnClose(); in preMain. This would also resolve the multiple emails issue.
    Lastly you may want to replace Strategy.MARKET which will enter a trade on the Open of the bar that triggers the signal (which is somewhat unrealistic) to Strategy.CLOSE which will enter the trade on the Close of the bar that generates the signal.
    Just some ideas
    Alex

    Comment


    • #3
      Hi,

      I'm new to this. I thought the solution was going to be simple. Currently it keeps sending emails instead of a one time alert at the buy or sell signal. How can I make it send just one email at a buy alert and one email at a sell alert. That would be great.

      Thanks,
      Patrick

      Comment


      • #4
        Patrick
        The enclosed revision of your script will generate one email only per signal.
        However, it will not prevent multiple signals to be triggered intrabar when the close crosses back and forth the MA.
        Alex

        PHP Code:
        var study = new MAStudy(10"Close"MAStudy.SIMPLE);
        vLastAlert = -1;

        function 
        preMain() {
        setPriceStudy(true);
        setColorPriceBars(true);
        setDefaultPriceBarColor(Color.black);
        }

        function 
        main() {
        var 
        study.getValue(MAStudy.MA);
        if(
        == null)
        return;

        if(
        close() >= && !Strategy.isLong())
        Strategy.doLong("Crossing Up"Strategy.MARKETStrategy.THISBAR);
        if(
        close() < && !Strategy.isShort())
        Strategy.doShort("Crossing Down"Strategy.MARKETStrategy.THISBAR);

        if(
        Strategy.isLong()){
        setPriceBarColor(Color.lime);
        if(
        vLastAlert!=1)Alert.email("Buy");
        vLastAlert=1;
        }
        else if(
        Strategy.isShort()){
        setPriceBarColor(Color.red);
        if(
        vLastAlert!=2)Alert.email("Sell");
        vLastAlert=2;
        }

        return 
        v;

        Comment

        Working...
        X