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

Cannot get correct bar to enter

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

    Cannot get correct bar to enter

    [ATTACH]n1081053[/ATTACH] [ATTACH]n1081054[/ATTACH] I have attached two script created from Strategy Builder. I have had trouble getting this script to do what I want, so I am re-constructing it step-by-step from the last copy which did what I intended. The script for StochasticReversalBarMAfilterAuto colors the buy signal bar blue (25), as it should. However, I wanted to create a purchase above that signal bar. I have not created the entry yet, but before I did, I wanted to make sure the strategy would enter on the correct bar. So in StochReversalBarMAfilterAuto2 I moved the setup criteria to "one bar ago", then created the condition that the entry signal would occur if ask of the current bar 0 exceeded the high of the signal bar 1 bar ago. I believe that should have colored bar 25 blue on the second strategy, but it didn't. That is one of the problems I have been having with this strategy all along, and I can't fix it. I have a condition set which uses the Keltner Channel EMA band to filter out trades too close to the 20 bar EMA, but a trade just above the high of bar 25 had plenty of room before reaching that level. What am I doing in Strategy Builder incorrectly? A crossover condition did not work, either.
    Click image for larger version

Name:	SchasticReversal 1.PNG
Views:	414
Size:	46.8 KB
ID:	1081051Click image for larger version

