Limit consecutive bars down to exact number.  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
darob
Posts: 192
Joined: 20 Nov 2014
Has thanked: 52 times
Been thanked: 26 times

Limit consecutive bars down to exact number.

Postby darob » 20 Mar 2016

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.
Attachments
Consecutive_Downs.pln
(1.25 KiB) Downloaded 367 times

User avatar
JoshM
Posts: 2151
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1534 times
Been thanked: 1529 times
Contact:

Re: Limit consecutive bars down to exact number.  [SOLVED]

Postby JoshM » 21 Mar 2016

Can the study be modified to fire the alert on the set number then stop until reset by an equal or higher close?
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).

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;
}

darob
Posts: 192
Joined: 20 Nov 2014
Has thanked: 52 times
Been thanked: 26 times

Re: Limit consecutive bars down to exact number.

Postby darob » 21 Mar 2016

Thanks for another great coding tutorial. Cheers.


Return to “MultiCharts .NET”