Announcement

Collapse
No announcement yet.

Alert EFS

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

  • Alert EFS

    Hi,

    I'm trying to integrate an alert pop-up to an EFS study, at the moment I receive multiple alerts on the same bar once a condition is met. Is there a way to restrict the alert to once per bar? I would also like to display the current last price in the pop up when the alert is fired.

    Thanks,
    Eyal

    I'm using this code:

    function onAction1() {
    drawShapeRelative(0, low(), Shape.CIRCLE, "", Color.RGB(255,255,255), Shape.LEFT);
    Alert.playSound("ding.wav");
    Alert.addToList(getSymbol()+" "+high()+" "+getInterval(), "Buy Alert", Color.black, Color.red);
    vLastAlert = 1;
    }

  • #2
    Eyal
    You need to create a Global Variable (ie outside of main()) called for example vFlag and set it to 0. Then at the top of main() add a condition that resets vFlag = 0 on every new bar.
    Then in the conditions for the alert you check that vFlag==0 and lastly you add vFlag=1 as the last action of the function onAction1() you posted.
    Alex

    Comment


    • #3
      Hi Alex,

      Wouldn't that work only for SetComputeOnClose? My EFS is calculated on tick basis and I am using code originally created using the wizard. I have 3 functions: pre, main, post as seen below. Btw, how do I display the last price during the alert trigger instead of the high that's coded there now?

      var studies....;
      var vFlag = 0;

      //}}EFSWizard_Declarations 21390


      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("");
      //}}EFSWizard_PreMain 5650
      vFlag = 0;
      }

      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 (
      --- Conditions ---
      ) onAction1();
      vFlag = 0;
      //}}EFSWizard_Expression_1 35843

      //}}EFSWizard_Expressions 50782


      //{{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() {
      drawShapeRelative(0, low(), Shape.CIRCLE, "", Color.RGB(255,255,255), Shape.LEFT);
      if ( vFlag == 0 ) {
      Alert.playSound("ding.wav");
      Alert.addToList(getSymbol()+" "+high()+" "+getInterval(), "Buy Alert", Color.black, Color.red);
      vFlag = 1; }
      }
      //}}EFSWizard_Action_1 32304

      //}}EFSWizard_Actions 44901

      Comment


      • #4
        Eyal
        The suggestions I provided are for triggering alerts in real time.
        In the attached sample alert.efs the alert will trigger in real time once per bar on every bar in which the condition is true.
        To display the last price replace high() with close() in your efs
        Alex
        Attached Files

        Comment


        • #5
          Works great. Thank you very much Alex.

          Comment

          Working...
          X