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

Indicator in Strategy for Backtesting. Best way?

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

    Indicator in Strategy for Backtesting. Best way?

    Hello,

    my issue is to create a "major" Strategy which can used for backtesting for all my inidkators.
    The strategy should not have any logic, except executing EnterLong and EnterShort.
    In this case i would write an indicator for indikator stuff and not for backtesting-stuff (my english is far from perfect)

    In the indikator, i print a green dot on the chart to show a posible good position to place a short or long Order.
    Of course, the strategy can't "read" the dot. what is the best way to get this position to the strategy?
    I use multiple Timeframes and more then one Plot.


    #2
    Hello SpikeLGWG,

    Thanks for your post.

    I would suggest adding a transparent plot (plot brush is set to Transparent) to your indicator and set the value to be +1 for a long entry, -1 for a short entry, and 0 for no entry.

    The transparent plot will not distort the current display of the indicator.

    The strategy can then be set to read the indicators plot and place orders based on the indicator plot.

    Note: you can also read the transparent plot in the market analyzer.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Tanks for your answer, so, as i understand, i shoud use the first Plot of the indicator to communikate with the strategy.
      But i am realy confused on Multitimeframe, do you have a tutorial to create a Multitimeframe strategy for backtesting?

      Comment


        #4
        HelloSpikeLGWG,

        Thanks for your reply.

        It does not have to be the first plot, it can be any plot that you wish. In a multiplot indicator, you may find it beneficial to name the plot "Signal" so that you can consistently know which plot to use for signal indication.

        We do not have a tutorial on creating a multi-timeframe strategy. We do have an extensive help guide section on creating multi time frame/series scripts which we highly recommending reviewing in its entirety: https://ninjatrader.com/support/help...nstruments.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your help, i will read your linked page

          Comment


            #6
            Hi,
            i have realy no idea how can this work.
            To understood this things i watched a Video of Backtesting, which use the "SampleMaCrossOver"-Strategy and the EMA Indikator.
            And i am realy cunfused:
            Click image for larger version

Name:	NinjaTrader_Backtesting.jpg
Views:	348
Size:	22.3 KB
ID:	1143441
            The Strategy check the crossing of this EMA-Indikators, but the Action to create a Order is one Bar to late! You see the blue vertikal Line, in this Bar the cross is happend.
            What can i do to get the Order to the Bar from the Blue line?

            Comment


              #7
              Hello SpikeLGWG,

              Thanks for your reply.

              In the strategy analyzer, the Strategy can only process bars based on Calculate.OnBarClose. What happens here is that the cross occurs and when the bar closes the cross is determined by the strategy to have occurred and an order is placed. Since it is the end of the bar (with the blue line), the order could not be filled until the next bar. This strategy would perform the same in live data when using Calculate.OnBarClose.

              In the Strategy Analyzer, to get the order to occur in the same bar as the cross you would have to:
              1) Add a 1 tick series to your script
              2) Enable Tick Replay
              3) Set your strategy to Calculate.OnEachTick.

              Notes:
              1) You would need the tick series for the entire duration of the backtest.
              2) Tick replay and rick process will slow down the strategy analyzer, be patient if you go this route.
              3) Setting the strategy to Calculate.OnEachTick means that you will have to add additional code logic to prevent multiple entries.

              Alternatively, use the Playback connection with market replay data however you will still have to set your strategy to Calculate.OnEachTick and you will have to add additional coding logic to prevent multiple entries.

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Thank you,
                i will try.

                Comment


                  #9
                  Hi, it looks better, but not like expected.
                  Here a Screenshot from the Strategy with an Indikator in live:
                  Click image for larger version

Name:	Ninatrader_Live.jpg
Views:	321
Size:	8.8 KB
ID:	1143500
                  the Opening of the Order is in the Bar and the Blue Arrow is on the excpected Position. On live it looks perfect.
                  On Backtesting with implemented Ticks:


                  Click image for larger version

Name:	NinjaTrader_Backtesting.jpg
Views:	308
Size:	12.3 KB
ID:	1143501
                  the opening of the Order is in the Wrong bar and the Wrong position, i would excpect, the Order is create nearby the Blue Arrow.
                  And realy strange is the logfile from this Minute:
                  "Debug.txt"
                  It starts with the Minute of the First Indikator and executes all Ticks from them.
                  After them the second Indikator with the Same Order.
                  And at last, the Strategy will executed, but only with the Result from the last Tick of this two Indicators.
                  I also atteched the two Files (Indikator "MyEMA" and Strategy "IndikatorTest")
                  Can you show me whats wrong?

                  Comment


                    #10
                    Hello SpikeLGWG,

                    Thanks for your reply.

                    Please provide a screenshot of the Strategy analyzer settings that you are using.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      of course Click image for larger version

Name:	Chart.jpg
Views:	315
Size:	57.3 KB
ID:	1143578Click image for larger version

Name:	Strategy.jpg
Views:	306
Size:	81.8 KB
ID:	1143579

                      Comment


                        #12
                        Hello SpikeLGWG,

                        Thanks for your reply.

                        Those are the setting for your chart and for your strategy. What I am looking for is the strategy analyzer settings, please see the layout item # 2 in this page: https://ninjatrader.com/support/help...zer_layout.htm for an example. I just need to see the settings on the right.
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok, but you know, the Problem is in the Chart and has nothing to do with the Strategy Analyser?

                          Click image for larger version

Name:	Strategy_Analyser.jpg
Views:	307
Size:	78.5 KB
ID:	1143595

                          Comment


                            #14
                            Hello SpikeLGWG

                            Thanks for your reply.

                            In an earlier post you wrote, "To understood this things i watched a Video of Backtesting, which use the "SampleMaCrossOver"-Strategy and the EMA Indikator." I apparently misunderstood that to mean you were using the Strategy analyzer.

                            For your chart view of historical trades then, you will need to enable "Tick Replay" assuming you have a data source that provides historical tick data. Please see the help guide here: https://ninjatrader.com/support/help...ick_replay.htm
                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Thank you for your realy fast help!
                              Click image for larger version

Name:	Perfect.jpg
Views:	313
Size:	47.3 KB
ID:	1143606

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rjm1903, Today, 04:14 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post rjm1903
                              by rjm1903
                               
                              Started by sidlercom80, 04-05-2021, 09:27 AM
                              7 responses
                              176 views
                              0 likes
                              Last Post Unsuitable  
                              Started by Zinger357, Today, 04:08 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Zinger357  
                              Started by sy2023, 09-15-2023, 08:51 PM
                              4 responses
                              248 views
                              0 likes
                              Last Post Crusade12  
                              Started by JosephHansen, Today, 12:35 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post JosephHansen  
                              Working...
                              X