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

Simple Pivot Strategy Not Capturing All Trades

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

    Simple Pivot Strategy Not Capturing All Trades

    I'm new to testing strategies on NT8. I tried to run a simple strategy where I sell one contract of NQ futures whenever the bar hits R1 using Ninjatrader's standard Pivots calculation. Stop loss and target profits where both set at $200. The backtest showed 5 total trades and although the target and stop loss worked on each I noticed that there were several times when trades should have been activated but weren't. I have attached a picture where a trade should have been executed but was not. Any help would be greatly appreciated - thanks!

    #2
    Can you upload your strategy?

    Comment


      #3
      Sure thing - strategy should be attached. Let me know if it doesn't come through.
      Attached Files

      Comment


        #4
        Got it. Thanks!

        Your OnBarUpdate is this,

        Code:
                protected override void OnBarUpdate()
                {
                    if (BarsInProgress != 0)
                        return;
        
                    if (CurrentBars[0] < 1)
                    return;
        
                     // Set 1
                    if (Close[0] == Pivots1.R1[0])
                    {
                        EnterShort(1, "");
                    }
        I see the problem immediately, and I'll help guide you along so you see it, too.

        You're entering a short a position only if the Close of the most recent bar falls exactly on R1.

        Here is where you gotta ask yourself, how often does that happen? Because if you look back
        at your first post, you can see how the bar does not close exactly at R1, but a little above it.

        Well, the way the logic is coded, that's why it missed the trade -- the code is wanting a very
        precise and exact kind of occurrence to happen, but that kind of exactness (Close just happens
        to be exactly at R1) is rare.

        What you need to think about is the act of "crossing" the R1 price level. That is, if the previous
        bar's close is below R1, and the current bar's close is above R1, well that below/above pairing
        of the 2 most recent bars is called "CrossAbove" -- as in, Close has "crossed above" price at R1.

        Check out these web pages,



        Each method has 2 signatures shown in the syntax section. You'd want to use the
        signature where you pass in the R1 price level, something like this,

        Code:
        if (CrossAbove(Close, Pivots1.R1[0], 1))
            Print("Close of bar crossed above R1");
        which is probably what your strategy needs to catch more trades.

        Make sense?


        Comment


          #5
          Ah ha - makes perfect sense! The one last question I have is if this can be fixed through the standard 'strategy builder' inputs or if I have to code this in by myself. Apologize for the rookie questions - I'll catch up quickly after I get through this first test.

          Comment


            #6
            I think so, but, uh, sorry, you're on your own with that (I don't know 'Strategy Builder' that well, because I don't use it).

            CrossAbove and CrossBelow are standard in NinjaTrader, so just look for way to select from a list of standard available methods, and you should see them both there.
            Last edited by bltdavid; 03-24-2019, 12:34 PM.

            Comment


              #7
              Found it.

              When you get to Conditions, just pull down the "Equals" dropdown box in the middle.

              Click image for larger version

Name:	IMGDT_20190324_112326.png
Views:	191
Size:	23.1 KB
ID:	1052475

              Comment


                #8
                Awesome I was just messing around with this part too. I should be able to take it from here. Thanks again for all of the help!

                Comment


                  #9
                  You're welcome!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by junkone, Today, 11:37 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post junkone
                  by junkone
                   
                  Started by frankthearm, Yesterday, 09:08 AM
                  12 responses
                  44 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  5 responses
                  35 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by proptrade13, Today, 11:06 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  35 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X