• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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,
        https://ninjatrader.com/support/help...crossabove.htm
        https://ninjatrader.com/support/help...crossbelow.htm

        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, 11:34 AM.

            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:	1
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 benjamind10, Today, 07:27 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post benjamind10  
                  Started by YevhenShynkarenko, Today, 06:07 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post YevhenShynkarenko  
                  Started by StevenNelson, Today, 04:07 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by Matthew Spositi, Today, 03:28 PM
                  2 responses
                  8 views
                  0 likes
                  Last Post Matthew Spositi  
                  Started by faisamtrader, Today, 01:30 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Working...
                  X