Announcement

Collapse
No announcement yet.

Alert Once per Bar

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

  • Alert Once per Bar

    For a non-Wizard formula, I want an alert to occur only once per bar, the first time the alert condition is met in any bar. For a Wizard formula, with alerts setup in the "happen only the first time" section, the same is accomplished by adding this to the main section:

    if (getBarState() == BARSTATE_NEWBAR) {
    vLastAlert = -1;
    }

    When I add that to a non-Wizard formula, I don't get the same result. A sound alert, for example, plays every time the condition is met, not just once per bar. Tried removing those lines, and still the alert plays every time the condition is met. What do I need to do here?

  • #2
    Hello Lancer,

    You could define a global flag and set to false initially. When your condition is first met, change the flag to true. Your condition needs to look at the flag as well. When the bar state returns BARSTATE_NEWBAR again, change the flag back to false. Try the following.

    PHP Code:
    var vFlag false;

    function 
    main() {
        if (
    getBarState() == BARSTATE_NEWBAR)
            
    vFlag false;
        
        var 
    vData1 5;
        var 
    vData2 1;
        
        if (
    vData1 vData2 && vFlag == false) {
            
    Alert.playSound("train.wav");
            
    vFlag true;
        }
        
        return;

    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