Announcement

Collapse
No announcement yet.

Setup Alert based on result of previous period info

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setup Alert based on result of previous period info

    I am a new to Java, and am currently working on writing an alert, I am looking for any assistance.

    If I am working on a 2 minute timeframe, is it possible to setup a trigger that will tell me, (e.g. Long trade example):

    - 2 - 2 min periods before current, represents Stochastics lines both pointing down
    - 1 - 2 min period before current, represents Stochastics lines crossing up.

    I am looking for the confirmed cross to occur in a completed period, not in an active period, as fluxuations may cause Stochastics to cross during the current period, and then ultimately continue in a down direction.

    Thank you in advance for any assistance

    Royce

  • #2
    Hello Royce,

    Yes, this is possible in EFS.

    The instance in which you would evaluate your trade conditions to look for the confirmed cross would be at BARSTATE_NEWBAR using the getBarState() function.

    PHP Code:
    if (getBarState() == BARSTATE_NEWBAR) {
        
    // execute this code block

    This condition detects the open of the current bar. At that point you could simply look at the previous 2 bars' stochastic values to look for a confirmed cross condition using the Stochastic functions. Pass the respective bar indexes to this function and assign there values to variables to be used in your conditional statements. The last parameter in the function call examples below is the optional bar index parameter.

    PHP Code:
    var nStK_1 stochK(1413, -1);  // one bar ago
    var nStK_2 stochK(1413, -2);  // two bars ago

    var nStD_1 stochD(1413, -1);  // one bar ago
    var nStD_2 stochD(1413, -2);  // two bars ago 
    Your conditional statement might look something like below.

    PHP Code:
    if (nStK_1 nStD_1 && nStK_2 nStD_2) {  // detects cross 
        // your code here

    This should help get you started. As you run into more specific issues during your formula development, please post your formula code.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Thanks Jason for your reply. I have been spending some time on reviewing other users EFS code. As a new user, I have extracted code from other users, applied my logic and am hoping I will get the net results I am looking for.

      Could you confirm that I am on the right track and that what I have written makes sense, your assistance is greatly appreciated.

      I have designed an EFS which will alert me when a 2 min. Stochastics will cross either up or down, before the 1 min Stochastics crosses in the corresponding direction. Using the suggestions you have made, this is what I have come up with.

      In particular, am I using the if(getBarState() under the function main section correctly as it ties into my conditions ?
      Thanks in advance

      Sincerely

      Royce

      var vStK_1 = stockK(14 ,3 ,3, -1, INV(1))
      var vStK_2 = stockK(14 ,3 ,3, -2, INV(1))
      var vStD_1 = stockD(14 ,3 ,3, -1, INV(1))
      var vStD_2 = stockD(14 ,3 ,3, -2, INV(1))
      var vStK2_1 = stockK(14 ,3 ,3, -1, INV(2))
      var vStK2_2 = stockK(14 ,3 ,3, -2, INV(2))
      var vStD2_1 = stockD(14 ,3 ,3, -1, INV(2))
      var vStD2_2 = stockD(14 ,3 ,3, -2, INV(2))

      function main() {

      //To Check a confirmed crossing on the previous bar, we are using the BARSTATE_NEWBAR

      if (getBarState() == BARSTATE_NEWBAR) {
      if (
      vStK_1 < vStK_2 && vStK_1 < vStD_1 && vStK2_1 > vStD2_1 && vStK2_2 < vStD2_2
      ) onAction1()

      else if (
      vStK_1 > vStK_2 && vStK_1 > vStD_1 && vStK2_1 < vStD2_1 && vStK2_2 > vStD2_2
      ) onAction2()
      }

      return null;

      }

      Comment


      • #4
        Hello Royce,

        You're most welcome.

        Here's a couple comments regarding your current code that should help you move further along in your process of learning EFS.

        1 - The way you are using the vStk_# variables by assigning values from the Stochastic series needs to be performed inside main() in the local scope. On each execution of the formula these variables need to be updated (at least at the new bar state). Declaring them in the global scope (i.e. outside of main() ) would set them to a single value only once and would not get updated on subsequent bars. Move these declarations inside main() near the top of the function.

        2 - The second issue you need to address is the syntax for the Stochastic functions. They are currently misspelled. If you run the formula as is, you will receive a formula error stating that "stockK" is not defined. On a side note, when you are in the development process, you should have the formula output window open (Tools-->EFS-->Forumula Output Window) to view this information and debugging information that you may be printing using the debugPrintln() function. Also while writing code, use the syntax checker in the EFS Editor after you have completed a section of code that you feel is complete. Doing this often will help you correct syntax errors as you go, which will be a bit easier to identify as apposed to waiting until the very end.

        Three things need to be done to correct the syntax for these function calls. First, replace the lower case "k" with an "h."

        stochK( kLength, kSmoothing, dLength [, source | sym() | inv()] [, barIndex] )
        stochD( kLength, kSmoothing, dLength [, source | sym() | inv()] [, barIndex] )


        When referencing external intervals in addition to a specific bar index you need to reverse the order that you currently have for the 4th and 5th parameters. The reference to inv() would be the 4th parameter and the bar index would be the 5th. In the parameter list above the fourth parameter can be a source, which is just another series object, or a call to sym() or inv(). It is a choice of 1 of the 3. The single pipe symbol (i.e. "|" ) means "or."

        Lastly, EFS, is a case sensitive language. Therefore, INV() needs to be all lower case inv().

        Work on making these corrections and test your new formula.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Hi Jason

          Thank you again for your feedback, I have implemented all of your suggestions and am on my way to completing my first functional EFS.

          I have developed the following two additional questions:

          -1- In an if statement, what I mostly see is an if statement where "if your condition meets X and your condition meet Y, then conduct the following action"
          Instead of using and to separate the two conditions, is it possible to create an if statement using both "and" and "or"
          e.g. "if you condition meet X or meets X1 and your condition meets Y, then conduct the following action".
          If this is possible, if you can let me know how to incorporate it into my formula, that would be very helpful.

          -2- On a Trigger Alert Screen, as soon as I click anywhere on the screen, the trigger alert screen disappears, is it possible to have it so that this always stays on top, so that you can reference the time stamp, or is it possible to export this trigger alert information to a text file for review and testing purposes.

          I look forward to your response

          Royce

          Comment


          • #6
            Hi Jason

            Please ignore the first question regarding "or", I found my answer and will be testing it tomorrow.

            Royce

            Comment


            • #7
              Royce
              To have the Triggered Alert List window always stay on top right click it and check Always on Top
              Alex

              Comment


              • #8
                Thanks Alex

                I am having an issue with how I am coding my logic, I seem to be missing something, can you assist me.

                My goal is to have two conditions met at the same time at the beginning of a new bar on a 1 minute timeframe. Therefore I am using

                if (getBarState() == BARSTATE_NEWBAR) as recommending by Jason, to check to see if my two conditions are true

                Here is the twist, the two conditions are on two different timeframes. The first one is based on a 1 min timeframe and the second condition is based on a 2 minute timeframe.

                I am looking for the condition to be checked at the beginning of each 1 min timeframe. But because one of my conditions are based on a 2 min chart, it seems like the condition on the 2 min is only being checked at the end of the 2 min timeframe = incorrect results.

                Because both conditions can be met when we are at the end of the 1 min condition, and in the middle of the 2 min condition.

                function main() {

                var vStK1_1 = stochK(14 ,3 ,3, inv(1), -1)
                var vStK1_2 = stochK(14 ,3 ,3, inv(1), -2)
                var vStD1_1 = stochD(14 ,3 ,3, inv(1), -1)
                var vStD1_2 = stochD(14 ,3 ,3, inv(1), -2)
                var vStK0_1 = stochK(14 ,3 ,3, inv(2))
                var vStD0_2 = stochK(14 ,3 ,3, inv(2))
                var vStK2_1 = stochK(14 ,3 ,3, inv(2), -1)
                var vStK2_2 = stochK(14 ,3 ,3, inv(2), -2)

                if (getBarState() == BARSTATE_NEWBAR) {
                if (vStK1_1 <= vStK1_2 && vStK0_1 > vStD0_2 && vStK2_1 < vStD2_1){
                Alert.addToList(getSymbol()+" "+getInterval(), "Enter Short Position", Color.RGB(0,0,0), Color.RGB(195,0,0));
                Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
                setChartBG(Color.RGB(254,233,233));
                }

                Comment


                • #9
                  Royce
                  As it is currently written your conditional statement will return an error because the variable vStD2_1 has not been declared and assigned a value.
                  Also the condition vStK0_1 > vStD0_2 will never evaluate to true because vStK0_1 and vStD0_2 have been assigned the same value when declared
                  Alex

                  Comment


                  • #10
                    Thanks Alex

                    I had too many typo's in my last post.

                    Is it possible to compare two conditions based on a 1 minute timeframe, even if one of the conditions is based on a 2 minute period.

                    Or can I get Stochastics data points intra-bar, or intra-period?

                    Royce

                    Comment


                    • #11
                      Royce
                      It is possible to base the conditions on multiple intervals. However to ensure that the signals will be the same in real time and on historical data you need to evaluate the conditions on completed bars for the highest interval used in the conditions. For more on this topic see this thread.
                      Alex

                      Comment


                      • #12
                        Thanks Alex

                        Makes sense, I will use this information and attempt to find a different way to accomplish the goal I am after.

                        I have another question:

                        In the Triggered Alert List, when an alert is triggered and an entry shows up in the list, is there a way to have the price of the stock show up in the window when the alert fires.

                        Thanks again for all of your assistance

                        Royce

                        Comment


                        • #13
                          Royce
                          You can do that by including close(0) in the description parameter of the Alert.addToList() function as shown in the example enclosed below
                          Alex

                          PHP Code:
                          if(your_condition){
                              
                          Alert.addToList(getSymbol(),"Current price is  "+close(0),Color.black,Color.red);

                          Comment

                          Working...
                          X