Announcement

Collapse
No announcement yet.

Stochastics - multiple timeframes overbought/oversold alerts

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

  • Stochastics - multiple timeframes overbought/oversold alerts

    Here's the code I modified from the EFS wizard for a basic stochastics overbought/oversold alert on one time frame.

    Everytime I receive an alert, the signal is just for the 2 minute time frame when I specifcally wanted a overbought/oversold signal when both 2 and 5 minute charts are in overbought/oversold territory.

    Any help would be greatly appreciated!

    //{{EFSWizard_Description
    //
    // Identifies Stochastic overbought and oversold event with a message to the Alert List.
    //
    //}}EFSWizard_Description 7532


    //{{EFSWizard_Declarations
    var vStoch2 = new StochStudy(8, 3, 3, inv(2));
    var vStoch5 = new StochStudy(8, 3, 3, inv(5));
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    function preMain() {
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("Stochastic Overbought/Oversold");
    //}}EFSWizard_PreMain
    }

    /**
    * 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.
    */
    function main() {
    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    vStoch5.getValue(StochStudy.SLOW) < 20 && vStoch2.getValue(StochStudy.SLOW) < 20
    ) onAction1()
    //}}EFSWizard_Expression_1

    //{{EFSWizard_Expression_2
    else if (
    vStoch5.getValue(StochStudy.SLOW) > 80 && vStoch2.getValue(StochStudy.SLOW) > 80
    ) onAction2();
    //}}EFSWizard_Expression_2

    //}}EFSWizard_Expressions

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

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    if (vLastAlert != 1) Alert.addToList(getSymbol(), "2 & 5 under 20 band", Color.RGB(0,0,0), Color.RGB(0,128,0));
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //{{EFSWizard_Action_2
    function onAction2() {
    if (vLastAlert != 2) Alert.addToList(getSymbol(), "2 & 5 over 80 band", Color.RGB(0,0,0), Color.RGB(128,0,0));
    vLastAlert = 2;
    }
    //}}EFSWizard_Action_2

    //}}EFSWizard_Actions
Working...
X