Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

2nd Most Recent Occurance

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

    2nd Most Recent Occurance

    I need help writing the condition for when price cross the 2nd most recent swing high or swing low
    from looking around this code by Paul give me the value of the 3 most recent values,
    but how do I write the cross condition ?? for 2nd most instead of most recent ?
    if (CrossAbove(Close,???????????????))
    { EnterLong () };

    Attached Files

    #2
    Hello condorhero,

    CrossAbove / CrossBelow cannot use bars ago values.

    You would need to create a condition that compares the bars the same that CrossAbove / Below does.
    Code:
    if (SeriesA[startBarsAgo] [B]<[/B] SeriesB[startBarsAgo] && SeriesA[endBarsAgo] > SeriesBendBarsAgo])
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello condorhero,

      CrossAbove / CrossBelow cannot use bars ago values.

      You would need to create a condition that compares the bars the same that CrossAbove / Below does.
      Code:
      if (SeriesA[startBarsAgo] [B]<[/B] SeriesB[startBarsAgo] && SeriesA[endBarsAgo] > SeriesBendBarsAgo])
      So using the print method I got
      for example
      if (CurrentBar < 60 )
      return;
      if (mySwing.SwingHigh[0] > 0)
      {
      for (int i=1; i<4;i++)
      {if (mySwing.SwingHighBar(0, i, 30)> -1)
      {
      myswingHighBarsAgo = mySwing.SwingHighBar(0, i, 30);
      Print (Time[0]+"Instance # "+i+"bars ago:"+myswingHighBarsAgo+"High was:"+High[myswingHighBarsAgo]);
      }
      }
      }
      output

      12/17/2020 3:53:37 PMInstance # 1bars ago:6High was:12757
      12/17/2020 3:53:37 PMInstance # 2bars ago:19High was:12755.75
      12/17/2020 3:53:37 PMInstance # 3bars ago:32High was:12756.75

      How do I use the output value in my strategy with the swing indicator?
      How do i specify that I want the #2 bars ago

      If CrossAbove(Close(HighofInstance#2,1)?

      Comment


        #4
        Hello condorhero,

        Below is a link to a forum post with sample code of comparing a swing to a previous swing.
        Hello, I'm using the Swing indicator in my strategy and I'm having trouble finding information on how to access previous highs and lows. For example, using Swing(5).SwingHigh[0] will give me the most recent Swing High with a strength of 5, but I would like to know where the last x number of highs were so I can plot higher
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello condorhero,

          Below is a link to a forum post with sample code of comparing a swing to a previous swing.
          https://ninjatrader.com/support/foru...12#post1085012
          so create

          private int Barsago2;
          private double swingHigh2

          and then put the code in?

          do I put that under onbar update?

          im sorry If I am slow, I just started teaching myself C#

          Comment


            #6
            Hello condorhero,

            This is Jim responding on behalf of Chelsea who is out of the office at this time.

            The code Jesse posted in the linked thread and be tested in OnBarUpdate and tested with the NinjaScript output window open to observe the prints.

            If you are new to C#, it can be helpful to use the Strategy Builder to create logic, and then use the View Code button to see how the syntax gets generated. You may also consider reviewing some educational materials on C# that can be found external to NinjaTrader. I have linked one publicly available resource below.

            C# (pronounced "C-Sharp") is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. It is widely used for the following: Our C# tutorial allows you to


            We look forward to assisting.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            91 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            137 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            68 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            121 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            72 views
            0 likes
            Last Post PaulMohn  
            Working...
            X