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 Enkidu, Yesterday, 06:40 AM
|
9 responses
36 views
0 likes
|
Last Post
by Enkidu
Yesterday, 01:11 PM
|
||
Started by kezyclaire, 12-01-2023, 09:37 AM
|
3 responses
151 views
0 likes
|
Last Post Today, 07:03 AM | ||
Started by volIQ, Yesterday, 04:28 PM
|
1 response
13 views
0 likes
|
Last Post Today, 06:55 AM | ||
Started by martini, Yesterday, 04:45 PM
|
1 response
10 views
0 likes
|
Last Post Today, 06:45 AM | ||
Started by proptradingshop, 03-21-2024, 09:50 AM
|
5 responses
26 views
0 likes
|
Last Post Today, 05:17 AM |
Comment