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

Intrabar Backtesting

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

    #16
    Hi Jessica,

    Thanks for your prompt response. The market replay isn't ideal for what I'm trying to do. Why?
    I need to optimize it. I usually use market replay for checking to make sure everything is working correctly. I can see visually if my strategy did what it was supposed to do.

    I was posting on the forum trying to get the backtester to work because I felt that if I can get it to work there, then it should work in the optimizer too.

    To explain further why market replay isn't ideal for my situation is this:

    If I want to optimize my strategy with a combination of both TP and SL from 10 to 100 with a step of 10, then I would have to run 100 cycles (10 * 10). So this where I should let the technology handle this automatically. Also, I'm sure the backtesting is built to make the most of my computer's resources in this case.

    Thanks again!

    Comment


      #17
      Originally posted by BernWillChris View Post
      I think what I'm concerned about right now, is the proper exit and I'm not sure why this is happening:



      As you can see, I'm entering correctly. The chart is on hourly candles and I programmed the strategy to enter the trade at the 7th minute; so that's working. However, it is very unlikely that my trades all hit their targets at the top of the hour.
      I'm not well versed in NT8 and I don't trade FOREX, so my ability to help decipher why all your targets are being executed at the top of the hour is limited.

      It looks like the recent conversation between support & the OP is getting off track?

      BernWillChris, I believe 1) Jessica hasn't a clue why your trades were exiting at the top of the hour and 2) she was asking for a video from you to help her figure this out.

      Jessica, the OP wants to 1) run strategy optimization on (I presume) a list of instruments and 2) is asking why his exits are so well timed that they only happen at the top of the hour despite using SetStopLoss and SetProfitTarget?

      I believe the problem that we should be addressing is: why does the OP's backtest show almost every target's exit time happening at the exact hour with the minutes portion set to zero?

      Jessica, look at the "Exit Time" column, what would cause such uniformity in the exit timestamp displaying zero minutes and zero seconds?

      I believe OP is saying these exit timestamps are lying.

      Comment


        #18
        Yes,

        Let's use the EUR/USD forex pair for an example. Let's say the price is 1.12432. The 4th digit, the pip digit, is always changing. Heck, this bad boy can move 20 pips in 5 mins if it wants to.

        So let's say that the moving averages cross at 9:42:12 am; remind you, this cross can happen at anytime. So what I want my strategy to do is execute a long position when that happens. Now, I'm in the trade. Remember that I said that price can move 20 pips in 5 mins, well, this time it took 12 minute to reach the target of 20 pips. So I went long @ 1.12432 and now price is 1.12632 @ 9:54:12.

        So basically, I'm saying that the target can be reached anytime, even at 10:00:00, but it is a zero percent chance that every single one of my trades are getting out at the top of the hour. If you look at the image, you will see that I'm getting in at the 7th minute. That's fine. Just to test to make sure that the code is doing what I want it to do, instead of using moving averages cross, I just requested the code to enter a trade at the 7th minute. Everything is fine there.

        Thanks again.

        Comment


          #19
          Thank you for clearing that up for me bltdavid, that helped a great deal.

          BernWillChris, bltdavis was correct in that I was trying to get a video from you because it would help me see what you are seeing.

          When I tried this trading Ł against $ (GPBUSD) with the historical data I'm attaching in a zip file (see here for instructions on importing it if you would like to use it so we are operating on the same data, http://ninjatrader.com/support/helpG.../importing.htm ) with the settings in the picture I have attached - both on 1 minute and 60 minute bars - I wasn't able to get my trades to execute at the top of the hour. I used the same strategy you sent me; the only change was that I'd renamed MyCustomStrategy2 to MyCustomStrategy. I am attaching the renamed copy of your strategy to this post as well.

          If you could help me configure my system so that I get the same results you are seeing - trades posting at the top of the hour - it will be a lot easier for me to tell you what is going on. In order to help me do that, I need to try to duplicate your system on my end.

          A video is one way to get the information I need to repeat your configuration, and I felt it was the easiest way. But generally speaking, if I could ask you to look over everything I'm sending you, it may be easy for you to see what I'm doing differently from you. If you could look everything over it would be appreciated.
          Attached Files
          Last edited by NinjaTrader_JessicaP; 09-20-2016, 02:07 PM.
          Jessica P.NinjaTrader Customer Service

          Comment


            #20
            Hi Jessica,

            Thanks again. I don't know any easier way of explaining what I'm trying to do. If you like, you can forward my posts to another staff member that has more time working with forex and the Strategy Analyzer and just tell them that I speak poorly. I'll not get offended and I also say this with the utmost respect . This is the 20th post and pretty much from the very first post I was looking for two possible answers:

            1.) Yes, Ninjatrader supports that and you can do it by doing so and so.

            or

            2.) No, your original thought was correct. Ninjatrader doesn't support intrabar at the time.

            This is what I said in a previous post:

            Let's say I have an hourly candle and the moving averages cross at 9:17:28 and hits its target of 20 pips at 9:48:53, then this is exactly what I would love to see in my backtest. I know everything is working and I'm getting back accurate results.
            I said that I was using hourly candles, not the one minute that you have. All that statement is saying that I want my strategy to enter the trade as soon as the condition is satisfied(moving averages cross), not after the hourly candle closes. The default way would have me getting in at the top of the hour and exiting at another top of the hour. But with that one trick that bltdavid gave me, I was able to enter intrabar, at the 7th minute. The only problem that I was having is that I wasn't exiting intrabar.

            Here is an image of my configuration:


            And I also used the default MA cross strategy that comes with Ninjatrader. You'll see how this isn't working intrabar. All trades are entering and exiting at the top of the hour. Setting the Order Fill Resolution to high, I thought would fix this problem, but it didn't.

            I'm not even sure why you attached GBP/USD. It isn't relevant and it leads me to believe that we are not on the same page.

            Thanks for the effort and I'll always be appreciative to someone reaching out to help.

            Comment


              #21
              I would be happy to let a colleague take this ticket if you would prefer, there will be no offense taken on either side of this conversation. If you only wanted to know whether Ninja has built-in intra-bar support, the answer is yes. I am adding some help guide documentation on the Calculate property, on OnMarketData, on Tick Replay, on Fill Resolution, and on multi-time frame strategies for further reading if you are interested.







              The backtest results you gave us were highly unusual, but if helping you determine why you were seeing those results is not the purpose of your reaching out to us, please let us know how we should proceed and we will be happy to help in any way we can.

              I would like to mention that I tested with 60 minute bars yesterday (I do not have an hourly bar type and one is not provided stock with NinjaTrader) and was unable to reproduce. I was attempting to use several forex pairs; is there a reason why EUR/USD as you mentioned using is important and GBP/USD would not be an acceptable instrument? I am also unclear as to why we went back to the SampleMACrossover strategy after you had provided us with a code sample.

              Generally speaking the reason I sent you a picture of settings I knew would not reproduce the issue is because it was the fastest and easiest way to get a configuration on our end that matches yours. Thank you for providing us with both your configuration details and with the strategy you are attempting to test with. This information will make it easy for either myself or one of my colleagues to assist you further and will allow us to understand you more clearly and rule out a lot of potential causes. Please provide this information in the future along with your initial request for similar questions in the future for faster assistance.

              The SampleMACrossover strategy is not designed to take advantage of any intra-bar data. The help guide links I posted above will allow you to put together a strategy of your own, or modify the strategy you sent us earlier, so that it can take advantage of this information. If you have any specific questions about any of the information in the help guide we will be happy to assist further.
              Last edited by NinjaTrader_JessicaP; 09-21-2016, 06:46 AM.
              Jessica P.NinjaTrader Customer Service

              Comment


                #22
                Hi Jessica,

                Thanks for your assistance. I had attached an image of what I was asking for.



                As you can see, I'm entering at 7th minute just like a programmed it to do. It isn't exactly at the HH:07:00, but close enough for my satisfactory. Maybe in the data, the first time it received an update, it could've been at HH:07:03.

                Now for the exit, see all of those random times. I programmed it to exit with a 20-pip TP or SL. If you look at the profit column, you'll see something like 203. That is 203 ticks or 20.3 pips. That is a bug from Ninjatrader, which isn't a big deal; I can work with that. But you can look at the entrance price and the exit price to see that it really was 20 pips roughly.

                Now, I was unable to do this code with the SetStopLoss() or SetProfitTarget(). I had to do it like this:

                Code:
                if(Close[0] > Position.AveragePrice + 200 * TickSize){
                      ExitLong();
                }

                I feel that it would be cleaner to use the SetStopLoss() and as my code gets more complex, I'll be wishing that I can use it.

                To answer your questions:

                Is there a reason why EUR/USD as you mentioned using is important and GBP/USD would not be an acceptable instrument?
                Nope, you can use any forex pair.

                I am also unclear as to why we went back to the SampleMACrossover strategy after you had provided us with a code sample.
                I deleted the old one that I created, so I thought that I just show you one that Ninjatrader already has and to also show you that the default way will have you getting in and out at the top of the hour. You'll make more profitable strategies by having your trade enter intrabar instead of waiting toward the end of the hourly bar and miss a lot of pips. And it will help with accuracy to be able to go intrabar during backtesting.

                So I'll be completely happy now if I can figure out a way of managing the trades using Ninjatrader's built-in SetStopLoss() and SetProfitTarget() and etc. It will also be great too if I can rollover fees subtracted from my profits to paint an even more accurate picture. I don't think the latter would be possible though.

                Thanks for your help.

                Comment


                  #23
                  Originally posted by BernWillChris View Post
                  Now, I was unable to do this code with the SetStopLoss() or SetProfitTarget(). I had to do it like this:

                  Code:
                  if(Close[0] > Position.AveragePrice + 200 * TickSize){
                        ExitLong();
                  }
                  Are you running this code inside BarsInProgress == 0?

                  That would explain why you are exiting at the top of every hour.

                  Your strategy from post #10 does not show this code.

                  Please attach the exact script that is producing the results you are seeing.

                  Comment


                    #24
                    Nope,

                    I'm using BarsInProgress == 1. I was just showing her how I was getting the software to get me out when I hit the 20 pips. Using that method isn't the worst thing, but as a programmer yourself, I'm sure you can understand why I might want the native functions to work as I would like.

                    Maybe I can create a .DLL with that snippet in a function called StopLoss(), I guess. Thanks

                    Comment


                      #25
                      That won't be necessary. I was able to reproduce this on my end with the attached script and settings. I am reviewing the specified behavior and data from other events and will be following up shortly. Thank you for your report. Please keep an eye on the NinjaTrader 8 Release Notes page for updates and bugfixes.

                      Attached Files
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #26
                        Hello BernWillChris,

                        First I appreciate your patience with this process.

                        To provide an immediate answer to your question, you can set Calculate = Calculate.OnEachTick to cause SetProfitTarget and SetStopLoss to function properly. For commissions, you will need to properly configure a commissions template using these instructions :



                        We are happy to help with any specific questions that come up setting up commissions.

                        To provide a more satisfying answer to your question, as we realize you may not desire to have your OnBarUpdate process every tick, I have done some research. After carefully reviewing our design specifications and the old behavior of NinjaTrader 7 under several test scenarios, we were able to determine that Ninja is behaving as it should.

                        In light of your scenario, I have requested the following feature be added to NinjaTrader
                        This user would like an overload added to SetProfitTarget and SetStopLoss which takes BarsInProgress into account, similar to EnterLong's overload

                        I will follow up with more information as soon as it's available. If the feature requests already exists, a vote will be added to it.All that said, if you do decide to use Calculate.OnEachTick, now that you are aware of how to make multi-series strategies, I would also like to draw your attention to IsFirstTickOfBar



                        If you check to see if this is true every OnBarUpdate, and return immediately when this is false and when BarsInProgress is not 1, then you will experience no slowdown at all when Calculate == Calculate.OnEachTick , and your strategy will work exactly the way you desire. The above feature, in other words, is not required for Ninja to operate the way you would like; it is only being requested as a convenience.

                        As a further convenience, I have included a script where I have done both these things and have attached it to this e-mail.

                        Please let us know if there are any other ways we can help.
                        Attached Files
                        Last edited by NinjaTrader_JessicaP; 09-21-2016, 12:23 PM.
                        Jessica P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by GLFX005, Today, 03:23 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post GLFX005
                        by GLFX005
                         
                        Started by XXtrader, Yesterday, 11:30 PM
                        2 responses
                        11 views
                        0 likes
                        Last Post XXtrader  
                        Started by Waxavi, Today, 02:10 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post Waxavi
                        by Waxavi
                         
                        Started by TradeForge, Today, 02:09 AM
                        0 responses
                        14 views
                        0 likes
                        Last Post TradeForge  
                        Started by Waxavi, Today, 02:00 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post Waxavi
                        by Waxavi
                         
                        Working...
                        X