Announcement

Collapse
No announcement yet.

onComputeonclose or something else??

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

  • onComputeonclose or something else??

    I have a very simple script that when the next bar exceeds the one before it (alert me). Have now beeping but it keeps beeping (would like to stop while the bar is forming and only want to beep once (but as soon as the high (0) >high(-1).

    Dont want to wait til the bar is finished though forming . Also I am putting an arrow above it and would like the arrow to be placed above the high(0) as it is forming and stay there...just trying to get rid of the constant beeping.

    Right now I have the arrow and the beeping. The arrows follows the bar as it is forming (which is good though)

  • #2
    PATRADER
    setComputeOnClose() is not the solution because the alert will not be triggered until the bar is completed.
    What you need to do is create a global variable called for example AlertTriggered and set it initially to false.
    Then at the beginning of function main you create a condition which resets AlertTriggered to false at every new bar.
    PHP Code:
    if(getBarState()==BARSTATE_NEWBAR){
        
    AlertTriggered false;

    Once you have done that you enclose the command that execute the alerts inside a condition that first evaluates if AlertTriggered is set to false and if that is the case executes the command and sets the AlertTriggered flag to true.
    PHP Code:
    //if(your condition==true){
        
    if(AlertTriggered==false){
            
    Alert.playSound(...);
            
    AlertTriggered true;//
        
    }

    This will ensure that only one alert will be triggered for the duration of that bar
    Alex

    Comment


    • #3
      Thanks

      I'll try it tonight. I will see if I can do it. I have 4 scripts that work nicely thanks to esignal and everyone. I have good info by reading older posts. My scripts are easy but very effective.

      If I get it working, I will post for all to read.

      One more thing......I have 4 scripts, can I just merge all into one???

      Comment


      • #4
        PATRADER
        You are most welcome.
        Without having any details about the scripts it is difficult to provide an absolute answer but in general you should be able to merge them
        Alex

        Comment


        • #5
          Here are my scripts for you to see

          Here are the scripts I am working on

          Goal:
          1). To fix audible alarm on ThirdBar script to alert only once while bar is forming (not when finished)
          2). Add all scripts together if possible
          3). Would definitely like to add First, second and last script, since these all add up to make 1 buy signal


          MAIN NOTES:
          I tried for 6 hrs last night to merge all scripts together. I got the first 4 scripts working together (I think) but when I added the last one, when that meets condition, I lost the condition or flag (AGR under the bar next to it). In order words, the first script didn’t work once I added the last one (but did if the script 5 didn’t meet condition).
          I also have tried to do the alert once on the ThirdBar script, but didn’t work. Got to try again tonight. Going to add (to first, second and last script that one bar has to be green (0) bar I think (using close(0)>open(0) for now but may change. I had to delete a few lines in each script (forum said I had too many lines)

          Script One:
          Description:
          Compares 2 bars in row.
          Conditions:
          Has two groups of conditions. If it doesn’t meet first group of conditions (AGR) then it sees if it meets second group of conditions (AGR1).
          First Condition: Compares two bars in a row.
          Second Condition: is similar to first bar except is also compares to the first bar of the day
          This script works well by itself.
          Alerts:
          When second bar is complete it alerts me by an audible alarm and then puts AGR or AGR1 little under second bar.
          Changes:
          No changes to be made to this script
          Notes:
          I used the wizard to get me started then edited the rest in the editor program


          Script two: ThirdBar
          Description:
          Compares 3 bars in row. Exactly like the first script except it adds a third bar that adds different alert and audio. This script actually completes the first script
          Conditions:
          Has two groups of conditions. If it doesn’t meet first group of conditions (AGR) then it sees if it meets second group of conditions (AGR1).
          First Condition: Compares three bars in a row.
          Second Condition: is same as first condition except it compares second bar the first bar of the day
          This script works well by itself.
          Alerts:
          When third is forming it alerts me by an audible alarm and then puts an arrow above the third bar.
          Changes:
          Want the audio to only alarm me once, not every second like it does now. Got info from you, but doesn’t work yet
          Notes:
          I used the wizard to get me started then edited the rest in the editor program. Was going to add this to the firsts script but not sure if it will work. Other script computes on close, this one doesn’t.


          Script three: SCRIPT3
          Description:
          Compares 3 bars in row.
          Conditions:
          Has one group of conditions. This script works well by itself.
          Alerts:
          When third has formed (completed) it alerts me by an audible alarm and then puts a letter under the third bar, arrow on top bar
          Changes:
          None as yet, except add to other scripts
          Notes:
          I used the wizard to get me started then edited the rest in the editor program.


          Script four: SCRIPT4
          Description:
          Compares 3 bars in row.
          Conditions:
          Has one group of conditions. This script works well by itself.
          Alerts:
          When third has formed (completed) it alerts me by an audible alarm and then puts a letter under the third bar, arrow on top bar
          Changes:
          None as yet, except add to other scripts
          Notes:
          I used the wizard to get me started then edited the rest in the editor program.


          Script five: 1%
          Description:
          Basically it is the first script’s conditions but wanted to know if the first bar of the first script is >1% of the first bar, so added one more condition.
          Conditions:
          This script works well by itself.
          Alerts:
          Adds a >1% above the bar it compares to (uses the same 2 main conditions as the first script but compares each main condition to compare to the first bar of the day).
          Changes:
          Would like to add to other scripts – all or first one
          Notes:
          I used the wizard to get me started then edited the rest in the editor program.


          Script One:
          PHP Code:
          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations
          function preMain() {
          setComputeOnClose(true);

          //{{EFSWizard_PreMain
              
          setPriceStudy(true);
              
          setStudyTitle("");
          //}}EFSWizard_PreMain
          }

          function 
          main() {

                
          setComputeOnClose(true);
              var 
          BarTime rawtime(0);
              var 
          BarIndex = (getFirstBarIndexOfDay(BarTime)-getCurrentBarIndex());
              var 
          FirstOpen open(BarIndex);
              var 
          FirstHigh high(BarIndex);
              var 
          FirstClose close(BarIndex);
              var 
          FirstLow low(BarIndex);
              
          //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1 AGR Type Setup bar has to be less than 50% of previous bar
                  
          if (
                      
          Strategy.isLong() == false &&                   //Bar is UP (green)?? does this work, need code here
                      
          high(0) <= high(-1) &&                          
                      
          close(0) >= open(0) &&                           
                      ((
          high(-1) - low(-1)) / 2) > (high(0) - low(0)) 
                  ) 
          onAction1()
              
          //}}EFSWizard_Expression_1
              
              //{{EFSWizard_Expression_2 AGR1 Type Setup Bar has to be less than 50% of First Bar of day 
                  
          else if (
                      
          Strategy.isLong() == false &&                       
                      
          high(0) <= high(-1) &&                              
                      
          close(0) >= open(0) && 
                      ((
          FirstHigh FirstLow) / 2) > (high(0) - low(0))   
                  ) 
          onAction2()
              
          //}}EFSWizard_Expression_2
              
          //}}EFSWizard_Expressions


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

          }

          function 
          postMain() {
           
          }

          //{{EFSWizard_Actions
              //{{EFSWizard_Action_1  Writes AGR to alert trader script has setup
              
          function onAction1() {
                  
          drawTextRelative(0low()-.005"AGR"Color.RGB(255,255,0), Color.RGB(0,0,0), Text.FRAME"Arial"8);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\l10setup.wav");
                  
          vLastAlert 1;
              }
              
          //}}EFSWizard_Action_1
              
              //{{EFSWizard_Action_2  Writes AGR1 to alert trader script has setup
              
          function onAction2() {
                  
          drawTextRelative(0low()-.005"AGR1"Color.RGB(255,255,0), Color.RGB(0,0,0), Text.FRAME"Arial"8);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\l10setup.wav");
                  
          vLastAlert 2;
              }
              
          //}}EFSWizard_Action_2
              //This script must use another script, as the final buy signal
              
          //}}EFSWizard_Actions 
          Script two: ThirdBar
          PHP Code:
          // Third Bar (uses same script except for last bar logic (0)
          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations


          function preMain() {

          //{{EFSWizard_PreMain
              
          setPriceStudy(true);
              
          setStudyTitle("");
          //}}EFSWizard_PreMain
          }

          function 
          main() {

               
          //Following is for AGR1 to compare to First Bar of the day
              
          var BarTime rawtime(0);
              var 
          BarIndex = (getFirstBarIndexOfDay(BarTime)-getCurrentBarIndex());
              var 
          FirstOpen open(BarIndex);
              var 
          FirstHigh high(BarIndex);
              var 
          FirstClose close(BarIndex);
              var 
          FirstLow low(BarIndex);
                 
          //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1 AGR Type Setup bar has to be less than 50% of previous bar
                  
          if (
                      
          Strategy.isLong() == false &&
                      
          high(-1) <= high(-2) &&
                      
          close(-1) > open(-1) &&
                      
          high(0) > high(-1) &&
                      
          close(0) > open(0) &&
                      
          low(0) >= low(-1) &&
                      ((
          high(-2) - low(-2)) / 2) > (high(-1) - low(-1))
                      ) 
          onAction1()
              
          //}}EFSWizard_Expression_1
              
              //{{EFSWizard_Expression_2 AGR1 Type SetUp Bar has to be less than 50% of First Bar of day (9:30)
                  
          else if (
                      
          Strategy.isLong() == false &&
                      
          high(-1) <= high(-2) &&
                      
          close(-1) > open(-1) &&
                      
          high(0) > high(-1) &&
                      
          close(0) > open(0) &&
                      
          low(0) >= low(-1) &&
                      ((
          FirstHigh FirstLow) / 2) > (high(-1) - low(-1))
                  ) 
          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..... As soon as bar is in (Breaks previous bar, then system alerts by audio and yellow flag above bar
              
          function onAction1() {
                  
          drawShapeRelative(0high()+.010Shape.RIGHTARROW""Color.RGB(255,255,0), Shape.TOP);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\l10buy.wav");
                  
          vLastAlert 1;
              }
              
          //}}EFSWizard_Action_1
              
              //{{EFSWizard_Action_2.... As soon as bar is in (Breaks previous bar, then system alerts by audio and yellow flag above bar
              
          function onAction2() {
                  
          drawShapeRelative(0high()+.010Shape.RIGHTARROW""Color.RGB(255,255,0), Shape.TOP);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\l10buy.wav");
                  
          vLastAlert 2;
              }
              
          //}}EFSWizard_Action_2
              
          //}}EFSWizard_Actions 

          SCRIPT3
          PHP Code:
          //}}EFSWizard_Description  SCRIPT3


          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations


          function preMain() {

          //{{EFSWizard_PreMain
              
          setPriceStudy(true);
              
          setStudyTitle("");
          //}}EFSWizard_PreMain

          }

          function 
          main() {
              
          setComputeOnClose(true);

          //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1
                  
          if (
                      
          high(0) >= high(-1) &&
                      
          low(0) <= low(-1) &&
                      
          high(0) < high(-2) &&
                      
          low(0) <= low(-2)-.02 &&
                      
          close(0) <= open(-2)-.02 &&
                      
          close(0) <= close(-2)-.02 &&
                      
          close(0) <= open(-1) &&
                      
          close(0) <= close(-1)
                  ) 
          onAction1();
              
          //}}EFSWizard_Expression_1
              
          //}}EFSWizard_Expressions


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

          }

          function 
          postMain() {
          }

          //{{EFSWizard_Actions
              //{{EFSWizard_Action_1
              
          function onAction1() {
                  
          drawTextRelative(0low()-.005"SCRIPT3"Color.RGB(255,251,240), Color.RGB(0,0,0), Text.FRAME"Arial"10);
                  
          drawShapeRelative(0high(0)+.010Shape.RIGHTARROW""Color.RGB(0,0,0), Shape.TOP);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\123.wav");
                  
          vLastAlert 1;
              }
              
          //}}EFSWizard_Action_1
              
          //}}EFSWizard_Actions 

          SCRIPT4
          PHP Code:
          //{{EFSWizard_Description SCRIPT4
          //
          //}}EFSWizard_Description


          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations


          function preMain() {

          //{{EFSWizard_PreMain
              
          setPriceStudy(true);
              
          setStudyTitle("");
          //}}EFSWizard_PreMain

          }

          function 
          main() {
              
          setComputeOnClose(true);

          //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1
                  
          if (
                      
          high(0) >= high(-1) &&
                      
          low(-1) >= low(0) &&
                      
          close(0) > close(-2) &&
                      
          close(0) > open(-2) &&
                      
          low(0) > low(-2) &&
                      
          low(-1) > low(-2) &&
                      
          high(-1) > high(-2)
                  ) 
          onAction1();
              
          //}}EFSWizard_Expression_1
              
          //}}EFSWizard_Expressions


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

          }

          function 
          postMain() {

          }

          //{{EFSWizard_Actions
              //{{EFSWizard_Action_1
              
          function onAction1() {
                  
          drawTextRelative(0low()-.005"SCRIPT4"Color.RGB(255,0,0), Color.RGB(255,255,255), Text.FRAME"Arial"8);
                  
          drawShapeRelative(0high(0)+.010Shape.RIGHTARROW""Color.RGB(255,251,240), Shape.TOP);
                  
          Alert.playSound("C:\\Program Files\\eSignal\\Sounds\\script4.wav");
                  
          vLastAlert 1;
              }
              
          //}}EFSWizard_Action_1
              
          //}}EFSWizard_Actions 

          1%SCRIPT
          PHP Code:
          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations

          function preMain() {
          setComputeOnClose(true);

          //{{EFSWizard_PreMain
              
          setPriceStudy(true);
              
          setStudyTitle("");
          //}}EFSWizard_PreMain
          }

          function 
          main() {
                
          setComputeOnClose(true);
              var 
          BarTime rawtime(0);
              var 
          BarIndex = (getFirstBarIndexOfDay(BarTime)-getCurrentBarIndex());
              var 
          FirstOpen open(BarIndex);
              var 
          FirstHigh high(BarIndex);
              var 
          FirstClose close(BarIndex);
              var 
          FirstLow low(BarIndex);
              
          //{{EFSWizard_Expressions
              //{{EFSWizard_Expression_1 
                  
          if (
                      
          high(0) <= high(-1) &&                          
                      
          close(0) >= open(0) && 
                      (
          FirstOpen 100) < (high(-1) - low(-1)) &&                
                      ((
          high(-1) - low(-1)) / 2) > (high(0) - low(0)) 
                  ) 
          onAction1()
              
          //}}EFSWizard_Expression_1
              
              //{{EFSWizard_Expression_2
                  
          else if (
                      
          high(0) <= high(-1) &&                             
                      
          close(0) >= open(0) && 
                      (
          FirstOpen 100) < (high(-1) - low(-1)) &&  
                      ((
          FirstHigh FirstLow) / 2) > (high(0) - low(0))    
                  ) 
          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() {
                  
          drawTextRelative(-1high(-1)+.015">1%"Color.RGB(255,255,0), Color.RGB(0,0,0), Text.FRAME"Arial"8);
                  
          vLastAlert 1;
              }
              
          //}}EFSWizard_Action_1    
              
          function onAction2() { 

          Comment


          • #6
            Hello PATRADER,

            If you are still having trouble with the combined script, please post that script using the attachment feature when replying on-line. We need to see that code in order to help you pin point why your combined script is not working according to your design.
            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


            • #7
              Will do

              I'll spend a few hrs and put as many notes and remarks and try it one more time, then send back up for review

              Would be great to get it to work....was up late last night again trying it...I will post it tonight and add appropiate comments so everyone can see if/where I need help....

              Maybe someone else can use it as well....


              One quick question....when you make a simple script, can you add another in it..like:
              Have one whole script, then at the end just add the other, so you would have two mains, two premains, etc..or bad idea...just thinking outloud.......(I'm at work and just looking at the scripts and had a thought)

              Comment


              • #8
                Re: Will do

                Hello PATRADER,

                Originally posted by PATRADER
                ...

                One quick question....when you make a simple script, can you add another in it..like:
                Have one whole script, then at the end just add the other, so you would have two mains, two premains, etc..or bad idea...just thinking outloud.......(I'm at work and just looking at the scripts and had a thought)
                Nope, that won't work as that is improper programming. Each function that you define in a single formula needs to be unique.
                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


                • #9
                  Update

                  I have spent the last week (every day) working on my scripts and checking them, redoing them, checking them etc...I wanted to see how far I could get on my own. I actually learned alot in this last week trying different things. I am at work lately during the day and only able to check the scripts by playing them back or at the nend of the day. I wont be able to trade during the day for another week or two, so i dont get live information and hoping that what I do in the playback is identicle to the actual day

                  I managed to merge the ones together that I wanted, with thanks to this forum. I did go through almost all posts over the last year (took a few hrs a day)

                  A few things I still am not able to do. I'm on my work pc so I will have to upoload the srcipt when I get home but I was not able to use the computeon close and the other code

                  (getBarState()==BARSTATE_NEWBAR){
                  AlertTriggered = false;

                  to work in the same script. My pc doesnt have the script or I would post it now. Expression one works by alerting me on close but the second one (with the other type) doesn't work.

                  They work great though if I run them separate but when combined they dont.

                  Can you run both in the same script??

                  Comment


                  • #10
                    Hello PATRADER,

                    You can use setComputeOnClose() and BARSTATE_NEWBAR in the same script. Although its not necessary to check for BARSTATE_NEWBAR because the setComputeOnClose() function forces the study to only execute at BARSTATE_NEWBAR. Why your script is not performing as you are expecting it to is most likely related to something else that you are doing in the script. You'll need to post the 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


                    • #11
                      Doing Well, but....

                      I am doing well, I have managed so far to get all my scripts working with some very helpful suggestions and support.

                      Now, I have two scripts out of 8. NOt bad for me.

                      I have one script that runs all conditions (several) on compute on close and the other one alerts me every tick (arrow follows bar forming and also alerts me only once, audio as soon as it meets same conditions).

                      Can I take both scripts then and merger them so all three types of alerts will work??

                      All the scripts are almost identical, just a few modifications.

                      Also, I used to do basic HP basic programming in the 80's. Since I have many of the same variables like:
                      close(o) > open(0)
                      close(-1) > close(0) etc...

                      can I assign a variable like

                      var 1 = close(o) > open(0) && close(-1) > close(0)

                      Have yet to try this, I have spent alot, alot of time trying to write, re-write scripts.

                      Then on each condition I can use the var 1 instead of all the code.
                      I am just trying to simplfy things alittle and stay cleaner in the code.

                      Thanks

                      Comment


                      • #12
                        Hello PATRADER,

                        Can I take both scripts then and merger them so all three types of alerts will work??
                        You can, however, you will have to rewrite the logic for the conditions in the formula that is using setComputeOnClose() to look for BARSTATE_NEWBAR and check the conditions against the values on bar -1. This will allow you to maintain the 'compute on close' behavior for those conditions while the other tick-by-tick conditions continue to evaluate on every tick.

                        can I assign a variable like
                        var 1 = close(o) > open(0) && close(-1) > close(0)
                        Yes you can, however, the variable name cannot be or start with a number. Try something like var myVar = ... Then you can use that variable directly in your conditions like below.

                        PHP Code:
                        if(myVar){//to evaluate if the condition is true
                        //or
                        if(!myVar){//to evaluate if the condition is false 
                        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

                        Working...
                        X