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

Multitimeframe strategy problem in Strategy Analyzer

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

    Multitimeframe strategy problem in Strategy Analyzer

    Hello,

    I am having issue using Strategy Analyzer to backtest my strategy. First I will describe how my strategy works.

    Strategy:
    Calculate = Calculate.OnEachTick;

    BarsArray[0] = 1 Minute (I do not have logic here)
    BarsArray[1] = 1 Minute (I use indicator golemTrendLines on this timeframe)
    BarsArray[2] = 1 Tick (I test distances of next 1 Minute candle open)

    I add Indicator golemTrendLines to strategy. It uses BarsArray[1] (1 Minute) and is also Calculate = Calculate.OnEachTick;


    1) It works fine (see image strategy-in-chart.png)
    when I add strategy on chart (1 minute timeframe) and test it on market replay data

    2) It works bad (see image strategy-in-analyzer.png)
    when I try to test strategy on strategy analyzer on BarsArray[0] = 1 tick data then it starts acting wierd. Indicator golemTrendLines which is inside strategy on BarsArray[1] = 1 Minute is set to 1 BarsArray[0] = 1 Tick

    Could you please tell how strategy analyzer works with multiframe and tickreplay?
    I was assuming, when i use DataSeries 1 tick in analyzer, then Indicator golemTrendLines will use BarsArray[1] = 1 Minute instead of 1 Tick timeframe.

    #2
    Hello kujista, thanks for your post.

    Please confirm I understand the issue: You are setting up this indicator to run on BarsArray[1] but when you test in the strategy analyzer the indicator is set to process on BarsArray[0], and this does not happen on live data or Market Replay otherwise?

    I would need to test this script to reproduce this problem. Could you kindly Export it and post it here or email it to me at platformsupport at ninjatrader.com? If you email, please reference the following in the body: ATTN ChrisL 2214954 <forum thread link here>

    Note, I will not be able to compile if the golem indicator is not open source. If that is the case, I would recommend testing the same thing with a default indicator (like EMA or SMA) and see if it happens there. That way the issue can be narrowed down to that indicator specifically

    I look forward to hearing from you.
    Last edited by NinjaTrader_ChrisL; 07-17-2019, 07:48 AM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Yes it's just like you said. I can export it but it's quite complex.. so i first give it a try..
      Anyway. If I used in Strategy Analyser - 1 minute data and TickReplay, should be working IsFirstTickOfBar just like in market replay ? Or does it operate only on 1 minute candle close

      Comment


        #4
        Hi kujista,

        Yes, IsFirstTickOfBar should work on the 1 minute bar. A Print statement can be used to verify that, or breakpoint in Visual Studio code as well.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          And should I be able also to get Open of Candle on 1 Minute timeframe using:
          if (BarsInProgress == 1 && IsFirstTickOfBar) {
          open = Opens[1][0];
          }

          This is crucial for me.. I need to get open on open of candle on higher time frame.
          I also should be using 1 Tick timeframe on barsarray[2] if strategy analyzer input series is set to 1 minute?

          Comment


            #6
            Hello kujista, thanks for your reply.

            Is getting the open not working for you in a test? This price data is expected to be available during OnBarUpdate. It should not matter what your primary series is set to as long as your strategy is designed to work on a 1 tick time series (i.e. OnEachTick).

            Best regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hello,
              I tested what inputs use indicators inside strategy. Take a look at this screen: http://prntscr.com/oon69e

              I found out, that if I have strategy with barsarray ( my first comment):

              BarsArray[0] = 1 Minute (I do not have logic here)
              BarsArray[1] = 1 Minute (I use indicator golemTrendLines on this timeframe)
              BarsArray[2] = 1 Tick (I test distances of next 1 Minute candle open)

              Then If I add indicators (doesn't matter if it is EMA - which comes with NT8 or my custom), the indicator added into strategy always uses Input[0] even if I use emaObj = EMA(Inputs[1], 10);

              This is problem because when i want to test strategy in strategy analyzer on tick data my indicator does not work properly because of bad Inputs[0] instead of Inputs[1].

              So I test strategy setting it like this: http://prntscr.com/oon9wv This defines Inputs[0] as 1 minute time frame which is passed inside my indicators inside strategy. Even when ticked choice TickerReplay I get strange behavior.. I set stop loss to one tick but i always get 2 ticks. even when price on 1 tick frame does not hit this value after entry :-/ Is there an issue I am missing?

              Comment


                #8
                Hello kujista, thanks for your reply.

                I am not getting the same problem with my test script. Could you take my script and re-create this problem your seeing?
                Attached Files
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hello thanks a lot for you assistance. I looked in example and found out, that wrong input for indicator was because I added indicator inside
                  if (State == State.Transition) {

                  instead of
                  if (State == State.DataLoaded) {

                  this solved the issue with input and strategy works with primary bars 1 tick and uses right input for my indicator.

                  I have I more questions. When I test strategy in strategy analyzer on primary bars 1 tick, everything works well.

                  When I add strategy to visible chart - 1 minute.. I get higher stoploss (2ticks) instead of those i require (1 tick). is there some behaviour that i don't get? I have TickerData enabled, so I thought it also works the same in chart - 1minute as well as in strtategy analyzer 1 tick.

                  Comment


                    #10
                    Hello kujista,

                    If you are looking at the historical executions on the 1-minute chart, it is likely an inaccuracy between filling the orders on 1 tick data vs. filling the orders on 1-minute bars. NinjaTrader uses a historical backfill algorithm and filling your orders upon a higher resolution series can improve backtest fill accuracy. On every order entry method, you will find an overload that takes a BarsInProgressIndex parameter. You can add a 1 tick series to your script and specify that the order fill upon that series. There is an example on this here:

                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you for the hint. I always place order EnterLong("blah"); when in OnBarUpdate BarsInProgress = 2 (which is 1 tick). Is it worse then EnterLong(2,2,"Blah"); Do I get better filling?

                      Comment


                        #12
                        Hi kujista, thanks for your reply.

                        Be sure that Tick Replay is enabled. This will provide a more true-to-life historical run for the strategy. This forum post from our colleague Chelsea goes into further detail of real time vs. historical differences you can see, be sure to read through this:

                        Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello,

                          I tried to follow previous link a wanted to do VolumeAsk and VolumeBid indicator. But the calculation is wrong.. I do not know what I am missing. Could you please take a look at protected override void OnMarketData(MarketDataEventArgs marketDataUpdate) in attached file? I gues the values Sells and Buys should together be Volume

                          Click image for larger version

Name:	Screenshot_1.png
Views:	341
Size:	18.0 KB
ID:	1066574
                          Attached Files

                          Comment


                            #14
                            Hi kujista,

                            The BuySellVolume indicator would be a good reference for this. Your OnMarketData method looks fine to me (its the same as BuySellVolume). The plots are getting set in an odd way, you can generally just exclude if(State == State.Historical) and just set the values so that the indicator transitions into real-time. The error seems to be in your OnBarUpdate method.
                            Chris L.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by andrewtrades, Today, 04:57 PM
                            1 response
                            5 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by chbruno, Today, 04:10 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post chbruno
                            by chbruno
                             
                            Started by josh18955, 03-25-2023, 11:16 AM
                            6 responses
                            436 views
                            0 likes
                            Last Post Delerium  
                            Started by FAQtrader, Today, 03:35 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post FAQtrader  
                            Started by rocketman7, Today, 09:41 AM
                            5 responses
                            19 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X