Announcement

Collapse
No announcement yet.

Stochastic and MACD crossover

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

  • Stochastic and MACD crossover

    Hello,
    I am trying to trigger an alert when the Stoch crosses 80/20 and confirmed MACD slow crosses over on a 3 min chart. I used the wizard to create the code.
    The problem that i face is that it triggers on every bar closed and does not just trigger on the actual crossovers. This kind of jams my system with the alerts flying off.

    Also, can i have one alert triggered on two different time frames..with the same indicators.

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vMACD4_13 = new MACDStudy(4, 13, 5, "Close", false);
    var vMACD4_13_2 = new MACDStudy(4, 13, 5, "Close", false);
    var vStoch5_3 = new StochStudy(5, 3, 1);
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("MACD Cross-over");
    setCursorLabelName("cross", 0);
    setDefaultBarStyle(PS_DOT, 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(1, 0);
    setPlotType(PLOTTYPE_LINE, 0);
    setComputeOnClose(true);
    //}}EFSWizard_PreMain

    }

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    vMACD4_13.getValue(MACDStudy.SIGNAL) < vMACD4_13.getValue(MACDStudy.MACD)
    ) onAction1()
    //}}EFSWizard_Expression_1

    //{{EFSWizard_Expression_2
    else if (
    vMACD4_13.getValue(MACDStudy.SIGNAL) > vMACD4_13.getValue(MACDStudy.MACD)
    ) onAction2()
    //}}EFSWizard_Expression_2

    //{{EFSWizard_Expression_3
    else if (
    vStoch5_3.getValue(StochStudy.SLOW) < vStoch5_3.getValue(StochStudy.FAST)
    ) onAction3()
    //}}EFSWizard_Expression_3

    //{{EFSWizard_Expression_4
    else if (
    vStoch5_3.getValue(StochStudy.SLOW) > vStoch5_3.getValue(StochStudy.FAST)
    ) onAction4();
    //}}EFSWizard_Expression_4

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return ;
    //}}EFSWizard_Return

    }

    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() {
    Alert.addToList(getSymbol(), "MACD Signal Cross Down", Color.RGB(0,0,0), Color.RGB(195,0,0));
    Alert.playSound("C:\\Program Files\\esignal\\Workstation\\Sounds\\Ding.wav");
    drawShapeRelative(0, high(), Shape.DOWNARROW, "", Color.RGB(155,0,0), Shape.BOTTOM);
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //{{EFSWizard_Action_2
    function onAction2() {
    Alert.addToList(getSymbol(), "MACD Signal Cross Up", Color.RGB(0,0,0), Color.RGB(195,0,0));
    Alert.playSound("C:\\Program Files\\esignal\\Workstation\\Sounds\\Ding.wav");
    drawShapeRelative(0, low(), Shape.UPARROW, "", Color.RGB(155,0,0), Shape.TOP);
    vLastAlert = 2;
    }
    //}}EFSWizard_Action_2

    //{{EFSWizard_Action_3
    function onAction3() {
    Alert.addToList(getSymbol(), "Stoch Cross Down", Color.RGB(0,0,0), Color.RGB(195,0,0));
    Alert.playSound("C:\\Program Files\\esignal\\Workstation\\Sounds\\Ding.wav");
    drawShapeRelative(0, high(), Shape.DOWNARROW, "", Color.RGB(155,0,0), Shape.TOP);
    vLastAlert = 3;
    }
    //}}EFSWizard_Action_3

    //{{EFSWizard_Action_4
    function onAction4() {
    Alert.addToList(getSymbol(), "Stoc Cross Up", Color.RGB(0,0,0), Color.RGB(195,0,0));
    Alert.playSound("C:\\Program Files\\esignal\\Workstation\\Sounds\\Ding.wav");
    drawShapeRelative(0, high(), Shape.UPARROW, "", Color.RGB(155,0,0), Shape.BOTTOM);
    vLastAlert = 4;
    }
    //}}EFSWizard_Action_4

    //}}EFSWizard_Actions


    Thanks
    -Shiva

  • #2
    Shiva
    The alerts being triggered on every bar are due to the fact that none of the conditions used are unique while the events (alerts, etc) are set to be executed every time the conditions are true.
    Take for example Set1 in which you define the cross down of the Signal line



    This means that all those events will be executed on every bar in which the Signal line is less than the MACD line.
    You have two solutions available to resolve this. The first one is to create a condition that is unique



    Notice how I have now defined the cross of the Signal line by establishing its position at the current and prior bar. In this case the events are to be executed every time the condition is true because that condition will only happen once on every cross
    The other solution is to leave your condition unchanged and instead execute the events only the first time that the condition is true



    Extending the same logic to the other Sets in the Formula Wizard should resolve the problem you are having
    Alex

    Comment


    • #3
      Shiva
      After you have modified the efs using the Formula Wizard you will need to edit it again with the Editor to add setComputeOnClose() back in because the Formula Wizard will remove it.
      To prevent the Formula Wizard from removing it again in the future instead of adding setComputeOnClose() like this



      add it in the position shown in the next image. The next time you edit and save the efs with the Formula Wizard the command will not be removed.
      Alex

      Comment

      Working...
      X