For loop in live chart


So if i have loop like following in my script:

for( i = 0; i < BarCount; i++ ) 
Signal Statement etc...

When i add this on a chart with live data, does the whole loop run on every bar …or just new bar is checked.

To “find” signals it will have to loop through, i.e., test, each bar. As
you show it it runs/tests each bar.

You can also run a loop on visible bars only:

FirstVisibleBar = Status( "FirstVisibleBar" );
Lastvisiblebar = Status( "LastVisibleBar" );
for( i = Firstvisiblebar, BN = 0; i <= Lastvisiblebar AND i < BarCount; i++

Ok, i understand. I am trying to send an email on trigger of buy/sell signals etc as follows:

if(Buy[i] AND barcomplete[i])

The problem is once a signal comes, it sends an email . But every-time i click anywhere on the chart or anything happens on the chart , it resends the email. Whereas i want it to send email once for every signal. Basically i don’t want it to resend the same signal email again. So basically i want a loop which runs only for the new bar ( live data).

Look for AlertIf and StaticVarSet function in the manual


Don’t do that. You don’t need that loop at all. All you need is LastValue function

if( LastValue( Buy ) ) SendEmail(...);

If you want one alert without repetition use this

AlertIF( Buy, "EMAIL", "A sample alert on "+FullName(), 1 );

And please DO NOT create new topics on same subject. Your topic is here: Best way to send email for signals