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 ageeholdings, Today, 07:43 AM
|
0 responses
10 views
0 likes
|
Last Post
by ageeholdings
Today, 07:43 AM
|
||
Started by pibrew, Today, 06:37 AM
|
0 responses
4 views
0 likes
|
Last Post
by pibrew
Today, 06:37 AM
|
||
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
14 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
9 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
12 views
0 likes
|
Last Post Today, 12:38 AM |
Comment