Likewise, I also want to be alerted when the reverse occurs.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Track Where MACD Crossover Occured
Collapse
X
-
Track Where MACD Crossover Occured
Per the attached image below. I want to be alerted whenever a MACD lines crossover occurs below the zero line as seen in the pic below (at point "B") and the last crossover occurred above the zero line (Point A). In other words, I want to be alerted based on the location of the last two MACD crossovers.
Likewise, I also want to be alerted when the reverse occurs.1 PhotoTags: None
-
Hi cryfgg, thanks for writing in. You can use C# boolean variables or counters to keep track of two crossovers e.g.
I omitted the CrossAbove/CrossBelow methods, the documentation for these methods is available in the help guide.Code:private bool flag1 = false; private bool flag1 = false; private int savedBar = -1; OnBarUpdate() { if(!flag1 && <MACD Cross>) { flag1 = true; } if(flag1 && !flag2 && <MACD Cross>) { flag2 = true; savedBar = CurrentBar; Print("Two MACD Signals"); } if(CurrentBar == savedBar+1) { flag1 = false; flag2 = false; savedBar = -1; } }
Kind regards,
-ChrisL
-
Originally posted by NinjaTrader_ChrisL View PostHi cryfgg, thanks for writing in. You can use C# boolean variables or counters to keep track of two crossovers e.g.
I omitted the CrossAbove/CrossBelow methods, the documentation for these methods is available in the help guide.Code:private bool flag1 = false; private bool flag1 = false; private int savedBar = -1; OnBarUpdate() { if(!flag1 && <MACD Cross>) { flag1 = true; } if(flag1 && !flag2 && <MACD Cross>) { flag2 = true; savedBar = CurrentBar; Print("Two MACD Signals"); } if(CurrentBar == savedBar+1) { flag1 = false; flag2 = false; savedBar = -1; } }
Kind regards,
-ChrisL
Wha'ts the function these codes:
!flag1 // checks to see if flag1 is false?
"savedBar = -1;" // ??
if(CurrentBar == savedBar+1) // ????
{
flag1 = false; // To reset the boolean?
flag2 = false; // To reset the boolean?
savedBar = -1; // ????
How do I use counter to track the crossovers?
Lastly, is it possible to save/compare the time on the chart when both crossover occurred?Last edited by cryfgg; 04-20-2022, 12:26 PM.
Comment
-
Hi cryfgg, the savedbar and resetting the flags back to false is just to reset the entire setup once two MACD signals have been found. You can use a counter by setting up a private int value and incrementing it every time the MACD condition is triggered. To save the time when the MACD condition is reached, set up a DateTime variable e.g.
private DateTime savedTime;
OnBarUpdate()
{
if(<MACD Cross>)
{
savedTime = Time[0];
}
}
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
656 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
371 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
579 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment