Announcement

Collapse
No announcement yet.

Multiple Time Frame Question

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

  • Multiple Time Frame Question

    I'm fairly new to EFS2. I'm trying to create an alert based on two criteria (just for purposes of learning):

    A simple hourly stochastic must be rising (K above D);

    A 10 min stochastic must show a cross of K above D.

    In other words, the hourly stochastic act as a longer-term trend indicator, and the 10 minute as the long 'alert signal'. Again, this is merely for learning.

    I've tried to program this using the EFS editor and declaring two instances of the built in Stochastic study, then attempting to specify the interval desired. No luck. I then created two custom stochastics, harcoding the hourly (60) and ten (10) intervals, then creating a new instance of each stochastic in the alert. No success.

    What happened in the first case was that my first rule (K crosses above D on the ten) was recognized and used, but the 60 min rule of 'K greater than D' was ignored. In the second case, I merely received several syntax errors.

    Is there a way to specify interval on the same indicator type (stochastic) for two or more instances within one formula, and to require the alert to return a 'true' condition for more than one interval on the stochastic?

    Thanks for any insights!

  • #2
    ghadley2

    Originally posted by ghadley2
    Is there a way to specify interval on the same indicator type (stochastic) for two or more instances within one formula, and to require the alert to return a 'true' condition for more than one interval on the stochastic?
    Yes there is. Each instance of the Stochastic study needs to be based on the interval you want.



    At that point you can create the conditions using the two studies as shown below



    In the example the condition checks for the current %K of the 60 min Stochastic to be greater than its current %D and for the 10 minute %K to cross over the %D (hence the check for the values at the prior bar ie xxx.getValue(-1))
    You would then need to add a flag to prevent the alert from setting off multiple times when the condition is met and/or to reset the alerts, etc.
    With regards to using multiple time frames to generate signals, alerts, etc you may also want to read this post.
    Alex

    Comment


    • #3
      Thank you very much indeed, Alexis. Problem solved!

      Comment


      • #4
        Last Question

        I guess I'd thought my EFS problem was solved, but I'm missing something here.

        Using Alexis' kind previous post, I wrote the following code to generate a buy signal when a 10 Minute stochastic crosses to the upside, AND a 60 minute shows its K line above its D; and to generate a short signal when the reverse is true. I don't have a 'close position' signal for either, which may be the problem?

        Anyhow, when I run the study against a chart, it simply blanks any bars altogether, or in the case of candlesticks, empties them of color without doing anything else. Ideas? I have the uneasy feeling I'm missing something painfully simple.

        Code follows:

        ============

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


        //{{EFSWizard_Declarations
        var myStochK1 = stochK(14, 3, 3, inv(60));
        var myStochD1 = stochD(14, 3, 3, inv(60));
        var myStochK2 = stochK(14, 3, 3, inv(10));
        var myStochD2 = stochD(14, 3, 3, inv(10));
        var vLastAlert = -1;
        //}}EFSWizard_Declarations


        function preMain() {
        //{{EFSWizard_Code_PreMain_setPriceBarColor
        setColorPriceBars(true);
        //}}EFSWizard_Code_PreMain_setPriceBarColor
        /**
        * 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("Multiple Stochastic");
        //}}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 (
        myStochK1>myStochD1 && myStochK2.getValue(-1)<myStochD2.getValue(-1) && myStochK2>myStochD2
        ) onAction1()
        //}}EFSWizard_Expression_1

        //{{EFSWizard_Expression_2
        else if (
        myStochK1<myStochD1 && myStochK2.getValue(-1)>myStochD2.getValue(-1) && myStochK2<myStochD2
        ) onAction2();
        //}}EFSWizard_Expression_2

        //}}EFSWizard_Expressions


        //{{EFSWizard_Return
        return null;
        //}}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() {
        setPriceBarColor(Color.RGB(0,255,0));
        if (vLastAlert != 1) drawShapeRelative(0, low(), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.BOTTOM);
        vLastAlert = 1;
        }
        //}}EFSWizard_Action_1

        //{{EFSWizard_Action_2
        function onAction2() {
        setPriceBarColor(Color.RGB(255,0,0));
        if (vLastAlert != 2) drawShapeRelative(0, low(), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.LEFT);
        vLastAlert = 2;
        }
        //}}EFSWizard_Action_2

        //}}EFSWizard_Actions

        Comment


        • #5
          ghadley
          Since you are initializing the studies outside of main the series is created then cached as it gets executed only once (*). This means that you cannot access the series directly using its variable name (ie myStochK1 or myStochD1) as that will only return the first value of the series at the time this was initialized but you will either need to call the series using the getSeries() function or retrieve the value using the getValue() method.
          So, the conditions would need to be wriiten as either

          PHP Code:
          if(getSeries(myStochK1)>getSeries(myStochD1) && 
               
          myStochK2.getValue(-1)<myStochD2.getValue(-1) && 
               
          getSeries(myStochK2)>getSeries(myStochD2)) 
          or

          PHP Code:
          if(myStochK1.getValue(0)>myStochD1.getValue(0) && 
               
          myStochK2.getValue(-1)<myStochD2.getValue(-1) && 
               
          myStochK2.getValue(0)>myStochD2.getValue(0)) 
          The easier [but far less efficient] solution which would require no changes in the conditions would be to initialize the studies inside function main
          Regardless of the solution you implement since you are using the script to generate signals based on multiple time frames I would suggest once again that you read the thread I indicated in my prior reply and base your conditions on completed bars for the reasons explained in detail in that thread.
          Alex

          (*) The same would happen if you initialized the series once only inside the main function either at BARSTATE_ALLBARS or using a bInit routine or similar methods

          Comment


          • #6
            There is a link referenced in Alex's note of 1-05-2006. When I click on it I get an 'access forbidden' message. Can this link still be opened?
            Thanks
            shaeffer

            Comment


            • #7
              shaeffer
              I just fixed the link. You should now be able to access the thread
              Alex

              Comment

              Working...
              X