Hi, I've attached an MC.Net supplied study that I'd like to modify so it fires an alert on an exact number of consecutive bar closes down. Currently it fires on the exact number but then continues to fire alerts on subsequent consecutive bars if they close lower (so 3,4,5 etc.) Can the study be modified to fire the alert on the set number then stop until reset by an equal or higher close?
I've been looking at the consolidation period idea JoshM kindly offered previously but it seems to me in this study the script may be able to reference the actual price action.
Thanks for any help. Cheers.
Limit consecutive bars down to exact number. [SOLVED]
Limit consecutive bars down to exact number.
- Attachments
-
- Consecutive_Downs.pln
- (1.25 KiB) Downloaded 467 times
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: Limit consecutive bars down to exact number. [SOLVED]
You can use a variable that's toggled when the alert has been generated already, and that's then turned off so that subsequent alerts cannot be triggered (unless this variable is reset again).Can the study be modified to fire the alert on the set number then stop until reset by an equal or higher close?
For example:
Code: Select all
private bool alertTriggered;
protected override void StartCalc()
{
// Reset variable each time the script (re)calculates anew
alertTriggered = false;
}
protected override void CalcBar()
{
int consecLowers = 3;
// Trigger an alert when a certain number of consecutive lower
// closes is reached
if (!alertTriggered && consecLowers == 3)
{
Alerts.Alert("Alert message");
// 'Flip' Boolean variable to prevent the alert from
// generating again
alertTriggered = true;
}
// Reset the Boolean variable so that
// alerts can be generated again
if (Bars.Close[0] >= Bars.Close[1])
alertTriggered = false;
}