Announcement

Collapse
No announcement yet.

$tick Alert

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

  • $tick Alert

    I am trying to make an efs alert for the tick. I have seen others on here but I didn't like them as a separate indicator and didn't know how to change them.

    I thought this would work where each time the $tick reaches either +1000 or -1000 the alert would sound and bar would change color. It would need to reset automatically as well. Can anyone lend a hand?

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


    //{{EFSWizard_Declarations
    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("tick");
    //}}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 (
                (
    01"$tick") >= 1000
            
    onAction1()
        
    //}}EFSWizard_Expression_1
        
        //{{EFSWizard_Expression_2
            
    else if (
                (
    01"$tick") <= 1000
            
    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() {
            
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Buzz.wav");
            
    setBarBgColor(Color.RGB(255,0,0));
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1
        
        //{{EFSWizard_Action_2
        
    function onAction2() {
            
    Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Buzz.wav");
            
    setBarBgColor(Color.RGB(0,255,0));
            
    vLastAlert 2;
        }
        
    //}}EFSWizard_Action_2
        
    //}}EFSWizard_Actions 

  • #2
    What you have should play a sound every time $tick is +-1000. You need to change your if statements to include a check for the value of vLastAlert being -1. If it's not -1 then don't play the sound.

    You also need some way of resetting vLastAlert once a sound is played. You need a couple more if statements that set vLastAlert back to -1 if $tick is under 1000 and vLastAlert = 1. Another if statement if $tick is greater than -1000 and vLastAlert =2.

    So in main before the return line add:
    PHP Code:
    if((01"$tick") < 1000 && vLastAlert == 1)
        
    vLastAlert = -1;

    if((
    01"$tick") > -1000 && vLastAlert == 2)
        
    vLastAlert = -1
    To keep it from playing the sound every time $tick is over the threshold, change your existing if statements to:
    PHP Code:
    if((01"$tick") >= 1000 && vLastAlert == -1
    and
    PHP Code:
    if((01"$tick") <= -1000 && vLastAlert == -1
    Hope this helps.

    Steve

    Comment


    • #3
      This is what I have now and it didn't work when the $tick broke the +1000 mark this afternoon. Any other suggestions or advice would be appreciated.

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


      //{{EFSWizard_Declarations
      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("tick");
      //}}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 (
                  (
      01"$tick") >= 1000
              
      onAction1()
          
      //}}EFSWizard_Expression_1
          
          //{{EFSWizard_Expression_2
              
      else if (
                  (
      01"$tick") <= 1000
              
      onAction2();
          
      //}}EFSWizard_Expression_2
      if((01"$tick") >= 1000 && vLastAlert == -1)

          
      vLastAlert = -1;



      if((
      01"$tick") <= -1000 && vLastAlert == -1)

          
      vLastAlert = -1;
      //}}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() {
              
      Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Buzz.wav");
              
      setBarBgColor(Color.RGB(255,0,0));
              
      vLastAlert 1;
          }
          
      //}}EFSWizard_Action_1
          
          //{{EFSWizard_Action_2
          
      function onAction2() {
              
      Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\Buzz.wav");
              
      setBarBgColor(Color.RGB(0,255,0));
              
      vLastAlert 2;
          }
          
      //}}EFSWizard_Action_2
          
      //}}EFSWizard_Actions 

      Comment


      • #4
        This is what you should have for main().
        PHP Code:
        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 ((01"$tick") >= 1000 && vLastAlert == -1onAction1();
            
        //}}EFSWizard_Expression_1
            
            //{{EFSWizard_Expression_2
                
        else if ((01"$tick") <= 1000 && vLastAlert == -1onAction2();
            
        //}}EFSWizard_Expression_2

            // reset last alert if tick falls back below 1000
            
        if((01"$tick") < 1000 && vLastAlert == 1)
                
        vLastAlert = -1;
                
            
        // reset last alert if tick rises above -1000
            
        if((01"$tick") > -1000 && vLastAlert == 2)
                
        vLastAlert = -1;
        //}}EFSWizard_Expressions


        //{{EFSWizard_Return
            
        return null;
        //}}EFSWizard_Return 
        Cut and paste the above into your efs file.

        I'm not familiar with the (0, 1, "$tick") statement, so that could be part of the problem to. What did you enter as a condition in the wizard that caused it to generate that code?

        Steve

        Comment


        • #5
          Thanks for your help so far but no dice. I have never built an efs and to be honest I can't remember where I got the (0, 1, "$tick") statement.

          The $tick hit +1000 several times yesterday and I never got an alert with the code. If you were to start from scratch what would your code look like?

          Comment


          • #6
            psychtrader,

            Try this code. I tested it using 200 for THRESHOLD and it did generate alarms and color the bars red. If this still doesn't work the way you want, at least its something to start from.

            PHP Code:
            // variable to hold closing value for tick
            var svTick null;

            // the threshold we must cross to sound the alarm. 
            // You can change this to a higher/lower value for test purposes
            const THRESHOLD 1000

            // color constants
            const HIGHCOLOR Color.RGB(255,0,0);
            const 
            LOWCOLOR Color.RGB(0,255,0);

            // sounds to play constants
            const HIGHSOUND "Buzz.wav";
            const 
            LOWSOUND "Buzz.wav";

            // alert constants
            const NONE = -1;
            const 
            HIGH_ALERT 1;
            const 
            LOW_ALERT 2;

            // The alert state, one of the above alert constants
            var vLastAlert NONE;


            function 
            preMain() 
            {
                
            setPriceStudy(true);
                
            setStudyTitle("tick");
                
            setShowCursorLabel(false);  // don't show anything in data window

            // end of preMain

            function main() 
            {
                var 
            vTickNow null;    // used to hold the current tick value
                
                // generate a series of the latest tick values
                
            if(svTick == nullsvTick close(sym("$tick, 1"));
                
                
            // copy latest tick value into a local variable to speed up the script
                
            if(svTick != null)
                    
            vTickNow svTick.getValue(0);
                
                
            // do comparisions of current tick value against alarm conditions
                
            if (vTickNow >= THRESHOLD && vLastAlert == NONEonAction(HIGHSOUNDHIGH_ALERT);  // high value alarm
                
            if (vTickNow <= -THRESHOLD && vLastAlert == NONEonAction(LOWSOUNDLOW_ALERT); // low value alarm

                // reset last alert if tick falls back below threshold
                
            if(vTickNow THRESHOLD && vLastAlert == HIGH_ALERT)
                    
            vLastAlert NONE;
                    
                
            // reset last alert if tick rises above -threshold
                
            if(vTickNow > -THRESHOLD && vLastAlert == LOW_ALERT)
                    
            vLastAlert NONE;
                    
                
            // color bars
                
            if(vTickNow >= THRESHOLD && vLastAlert == HIGH_ALERT)
                    
            setBarBgColor(HIGHCOLOR);
                    
                if(
            vTickNow <= -THRESHOLD && vLastAlert == LOW_ALERT)
                    
            setBarBgColor(LOWCOLOR);

                return 
            null;
            // end of main

            function onAction(soundalert
            {
                
            Alert.playSound(sound);
                
            vLastAlert alert;
            // end of onAction 
            Steve

            Comment


            • #7
              Steve,

              Thanks a ton! I am able to get this to work with your help. I have adjusted the efs to only make the sound as the painting of the whole screen and having it stay up there was too much. I am looking into the functionality of another efs (NearHigh_Low) which will paint the whole background either red or green when the high or low is within a percentage of the high or low of the day. What is nice about that efs is that once the high or low is out of range it turns the background back to gray rather than red or green. I will put the results back here once I am done so others can use it if wanted. Thanks again.

              Comment


              • #8
                i really liked this alert, but it didn't seem to work for low tick readings. Also, i want to set different variables, such as i want low tick alerts to be -990 while high ticks to be 1200. I tried editing it in the efs wizard but it says its not able to access it. I can only do it through the editor, and i unfortunately I don't know the language. I basically want the same thing the other person mentioned, but just have an alert window with the chimes down sound alert for low/high tick readings. Thanks in advance.

                Comment


                • #9
                  franky,

                  The esignal wizard won't be able to edit the code since it wasn't generated by the wizard. As for learning the language, I would suggest picking up some JavaScript books from your local library or view the eSignal JavaScript training videos as a start.

                  You can cut/paste the following code into the efs editor.

                  Modify lines 6 and 7 to set your high and low alert values. These should be the first lines that start with "const". Note that both numbers should be positive. The efs converts the low alert into a negative value for you.

                  Modify lines 14 and 15 to change the sound played. You can have different sounds for high/low alerts if desired.

                  The program should work for low tick readings. You will only get one alert as it breaks above the threshold, and then the tick readings must go back below the threshold to "rearm" the trigger before it will sound again. That's lines 49-55.

                  Steve

                  PHP Code:
                  // variable to hold closing value for tick
                  var svTick null;

                  // the threshold we must cross to sound the alarm. 
                  // You can change this to a higher/lower value for test purposes
                  const HIGH_THRESHOLD 1000;
                  const 
                  LOW_THRESHOLD 1000

                  // color constants
                  const HIGHCOLOR Color.RGB(255,0,0);
                  const 
                  LOWCOLOR Color.RGB(0,255,0);

                  // sounds to play constants
                  const HIGHSOUND "Buzz.wav";
                  const 
                  LOWSOUND "Buzz.wav";

                  // alert constants
                  const NONE = -1;
                  const 
                  HIGH_ALERT 1;
                  const 
                  LOW_ALERT 2;

                  // The alert state, one of the above alert constants
                  var vLastAlert NONE;


                  function 
                  preMain() 
                  {
                      
                  setPriceStudy(true);
                      
                  setStudyTitle("tick");
                      
                  setShowCursorLabel(false);  // don't show anything in data window

                  // end of preMain

                  function main() 
                  {
                      var 
                  vTickNow null;    // used to hold the current tick value
                      
                      // generate a series of the latest tick values
                      
                  if(svTick == nullsvTick close(sym("$tick, 1"));
                      
                      
                  // copy latest tick value into a local variable to speed up the script
                      
                  if(svTick != null)
                          
                  vTickNow svTick.getValue(0);
                      
                      
                  // do comparisions of current tick value against alarm conditions
                      
                  if (vTickNow >= HIGH_THRESHOLD && vLastAlert == NONEonAction(HIGHSOUNDHIGH_ALERT);  // high value alarm
                      
                  if (vTickNow <= -LOW_THRESHOLD && vLastAlert == NONEonAction(LOWSOUNDLOW_ALERT); // low value alarm

                      // reset last alert if tick falls back below threshold
                      
                  if(vTickNow HIGH_THRESHOLD && vLastAlert == HIGH_ALERT)
                          
                  vLastAlert NONE;
                          
                      
                  // reset last alert if tick rises above -threshold
                      
                  if(vTickNow > -LOW_THRESHOLD && vLastAlert == LOW_ALERT)
                          
                  vLastAlert NONE;
                          
                      
                  // color bars
                      
                  if(vTickNow >= HIGH_THRESHOLD && vLastAlert == HIGH_ALERT)
                          
                  setBarBgColor(HIGHCOLOR);
                          
                      if(
                  vTickNow <= -LOW_THRESHOLD && vLastAlert == LOW_ALERT)
                          
                  setBarBgColor(LOWCOLOR);

                      return 
                  null;
                  // end of main

                  function onAction(soundalert
                  {
                      
                  Alert.playSound(sound);
                      
                  vLastAlert alert;
                  // end of onAction 

                  Comment


                  • #10
                    Thanks for the prompt response, but when i look at a bar chart of a tick, it still has some problems with low ticks alerts, for example on 3/02 11:57 pacific(2:57 easter), we got a low tick of ~-990, if i set a low tick alert of -800, it won't show that. If bring it down severly to -500, then i get alot of green bars showing up(showing alert is working).
                    Second questions is for changing the alert sound. if i awnt to change it to chimes down.wav, do i enter the code in the efs editor as chimes down.wav, chimes_down.wav or chimesdown.wav??

                    Lastly, if i right click on a tick chart, i get an option for set alert, can i bypass this efs and set the alert through that? If i do, do i need to redo this every day?
                    Thanks again

                    Comment


                    • #11
                      franky,

                      Don't know what the problem is. It works for me. Here are the lines I used.

                      const HIGH_THRESHOLD = 800;
                      const LOW_THRESHOLD = 800;

                      Notice that the low is a positive number. This made a green background on 3/2/07 at 14:57 EST.

                      For the sound you should have:
                      const HIGHSOUND = "Chime Down.wav";
                      There should be a space between chime and down.

                      Someone else will have to answer your question about the alert using the right click menu.

                      Steve

                      Comment


                      • #12
                        Works fine for me too. I did have to make one change to get the sounds to work.

                        PHP Code:
                        //// sounds to play constants

                        const HIGHSOUND "C:\\Program Files\\eSignal\\Sounds\\Buzz.wav";

                        const 
                        LOWSOUND "C:\\Program Files\\eSignal\\Sounds\\Buzz.wav"
                        I know that when I used the right click to set an alert that yes, when the alert was triggered I had to reset it.
                        Last edited by psychtrader; 03-05-2007, 04:28 AM.

                        Comment


                        • #13
                          psychtrader,

                          You may have to set the entire path to the sound if you don't have the sound path set correctly.

                          To see what your sound path is currently set to, on the top menu, pick Tools->EFS->Settings. The third big button on the dialog box shows where eSignal thinks your sound directory is. Clicking on the button allows you to change the path to your sound directory. You may have to restart eSignal after changing it before it will see the change.

                          Steve

                          Comment


                          • #14
                            Steve,

                            FWIW, there is also a utility function that returns the path that is called getSoundFileRoot(). Instead of hard coding the address, you can use this function to retrieve the information

                            Comment

                            Working...
                            X