I am new to Ninja scripting. Appreciate if someone Can share thoughts on below
I am working on an indicator that evaluates a condition on the bar that just closed and sends an email alert message.
Example: Send an alert if open and close of previous bar is below 50% of its range.
Protected override void Initialize()
{
Overlay= false;
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
double RangeBar = High[0] - Low[0] ;
double range_pct = (0.50 * RangeBar) + Low[0];
if (range_pct > Close[0] && range_pct > Open[0])
{
Print(Time[0] + "----" + "Called Email Method in Range_PCt section");
DrawArrowDown();
SendMail();
}
}
I tested this in market replay connection. When above logic is implemented, it prints out alerts multiple times for the previous bar. I believe for each incoming tick, its evaluating condition to true on the previous bar . Is it correct to write above logic in onBarUpdate method ? is there a another method or a better way to implement above logic. Please advise !
Thanks,
Nag
Comment