Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Count number of bars back for swing high

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Count number of bars back for swing high

    How can I print the number of bars back a prior swing high took place?

    Thanks.

    #2
    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]
    [/LEFT]
    [/FONT][/COLOR]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by brucelevy View Post
      How can I print the number of bars back a prior swing high took place?

      Thanks.
      That is a documented available output directly of the Swing() indicator.

      ref: http://ninjatrader.com/support/helpGuides/nt7/swing.htm

      In fact, it is the very first method signature listed.

      Comment


        #4
        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


          #5
          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]
          [/LEFT][/FONT][/COLOR]
          Shawn B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by frankthearm, Yesterday, 09:08 AM
          14 responses
          47 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by gentlebenthebear, Today, 01:30 AM
          2 responses
          13 views
          0 likes
          Last Post gentlebenthebear  
          Started by Kaledus, Today, 01:29 PM
          2 responses
          9 views
          0 likes
          Last Post Kaledus
          by Kaledus
           
          Started by PaulMohn, Today, 12:36 PM
          2 responses
          17 views
          0 likes
          Last Post PaulMohn  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          2 responses
          56 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Working...
          X