Announcement

Collapse
No announcement yet.

Alerting on 2 bars

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

  • Alerting on 2 bars

    The following efs is designed to alert intra-bar once when the criteria is met, which it does. It also alerts at the open of the next bar which it is not supposed when the criteria is not met. What did I miss in the code?

    PHP Code:
    var vPlaySoundb "C:\\Program Files\\eSignal\\Sounds\\spbuy.wav";
    var 
    vPlaySoundr "C:\\Program Files\\eSignal\\Sounds\\spsell.wav";
    var 
    fpArray = new Array(); 
    var 
    vFlag;
     



    function 
    preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Buy Seller program");
        
    setShowTitleParameters(false)


    var 
    x;

    x=0
       
    fpArray[x] = new FunctionParameter("Buyp"FunctionParameter.NUMBER); 
       
    with(fpArray[x]){       
          
    setDefault(""); 
       } 
       
    x++; 
       
    fpArray[x] = new FunctionParameter("Sellp"FunctionParameter.NUMBER); 
       
    with(fpArray[x]){ 
          
    setDefault(""); 
       } 
       
    fpArray[x] = new FunctionParameter"bSound"FunctionParameter.STRING);
      
    with(fpArray[x]){ 
        
    setName("Play Sound");
        
    addOption("true");
        
    addOption("false");
        
    setDefault("true");
        } 
        
    fpArray[x] = new FunctionParameter"sSound"FunctionParameter.STRING);
      
    with(fpArray[x]){ 
        
    setName("Play Sound");
        
    addOption("true");
        
    addOption("false");
        
    setDefault("true");
        } 
        
    fpArray[x] = new FunctionParameter("uC"FunctionParameter.COLOR);
      
    with(fpArray[x]){ 
        
    setName("Buy Text Color");
        
    setDefault(Color.green);
        } 
      
    fpArray[x] = new FunctionParameter("dC"FunctionParameter.COLOR);
      
    with(fpArray[x]){ 
        
    setName("Sell Text Color");
        
    setDefault(Color.red);
        } 
      
    }    


    var 
    Cond1;
    var 
    Cond2
    var 
    uColor;
    var 
    dColor;

    function 
    main(BuypSellpbSoundsSounduCdC) {
       
      if (
    getCurrentBarIndex() == && getBarState() == BARSTATE_NEWBAR)
            
    vFlag false;

       
    uColor uC;
       
    dColor dC;
       
       
       var 
    Cond1 high(0sym("EPREM A0") ); 
     
       var 
    Cond2 low(0sym("EPREM A0") );
        

    if((
    getHour()*100)+getMinute() > 930 && (getHour()*100)+getMinute() < 1600){

    if(
    Cond1 Buyp && vFlag == false){
     
    //drawTextRelative(0, low()-1, "PB", Color.green, Color.RGB(0,0,0), Text.BOTTOM | Text.CENTER, "Arial", 10);
      
    drawText"B"BottomRow1uColorText.BOTTOM Text.CENTER );
      if(
    bSound == "true") {Alert.playSound(vPlaySoundb)};
      
    vFlag true;
    }

    if(
    Cond2 Sellp && vFlag == false){
      
    drawText"S"TopRow1dColorText.ONTOP Text.CENTER ); 
      if(
    sSound == "true") {Alert.playSound(vPlaySoundr)};
      
    vFlag true;
    //drawTextRelative(0, high()+1, "PS", Color.red, Color.RGB(0,0,0), Text.TOP | Text.CENTER, "Arial", 10);
    }
    }

    Last edited by FibbGann; 11-28-2006, 06:07 PM.
    Excellent book on JavaScript for beginners

  • #2
    Hi Dan,

    There are some other issues with defining local variables within the efs on a newbar (even though you have defined globals of the same name outside main...) and your associated logic therein.

    Also, you are not incrementing x consistently...

    var x = 0;
    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x]){
    ...
    }

    x++;
    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x]){
    ...
    }

    x++;
    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x]){
    ...
    }


    An alternative method that I use is...

    var x = 0;
    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x++]){
    ...
    }

    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x++]){
    ...
    }

    fpArray[x] = new FunctionParameter(...);
    with(fpArray[x++]){
    ...
    }


    I hope this helps a bit...

    Comment


    • #3
      Hello Dan,

      What is the chart symbol you're running this formula on? Also, what values are you entering in Edit Studies for the Buyp and Sellp parameters?
      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


      • #4
        JasonK,

        I usually run this on a 60s or 180s ES #f chart. The Buyp and Sellp change daily.

        Todays numbers are :

        Buyp = 3.53
        Sellp = 1.29
        Excellent book on JavaScript for beginners

        Comment


        • #5
          Hello Dan,

          The way your code logic is currently written, an alert will be triggered on any bar where the EPREM is above Buyp or below Sellp. Because you are resetting vFlag to false at newbar, the alert conditions will be reevaluated and triggered again at the open of a bar if either of the conditions are still true. If at the open, neither of the conditions evaluate to true, no alert will be triggered.

          One thing you can do that will help you visualize this is by returning the values of Cond1 and Cond2 as strings so that you can see them in the cursor window. Also, you could add some debugPrintln() statements inside your conditions for the audio alerts and print out the values of your variables.

          If you do not want the alert to be triggered on consecutive bars, then you'll need to add some additional logic that prevents vFlag from being reset to false on each bar. You could incorporate a global counter that increments at newbar and then add to your conditions a check for a certain number. Inside the conditions you would then reset the counter to 0. If the new condition is looking for a value of 2 for the counter and false for vFlag, then the alert conditions will only be evaluated every 2 bars. Hope this helps.
          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


          • #6
            JasonK,

            If I am reading your quoted statement from the previous thread correctly?

            The way your code logic is currently written, an alert will be triggered on any bar where the EPREM is above Buyp or below Sellp. Because you are resetting vFlag to false at newbar, the alert conditions will be reevaluated and triggered again at the open of a bar if either of the conditions are still true. If at the open, neither of the conditions evaluate to true, no alert will be triggered.
            I should get one trigger per bar if either of my conditional "if" statements are true. When the new bar opens I should not get a trigger if neither of the statements are true. If I read this correctly that is not happening. If I get a trigger say on the current bar, when the next bar opens I get another trigger even if both statements are false. This only happens in real-time and not in bar replay or tick replay. Please advise me if I misunderstood the quoted statement.
            Last edited by FibbGann; 12-14-2006, 06:56 PM.
            Excellent book on JavaScript for beginners

            Comment


            • #7
              Hello Dan,

              What are the current values of Buyp and Sellp that you are using?
              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


              • #8
                For today it is...

                buyp = 13.39
                sellp = 11.19

                You can lower them to get the triggers if needed as you can see on the eprem A0.
                Excellent book on JavaScript for beginners

                Comment


                • #9
                  Hello Dan,

                  Originally posted by FibbGann
                  If I get a trigger say on the current bar, when the next bar opens I get another trigger even if both statements are false. This only happens in real-time and not in bar replay or tick replay. Please advise me if I misunderstood the quoted statement.
                  I've been testing your code again today and I'm not seeing the behavior you're describing. The code is doing was it is supposed to as far as I can see. When both conditions are false I'm not receiving an alert. Only when one of the conditions evaluates to true does an alert occur. To verify what the values are that the condition is based on, place the following debugPrintln() statements inside each of the conditions. The only time these alerts occur is when one of these conditions evaluate to true.



                  If this doesn't clear things up for you, let's try a different angle. I think the problem may be that you have different expectations as to what this code is supposed to do. When you receive an alert on a bar where you think the conditions are both false, please describe for me why you think they should have evaluated to false. We may need to add some other condition or change some of the logic around perhaps.
                  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