Announcement

Collapse
No announcement yet.

Everytime, The First Time, and Every Bar

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

  • Everytime, The First Time, and Every Bar

    For a PlaySound alert in Formula Wizard:

    "Everytime" means that the sound plays on every tick that the formula condition is met. If the condition is met for every tick in a 1 min. bar, then the sound will play constantly for the entire minute. If the condition is met constantly for several minute bars, then the sound will play constantly for those several minutes.

    "The first time" means that the sound plays only once on the first tick of the formula condition being met. If the formula has 2 conditions, once the condition of Set1 is met and the sound plays, the sound alert will not play again for a Set1 alert until the condition of Set 2 is first met. So if the Set1 condition is met in one bar, the alert sounds, but will not sound again if the alert condition is met again in the next or future bars (until the Set2 alert is met, then the Set1 alert can trigger again).

    In most cases, I'd say that neither the "Everytime", nor "The first time", are adequate options for sound alerts. What is needed is an option that plays the sound once at the first tick upon the condition being met, for each and every bar that the condition is met. Using the proposed option, the sound does not play constantly, nor does a Set2 alert have to occur after a Set1 alert before the Set1 alert can trigger again.

    The proposed option text in the Wizard might be ". . . while the following will happen only the first time in every bar".

    Pending addition of such an option in the Formula Wizard, what code can be manually entered into a Wizard formula to get the desired behavior for a PlaySound alert?

  • #2
    Hi Lancer,

    You may have to modify the wizard-generated source code in the regular editor to add a check for getBarState() == BARSTATE_NEWBAR and play the sound only then.

    I'll see what we can do about putting this in the next Formula Wizard.

    Thanks!

    Comment


    • #3
      How about some control over what goes into preMain()

      I find the "fill in the blanks type entry system" you have developed for most functions to be quite helpfull for generating correct syntax.

      Maybe a similar idea could be eveloped for the preMain() stuff.

      Comment


      • #4
        Here's a simple example formula. Can you use this to illustrate how a Wizard formula is modified with the getbarstate code?


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


        //{{EFSWizard_Declarations

        var vStoch14_1 = new StochStudy(14, 1, 3);
        var vLastAlert = -1;

        //}}EFSWizard_Declarations 7986


        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(false);
        setStudyTitle("Example; Sound Alert Once Each Bar");
        //}}EFSWizard_PreMain 9369

        }

        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 (
        vStoch14_1.getValue(StochStudy.FAST) <= 10
        ) onAction1()
        //}}EFSWizard_Expression_1 9426

        //{{EFSWizard_Expression_2
        else if (
        vStoch14_1.getValue(StochStudy.FAST) >= 90
        ) onAction2();
        //}}EFSWizard_Expression_2 11134

        //}}EFSWizard_Expressions 40459


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

        }

        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() {
        vLastAlert = 1;
        }
        //}}EFSWizard_Action_1 5589

        //{{EFSWizard_Action_2
        function onAction2() {
        vLastAlert = 2;
        }
        //}}EFSWizard_Action_2 5582

        //}}EFSWizard_Actions 31632

        Comment


        • #5
          //{{EFSWizard_Description
          //
          // This formula was generated by the Alert Wizard
          //
          //}}EFSWizard_Description 7532


          //{{EFSWizard_Declarations

          var vStoch14_1 = new StochStudy(14, 1, 3);
          var vLastAlert = -1;

          //}}EFSWizard_Declarations 7986


          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(false);
          setStudyTitle("Example; Sound Alert Once Each Bar");
          //}}EFSWizard_PreMain 9369

          }

          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.
          */

          if(getBarState==0)
          debugPrintln("New_Bar");

          //{{EFSWizard_Expressions
          //{{EFSWizard_Expression_1
          if (
          vStoch14_1.getValue(StochStudy.FAST) <= 10
          ) onAction1()
          //}}EFSWizard_Expression_1 9426

          //{{EFSWizard_Expression_2
          else if (
          vStoch14_1.getValue(StochStudy.FAST) >= 90
          ) onAction2();
          //}}EFSWizard_Expression_2 11134

          //}}EFSWizard_Expressions 40459


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

          }

          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() {
          vLastAlert = 1;
          }
          //}}EFSWizard_Action_1 5589

          //{{EFSWizard_Action_2
          function onAction2() {
          vLastAlert = 2;
          }
          //}}EFSWizard_Action_2 5582

          //}}EFSWizard_Actions 31632

          Comment


          • #6
            David, can you edit that to include the subject PlaySound section so that it's a working formula? Per ". . . while the following will happen only the first time in every bar". (e.g. AnySound.wav) Thanks.

            Comment


            • #7
              this makes a noise every new bar, you nee formula.dll from the US Futures area installed in c:\winnt for w2k

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


              //{{EFSWizard_Declarations

              var vStoch14_1 = new StochStudy(14, 1, 3);
              var vLastAlert = -1;
              var alert;


              function initializeFormulaAlert() {
              alert = new DLL("FormulaAlert.dll");
              alert.addFunction("alert", DLL.INT, DLL.CDECL, "alert", DLL.STRING, DLL.STRING);
              alert.addFunction("emailAlert", DLL.INT, DLL.CDECL, "emailAlert",
              DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING,
              DLL.STRING, DLL.STRING, DLL.STRING);
              }

              //}}EFSWizard_Declarations 7986


              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(false);
              setStudyTitle("Example; Sound Alert Once Each Bar");
              alertActive = true;
              initializeFormulaAlert();
              //}}EFSWizard_PreMain 9369

              }

              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.
              */

              if (getBarState() == 0) {
              Alert.playSound("swoosh.wav");
              }

              //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1
              if (
              vStoch14_1.getValue(StochStudy.FAST) <= 10
              ) onAction1()
              //}}EFSWizard_Expression_1 9426

              //{{EFSWizard_Expression_2
              else if (
              vStoch14_1.getValue(StochStudy.FAST) >= 90
              ) onAction2();
              //}}EFSWizard_Expression_2 11134

              //}}EFSWizard_Expressions 40459


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

              }

              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() {
              vLastAlert = 1;
              }
              //}}EFSWizard_Action_1 5589

              //{{EFSWizard_Action_2
              function onAction2() {
              vLastAlert = 2;
              }
              //}}EFSWizard_Action_2 5582

              //}}EFSWizard_Actions 31632

              Comment


              • #8
                Copied that Formula Wizard code to filename "PlaySound Alert Test.efs", and saved the FormulaAlert.efs file to system folder WinNT. The Wizard was unable to open the file, and displayed this popup:

                Unable to Parse Formula
                The file 'PlaySound Alert Test.efs' was not recognized by the Formula Wizard. Do you wish to create a new, empty formula instead?"

                What I'm trying to do is open the formula using Formula Wizard and set sounds (Wav1.wav for condition Set1, and Wav2.wav for condition Set2), then test the PlaySound alerts.

                Any ideas?

                Comment


                • #9
                  dloomis, actually Lancer was asking for something slightly different. He wants the sound to play at most once per bar, but have the ability to play the sound multiple times in a row on separate bars for the same Set. (Currently it will only play alternating Set 1, Set 2, Set 1, Set 2).

                  This is the code to do what you need:

                  PHP Code:
                  //{{EFSWizard_Description
                  //
                  // This formula was generated by the Alert Wizard
                  //
                  //}}EFSWizard_Description 7532


                  //{{EFSWizard_Declarations

                  var vStoch14_1 = new StochStudy(1413);
                  var 
                  vLastAlert = -1;

                  //}}EFSWizard_Declarations 7986


                  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(false);
                      
                  setStudyTitle("Example; Sound Alert Once Each Bar");
                  //}}EFSWizard_PreMain 9369

                  }

                  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.
                  */

                      
                  if (getBarState() == BARSTATE_NEWBAR) {
                          
                  vLastAlert = -1;
                      }

                  //{{EFSWizard_Expressions
                      //{{EFSWizard_Expression_1
                          
                  if (
                              
                  vStoch14_1.getValue(StochStudy.FAST) <= 10
                          
                  onAction1()
                      
                  //}}EFSWizard_Expression_1 9426
                      
                      //{{EFSWizard_Expression_2
                          
                  else if (
                              
                  vStoch14_1.getValue(StochStudy.FAST) >= 90
                          
                  onAction2();
                      
                  //}}EFSWizard_Expression_2 11134
                      
                  //}}EFSWizard_Expressions 40459


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

                  }

                  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() {
                          if (
                  vLastAlert != 1Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
                          
                  vLastAlert 1;
                      }
                      
                  //}}EFSWizard_Action_1 17494
                      
                      //{{EFSWizard_Action_2
                      
                  function onAction2() {
                          if (
                  vLastAlert != 2Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Ding.wav");
                          
                  vLastAlert 2;
                      }
                      
                  //}}EFSWizard_Action_2 15868
                      
                  //}}EFSWizard_Actions 50510 
                  This code will also load in the Formula Wizard. The key to editing code outside of the Formula Wizard is to not change the structure of code between the //{{ and //}} brackets. You MAY change individual parameters of functions, etc.. but don't add new function declarations, variable declarations that don't follow the same style.

                  What I've done here is set each sound to play only ONCE, but reset the 'vLastAlert' variable which is used by the wizard to stop a Set's actions from executing twice in a row. The 'vLastAlert' variable is reset on each BARSTATE_NEWBAR at the beginning of the main(). Notice how I put the new code outside of the //{{ and //}} brackets, so that the Formula Wizard can still load it.

                  Let me know if that works for you (the markets are closed right now so I can't test it properly).

                  Comment


                  • #10
                    So for any Wizard formula with PlaySound alerts, to get the alert behavior of once per bar, add these three lines after function main() {, and before the first //{{EFSWizard Expression:

                    if (getBarState() == BARSTATE_NEWBAR) {
                    vLastAlert = -1;
                    }

                    Everything else remains the same.

                    Thanks Dion and David. I'll test with Sunday PM futures.


                    In edit:
                    Before adding the modified code, which section in the Alert Wizard should be used to initially create the alert: ". . . will happen everytime", or ". . . will happen only the first time", or does it matter?
                    Last edited by Lancer; 02-07-2003, 06:54 PM.

                    Comment


                    • #11
                      No need to wait til Sunday when there is the Replay Tool,

                      right click on chart, Tools, Start Repay.

                      Comment


                      • #12
                        lancer:

                        The playSound() function should be under the 'will only happen the first time'.

                        Everything else as you have stated is correct. Let me know if it works out for you.

                        Thanks!

                        Comment


                        • #13
                          All working fine on live data.

                          David, I've never gotten the Replay Tool to work; it always crashes eSignal (even build 544).

                          Comment


                          • #14
                            I just want to confirm this:

                            If I use the formula wizard to write an alert with 2 condition sets,and

                            I use the "first time" feature,

                            The alert will trigger once when the condition set1 occurs, and will not trigger again until after the condition set 2 occurs;

                            thereafter, if condition set 1 occurs again, the alert will trigger again, and so on......

                            In other words, the condition set 2 serves as a reset of the alarm? When condition set 2 occurs, the alarm has now been reset to trigger if and when condition set 1 occurs, and so on.....

                            right???

                            Thanks.............

                            Comment


                            • #15
                              point1pc
                              Not necessarily. Depending on how the formula is written it could also trigger every "first time" the condition in Set1 (or Set2) exists without necessarily having to trigger the other condition.
                              As an example look at the following image.



                              The condition in Set1 is to paint the bar in blue the first time the High goes above the upper envelope. In Set2 instead the condition is to paint the bar in red the first time the Low goes below the lower envelope.
                              As you can see there are multiple red and blue bars that are triggered without having first triggered the other condition.
                              In this example the reset for the condition in Set1 is provided simply by having the High go back under the upper envelope (and viceversa for Set2)
                              Hope this helps
                              Alex
                              Last edited by ACM; 06-28-2003, 03:56 PM.

                              Comment

                              Working...
                              X