Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Condition only applies the first time

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

    Condition only applies the first time

    hello. Excuse my English. I am a novice programmer. I have an indicator that I want to draw the bar a color and play a sound when a condition is given THE FIRST TIME. If I use Calculate.OnPriceChange or Calculate.OnEachTick the drawing and sound repeat constantly. How could I do so that both drawing and sound are only performed the first time the condition is met? thank you.

    #2
    Hello julifro,

    You could use a bool variable for that. On each first tick of the bar you could reset the variable so that each new bar the condition can be checked again. Inside the condition you would toggle the bool so that the condition is not true after the first time it happens.

    private bool myBool;

    Code:
    protected override void OnBarUpdate()
    {​
    if (IsFirstTickOfBar)
        {
            myBool = false;​
        }
        if(myBool == false && Close[0] > Open[0])
        {
             // do the alert
            myBool = true;
        }
    }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    589 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    342 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    555 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X