简体   繁体   中英

Using Loop to show two or more indication when conditions will met

I want to create an alert. My indicator should show an alert when the first indicator shows a signal and if the second indicator shows two or more time signals in that time.

My script work fine when i use only to show one time indication

alertcondition(bsignal == true and long == true, title="Buy Signal generated", message="Buy Signal generated")

But i need to show indication every time when the condition is met so i search it on google and use this while loop, but its not working... Error show " Syntax error at input 'true'. "

a = bsignal 
b = long 
while true
    if (a == true) and (b == true)
       alertcondition(true, title="Buy Signal generated", message="Buy Signal generated")
   else
      alertcondition(false)

Please suggest what should i do? Thanks in advance

If you need to trigger an alert in a loop, you should use the alert() function. alertcondition() cannot be called in a local scope.

However, I am not sure if you need a loop. Your script will be executed on each bar and you will have access to historical data. You can check if a condition was true some time ago with the ta.barssince() function. Or you can use the history referencing operator . This way you can check historical data and avoid a loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM