Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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# Tutorial - C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. This C# tutorial will teach you basic C# programming and will also take you through various advanced concepts related to C# programming language.


            We look forward to assisting.

            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by samish18, Today, 01:01 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by WHICKED, Today, 12:56 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cre8able, Today, 01:16 PM
            0 responses
            3 views
            0 likes
            Last Post cre8able  
            Started by chbruno, 04-24-2024, 04:10 PM
            2 responses
            47 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by WHICKED, Today, 12:45 PM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X