Thanks.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Count number of bars back for swing high
Collapse
X
-
Hello brucelevy,
You could use Max to quickly find the maximum number of bars back the last Swing High took place. Here is the Swing Help Guide and the Maximum (MAX) Help Guide to assist you further.
Here is an example that prints the number of bars back the last Swing High to the output window.
Code:[COLOR=#000000][FONT=Tahoma][LEFT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/SIZE] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT][/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][/LEFT] [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Swing([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]).SwingHigh[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] >=[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/LEFT] [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] {[/SIZE][/FONT][/LEFT] [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] Print([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"It has been "[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]+ MAX(Swing([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]).SwingHigh,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]14[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] +[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]" bars since the last Swing High"[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/LEFT] [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] } [/SIZE][/FONT][/LEFT] [/FONT][/COLOR][COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] }[/SIZE][/FONT][/LEFT] [/FONT][/COLOR]
[/FONT][/COLOR]Shawn B.NinjaTrader Customer Service
-
Originally posted by brucelevy View PostHow can I print the number of bars back a prior swing high took place?
Thanks.
ref: http://ninjatrader.com/support/helpGuides/nt7/swing.htm
In fact, it is the very first method signature listed.
Comment
-
Thanks, it is now showing how many bars back the swing occurred but I am now trying to find out how many bars ago price crossed and closed above that swing?
if(Swing( 5).SwingHigh[ 0] >= 5)
{
Draw.TextFixed(this, "Prior Swing High", "Bars since swing high: "+Swing(5 ).SwingHighBar(0,1, 200), TextPosition.TopRight);
}
Comment
-
Hello brucelevy,
You can use GetBar() to return the number of bars ago the price crossed and closed above the swing.
Here is the GetBar() Help Guide to assist you further.
Here is an example using GetBar().
Code:[LEFT] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]protected[/SIZE] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]override[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]void[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]OnBarUpdate[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]()[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] {[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] [/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]if[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]CrossAbove[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Close[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2],[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Swing[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]5[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]).[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]SwingHighBar[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]0[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2],[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]1[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2],[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]200[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]),[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]5[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]) &&[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Close[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]0[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]] >=[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Swing[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]5[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]).[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]SwingHigh[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2][[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]0[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]])[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] {[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] [/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]int[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]startTime[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]=[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]ToTime[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Time[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2][[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#22CDFF]0[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]]);[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] [/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]int[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]barsAgo[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]=[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]CurrentBar[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]-[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Bars[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2].[/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]GetBar[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#ADD8E6]new[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]DateTime[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]startTime[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]));[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] [/SIZE][/FONT] [FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]Print[/COLOR][/SIZE][/FONT][FONT=Times New Roman][SIZE=2]([/SIZE][/FONT][FONT=Times New Roman][SIZE=2][COLOR=#F0F0F0]barsAgo[/COLOR][/SIZE][/FONT] [FONT=Times New Roman][SIZE=2]);[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] }[/SIZE][/FONT] [FONT=Times New Roman][SIZE=2] }[/SIZE][/FONT]
Shawn B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by strategist007, Today, 07:51 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,967 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
6 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
Comment