Name:	StochasticReversal 2.PNG
Views:	325
Size:	42.7 KB
ID:	1081052

    #2
    Hello Bionian,

    Thanks for your post.

    What we recommend is to debug your strategy using print statements. These print statements can be used to output the value of the variables used in your conditions and in this way you can better understand why your strategy is performing as it does. We have assembled some general debugging tips here: https://ninjatrader.com/support/help...script_cod.htm

    Using a print statement in the strategy builder can be done and here is a link to a short video to help you get started: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

    I note that your strategy is using the calculate mode of Calculate.OnPriceChange. Keep in mind that when you first apply the strategy to your chart, the strategy will be performing on all the historical bars as if the mode were Calculate.OnBarClose which does cause the barsAgo references to change. When Calculate.OnBarClose, the index of [0] would refer to the just completed bar and your code will only run once per bar. When the strategy gets to the right edge, Calculate.OnPriceChange will begin and the index of [0] will now be the forming bar and the just close bar will be [1].
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Paul. Yes, that is exactly what I wanted. I wanted the signal bar (bar 25) to close, then enter the next bar (action bar) as soon as it traded above the high of 25. I did not want bar 26 to close before entry. I thought that perhaps the code would reveal why that is not happening. I will review the links you provided and see if I can add any additional input.

      Comment


        #4
        Paul-

        I have added the print command to each bar in the strategy. The strategy is attached. I have also found 3 instances which should have triggered, but didn't. They are 12/12: the bar at 12:35 should have triggered as it went above the high of the bar at 12:30. On 12/13 the bar at 11:40 should have triggered as it went above the bar at 11:35. And on 12/16, the bar at 13:50 should have triggered as it went above the bar at 13:45. Instead, it triggered as bar 13:55 went above the bar at 13:50. This has been most frustrating, because I have been working on it for days. Can you help me out? StochReversalBarMAfilterAuto2Print.zip

        Comment


          #5
          Hello Bionian,

          Thanks for your reply.

          Debugging a strategy (or any code) can be tedious. To be clear, as we are a small team, we do not provide debugging services but we can certainly keep you moving on debugging which is part of any programming effort.

          In looking at your strategy, you are using EnterLong() so if the entry conditions are all true these orders will be filled when submitted as they are market orders. As you have identified areas where you think they should have filled this means your entry conditions were not all true.

          In looking at your print statement in the strategy builder I do not see where you are showing all of the values/variables used in the conditions for entry. Once you show all of the values in the print statement then you will be able to answer the question as to why it did not place the order(s).







          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks. So to be clear, if I want to buy above bar 36 (12:30) on 12/12, and enter on bar 37 (12:35), I would program the strategy to trigger "on price change", the buy order to buy at the current bar if ask > close of one bar ago. All my other conditions, such as a bar closing above its median, stochastic K crossing stochastic D, and stochastic D <= 30 would be for 1 bar ago. Since the entry is based on the close of the prior bar, and the strategy is set to "price change" rather than "close", then the buy should trigger. Correct?

            Comment


              #7
              Hello Bionian,

              Thanks for your reply.

              Again I would encourage you to print the actual values being used to make the trade entry decision to validate your questions in the context of what and when you are looking.. Note that if you are looking at historical data, the strategy will operate as if Calculate.OnBarClose were set. The OnPriceChange will be on real time bars only.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Thanks. I did not know that. That maybe part of my problem.

                Comment


                  #9
                  Do you have any suggestions for back testing an "on price change" strategy other than through market replay? This would take a great deal of time for a 1-year back test, and optimization would be very tedious. If the goal of the strategy is to enter at market above another bar, any back test on the close would not be reliable. Many of those trades would never trigger, and the ones that did would have huge slippage.

                  Comment


                    #10
                    Hello Bionian,

                    Thanks for your reply.

                    You could add a 1 tick series to your strategy and submit your orders to that 1 tick series. You would also need to enable tick replay in order for your strategy to run like Calculate.OnPriceChange. In both cases you would need to have tick data for the period of the analysis. You might try this on a short period of time and compare to results using Playback with market replay over the same period.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Paul-

                      Thanks for your reply. I began using NinjaTrader as my data provider for ES in early November. Before that I was using Interactive Brokers, so most of my historical data probably does not have tick data. How can I confirm whether I have tick data, and if I don't, do I need to delete data files and have NinjaTrader re-download them?
                      And is tick data automatically downloaded with NinjaTrader?
                      And finally, would I need to download historical and/or replay data for each ES contract (6-19, 9-19, 12-19, ect)?

                      Sorry for all the questions.

                      Rick

                      Comment


                        #12
                        Hi Rick,

                        Thanks for your reply and further questions, no worries.

                        You can review the historical data through the historical data managed (Tools>Historical data) Reference: https://ninjatrader.com/support/help...ta_manager.htm

                        An easier way though would be to create a chart of tick bars such as 2000 tick size bars and specify 365 days to load. Once that chart loads ( will take a some time) you will have all of the tick data available and it is now stored in your PC. On the chart, go to the very left bar (scroll left until you can't), place the mouse cursor on the bar and center mouse wheel click to display the "mini data box", this will show the date of the first bar. We typically have 1 year of tick data available.

                        Tick data is auto downloaded when you have a chart that calls for historical tick data and the data is not found in your PC, so the first time you load a chart the downloaded data is first saved then is displayed on the requesting chart.

                        For the historical (not replay) it will auto load the various contracts that were the front month on the day of the data, so no, you do not need to managed this for the chart historical data.

                        Yes for playback with market replay data you do need to be mindful of the front month and download the data within that front month in effect on the day of the download. You can find these dates in the instruments, Tools>Instrument (select instrument) then edit instrument, scroll to the bottom to see the rollover dates/contracts. reference: See " Understanding the Contract months section" on this page: https://ninjatrader.com/support/help...nstruments.htm
                        Last edited by NinjaTrader_PaulH; 12-19-2019, 07:18 AM. Reason: Correction to last paragraph, changed "not to "need"
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_PaulH View Post

                          Yes for playback with market replay data you do not to be mindful of the front month and download the data within that front month in effect on the day of the download.
                          Paul, I think you had a typo here. Could you please re-phrase? Sorry.

                          Rick

                          Comment


                            #14
                            Hello Rick,

                            Thanks for your reply.

                            To restate: "Yes for playback with market replay data you do need to be mindful of the front month and download the data within that front month in effect on the day of the download. "

                            (I will correct post 12 as well.)
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Paul-

                              Here's an idea that would not require huge amounts of tick data. For back testing, I could create two data series on one chart- one is ES 5 minute series, the other is the ES 1 minute series. I am already doing this on another strategy. Can't I use the 5-minute series to create the condition, then use the close of the 1-minute bar for the entry? Suppose I get all the 5-minute bar conditions for the entry met at 10:00. Then once those conditions are met AT THE CLOSE OF 1 BAR AGO on the 5 minute chart, then make my entry based on the 1 minute chart, "IF ASK OF BAR 0 > CLOSE OF 1 BAR AGO" on the one-minute chart once the 5-minute conditions are met.

                              f this would work, would I need to place the bar 5 conditions into a condition set to make sure the 1-minute bar triggers at the right place?

                              You can probably answer without much thought whether this would work. If so, then I can spend the half a day it will take as a novice for me to figure out how to put it into Strategy Builder.

                              Thanks-
                              Rick

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,415 views
                              0 likes
                              Last Post Traderontheroad  
                              Working...
                              X