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.



            We look forward to assisting.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            44 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            65 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X