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

Buy on second bar as it breaks first pls help

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

    Buy on second bar as it breaks first pls help

    simple i want to enter long as the second bar breaks the first. 5 min chart at the open.

    this should be really simple and i just cant figure it out.

    if (Close[0] > High[1])

    ;


    {
    EnterLong(DefaultQuantity, "");

    on the backtest settings window if i try 0 bars required it doesnt get me in and if i try 1 bar required it gets me in on the third bar at some odd price.

    thanks in advance

    #2
    Please review this reference sample.

    RayNinjaTrader Customer Service

    Comment


      #3
      thanks but

      this is better, but

      changed the code to look like this, i just put 0's as the low number:

      // Stores the highest high from the first 30 bars
      if (Bars.BarsSinceSession < 0 && High[0] > highestHigh)
      highestHigh = High[0];

      // Entry Condition: Submit a buy stop order one tick above the first 30 bar high. Cancel if not filled within 10 bars.
      if (Bars.BarsSinceSession > 0 && Bars.BarsSinceSession < 40)

      so, its still getting me in way late, in this case RNR today on a 5 min chart gets me in on the 5th bar even though the second broke the first.

      sorry man am not a programmer, i cant understand what numbers NJ is referencing.

      Comment


        #4
        Unfortunately you need to be somewhat of a programmer to work your way through this.
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by gamblor View Post
          simple i want to enter long as the second bar breaks the first. 5 min chart at the open.

          this should be really simple and i just cant figure it out.

          if (Close[0] > High[1])

          ;


          {
          EnterLong(DefaultQuantity, "");

          on the backtest settings window if i try 0 bars required it doesnt get me in and if i try 1 bar required it gets me in on the third bar at some odd price.

          thanks in advance

          Have you tried this?

          Code:
           
          if (Bars.BarsSinceSession == 1
          && Open[0] >= Close[1]
          && Close[1] > Open[1])
          
          EnterLong();}
          }

          Set your session to begin 5 minutes before you actually want it to start, ie if your session is 9:30am, make it 9:25am. That way Bar 0 is 9:30am, and Bar 1 is 9:35. This enters only on the 2nd bar of the session.

          And make sure CalculateOnBarClose = false;

          Comment


            #6
            thanks ray guess am an idiot. dont understand why this sample doesnt work with a couple of mods.

            if i got this right, the second statement that says it stores the highest high off the 30 bars can be changed to:

            if (Bars.BarsSinceSession < 0 && High[0] > highestHigh)

            all i did is tell it to use to use the first bar to set the highesthigh

            then:

            if (Bars.BarsSinceSession > 1 && Bars.BarsSinceSession < 40)

            should get me in on the next bar.

            but it doesnt it takes me in on the 5th bar of this chart, i can post a chart if you'd like somewhere.

            why is it waiting that long? its clear to me that the 5th bar is breaking the first 5 min high, but that already happened on the second bar and thats where it should be going in.

            think i'll leave for now... long weekend and am going on holidays for a while next week. i'll ask again then.

            scriabinop23: thanks man, i'll look into your post tomorrow, maybe thats the solution.... thanks for helping any help is greatly appreciated.

            Comment


              #7
              Hi gamblor,

              Please debug your code per this tip: http://www.ninjatrader-support.com/v...ead.php?t=3418
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Here's some other ideas for you.

                Bars.BarsSinceSession can never be below 0, so that logic is flawed in itself. Do a
                Print(Time[0] + " " + Bars.BarsSinceSession + " O: " +Open[0] + " C-1:" +Close[1]) in onbarupdate and you'll see that the first bar of a session is actually bar 0.

                High[0] when at Bars.BarsSinceSession == 0 is actually the high of the previous day's last bar. Thats why you want to start your session 5 minutes early.

                There's a built in function (indicator) to find the current session's high.

                Use:


                CurrentDayOHL().CurrentHigh[0]


                Additionally, you can check the previous session's high:

                PriorDayOHLC().PriorHigh[0]


                That will tell you, effective the most recent bar, what the current high is.
                Last edited by scriabinop23; 02-16-2008, 09:42 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rhyminkevin, Today, 04:58 PM
                4 responses
                52 views
                0 likes
                Last Post dp8282
                by dp8282
                 
                Started by iceman2018, Today, 05:07 PM
                0 responses
                5 views
                0 likes
                Last Post iceman2018  
                Started by lightsun47, Today, 03:51 PM
                0 responses
                7 views
                0 likes
                Last Post lightsun47  
                Started by 00nevest, Today, 02:27 PM
                1 response
                14 views
                0 likes
                Last Post 00nevest  
                Started by futtrader, 04-21-2024, 01:50 AM
                4 responses
                50 views
                0 likes
                Last Post futtrader  
                Working...
                X