Announcement

Collapse
No announcement yet.

Need help writing simple formula

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

  • Need help writing simple formula

    I would like a signal for a three bar setup as follows:

    0 = Current bar
    -1 = One bar left of current bar
    -2 = One bar left of -1 bar

    Close (-2) < Open (-2)
    Close (-1) < Open (-1)
    Close (-1) < Close (-2)
    Open (-1) < Open (-2)
    Close ( 0) > Open ( 0)
    Low ( 0) <= Low (-1)
    Open ( 0) < Close (-1)
    Close ( 0) > Open (-1)

    Or

    Close (-2) > Open (-2)
    Close (-1) > Open (-1)
    Close (-1) > Close (-2)
    Open (-1) > Open (-2)
    Close ( 0) < Open ( 0)
    High ( 0) >= High (-1)
    Open ( 0) > Close (-1)
    Close ( 0) < Open (-1)

    I would like an audible sound (phone ring) and a white arrow above and/or below the signal bar.

    Can someone help me please?

    Thank you.

  • #2
    Wavethree3
    Have you considered writing the efs using the Formula Wizard? This tool makes programming scripts such as this one a very easy task. Here below is how your first set of conditions would be laid out in the Formula Wizard



    You would then select Set2 and insert your second set of conditions. All this can be done simply by pointing and clicking.
    At this point unless you include a way to limit the alerts you will get a continuous series of sound alerts on every tick so long as the condition is true.
    There are several ways around this and most require editing the efs using the Formula Editor. However there is one option that can be implemented directly in the Wizard and that is to verify if getBarState()==BARSTATE_NEWBAR which only occurs at the first tick of a new bar. In this case the conditions will have to all be "shifted" one bar back ie as follows



    Notice how the first condition checks for BARSTATE_NEWBAR and all the other conditions are now one bar back. You would then need to repeat the same process for Set2.
    Give it a try and if you encounter any problems post what you have done and someone will be available to help.
    Alex

    Comment


    • #3
      Testing the formula

      Thank you for your help. I did what you suggested in Formula Wizard. How can I test this formula? These conditions don't happen often.

      Comment


      • #4
        Wavethree3
        I did notice that while putting together the examples. One thing I would do is add a command to paint the background when the alert is triggered. This way you can verify visually if the conditions were triggered in a given symbol/interval. Once you have verified that it did occurr then download the data with the Tick Downloader (see under Tools-> Tick Replay in the main menu) and use Tick Replay to simulate the real time conditions.
        Alex

        Comment


        • #5
          That sounds great. How do I program in a visual like that? Also, when I am loading the formula onto a chart I am getting an error that says that the CLOSE on line 50 is not defined.
          Attached Files

          Comment


          • #6
            Wavethree3
            You would do that using the Formula Wizard (see example below)



            As to the error that is caused by incorrect syntax in Set2 (see image). You typed in High Low Close instead of high, low, close. Try using the point and click feature of the Formula Wizard rather than writing it yourself
            Alex

            Comment


            • #7
              Wavethree3
              You will also need to add the commands to be executed if Set2 is true. Notice that in the section "...then the following will happen everytime" you do not have any commands to be executed. Click on the Add Line button to the right and then in the Function Editor select the appropriate command.
              NOTE: In version 7.8 and 7.9 all the commands are also listed in Actions by mistake. Do not use those commands but only those listed in the Alert and Globals sections
              Alex

              Comment


              • #8
                I noticed that and did that. It seems to work visually very well. I will be waiting for the "ring". I appreciate what you do to help all of us.

                Steve

                Comment


                • #9
                  Steve
                  As to the ring you may get more than one when the conditions return true because of what I explained in an earlier reply. However as I said before there are several solutions available
                  Alex

                  Comment


                  • #10
                    You are EXACTLY right on the ring occuring on every tic. You mentioned on a previous thread,

                    "There are several ways around this and most require editing the efs using the Formula Editor. However there is one option that can be implemented directly in the Wizard and that is to verify if getBarState()==BARSTATE_NEWBAR which only occurs at the first tick of a new bar."

                    Before I change the formula and reload it back into my charts, may I get clarification on what exactly will happen?

                    Are you saying that if I make the insertion you suggest that it will COMPLETE the bar that meets the conditions AND THEN on the first tic of the NEXT bar it will RING ONCE? That would be acceptable to me if that is what you mean.

                    Ideally, I would like the ring on the bar only on the first tic the conditions are met and then know more. For example, if it meets the conditions it will ring once. If it stops meeting the conditions and then meets them again, it will ring once again, all on the same bar.

                    Comment


                    • #11
                      Steve

                      Are you saying that if I make the insertion you suggest that it will COMPLETE the bar that meets the conditions AND THEN on the first tic of the NEXT bar it will RING ONCE?

                      That is correct. It will wait for the first tick of a new bar and then verify the conditions. Note that if you set it up to work this way you need to modify the bar indexes as shown in a prior example ie what is now high(-1) needs to be changed to high(-2) etc.
                      FWIW given that your conditions evaluate if the close on the current bar is <> than the open this solution would be IMHO the most appropriate because you would wait for the bar to be completed.

                      ...if it meets the conditions it will ring once. If it stops meeting the conditions and then meets them again, it will ring once again, all on the same bar.

                      This is not as simple to implement and you would not be able to write it using the Formula Wizard alone. You would need to add some logic using the Formula Editor at which point you will no longer be able to edit the efs with the Formula Wizard
                      Alex

                      Comment

                      Working...
                      X