When a condition is satisfied, i want the indicator to immediately alert only once within the duration of the Candle.
I try this simple code:
variables: _CurrentBarNumber(Barnumber),_currentBarAlerted(false);
if currentbar<>_currentBarNumber then begin
_CurrentBarNumber=currentBar;
_currentBarAlerted=false;
end;
if ( high>high[1] ) and not _currentBarAlerted then begin
Alert( "Test Alert " );
_currentBarAlerted=true;
end;
But it does not work... it keeps alerting.
I am testing this on 30mins bar and am using the latest beta.
Is this a Multicharts bug or is there something wrong with the code ?
Alerts [SOLVED]
Please try to use this code:
Input :
condition(true),
alert_message("alert");
var : intrabarpersist _is_alerted_on_this_bar(false), intrabarpersist _currentbar(0);
if _currentbar<>currentbar then begin
_is_alerted_on_this_bar=false;
_currentbar=currentbar;
end;
if condition and not _is_alerted_on_this_bar then
begin
alert(alert_message);
_is_alerted_on_this_bar=true;
end;
Input :
condition(true),
alert_message("alert");
var : intrabarpersist _is_alerted_on_this_bar(false), intrabarpersist _currentbar(0);
if _currentbar<>currentbar then begin
_is_alerted_on_this_bar=false;
_currentbar=currentbar;
end;
if condition and not _is_alerted_on_this_bar then
begin
alert(alert_message);
_is_alerted_on_this_bar=true;
end;
Here is a definition of Intrabarpersist taken from TS Help:
"IntrabarPersist (Reserved Word)
A reserved word used when declaring a variable (or array) that indicates that the value of the variable (or array element) can be updated on every tick. By default, the value of a variable or an array element is only updated at the close of each bar.
Examples
Declares the variable Count to an initial value of zero and increments the value of Count every time a tick is received and at the close of each bar..
Variable: IntrabarPersist Count(0);
Count = Count + 1 ;
(Default behavior without IntrabarPersist) Declares the variable Count to an initial value of zero and increments the value of Count at the close of the each bar.
Variable: Count(0);
Count = Count + 1 ;"
"IntrabarPersist (Reserved Word)
A reserved word used when declaring a variable (or array) that indicates that the value of the variable (or array element) can be updated on every tick. By default, the value of a variable or an array element is only updated at the close of each bar.
Examples
Declares the variable Count to an initial value of zero and increments the value of Count every time a tick is received and at the close of each bar..
Variable: IntrabarPersist Count(0);
Count = Count + 1 ;
(Default behavior without IntrabarPersist) Declares the variable Count to an initial value of zero and increments the value of Count at the close of the each bar.
Variable: Count(0);
Count = Count + 1 ;"