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

Multi TimeFrame BackTest Showing only Default Time Frame on BackTest

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

    Multi TimeFrame BackTest Showing only Default Time Frame on BackTest

    Ok When I run this strategy manually it analyzes and plots the data correctly according to the timeframe that I provide when executing the strategy. However, when I run an optimization backtest it reverts only to using the default timeframe of the price data. It doesn't matter what timeframe inputs I set up the back test to run but seems as if they are ignored and the default timeframe is adopted instead.

    public class TimeFrameTest : Strategy
    {
    private TRIX TRIX1;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    .
    .
    .
    TPeriod = 1;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Second,15);
    AddDataSeries(Data.BarsPeriodType.Second,30);
    AddDataSeries(Data.BarsPeriodType.Second,45);
    AddDataSeries(Data.BarsPeriodType.Minute,1);
    AddDataSeries(Data.BarsPeriodType.Minute,2);
    AddDataSeries(Data.BarsPeriodType.Minute,3);
    AddPlot(Brushes.Blue, "PlotA");
    }

    else if (State == State.DataLoaded)
    {
    TRIX1 = TRIX(Closes[TPeriod], 14, 3);
    }
    }

    protected override void OnBarUpdate()
    {


    if (CurrentBars[0] < 50
    || CurrentBars[3] < 50)
    return;

    Values[0][0] = 10*(TRIX1[0])+49; //scaled plot to be used with
    // CL 06-17 contract for testing and visualization purposes only
    // This plot reverts to default price timeframe when running backtest
    // when running strategy manually it plots correctly

    if ((TRIX1[2] <= TRIX1[1])&&(TRIX1[1] >= TRIX1[0]))
    {
    EnterShort();
    }

    if ((TRIX1[2] >= TRIX1[1])&&(TRIX1[1] <= TRIX1[0]))
    {
    ExitShort();
    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource), Name="TPeriod", Order=1, GroupName="NinjaScriptStrategyParameters")]
    public int TPeriod
    { get; set; }

    #endregion

    #2
    Hello DuggyLou,

    I want to clarify the behavior you are expecting with the code you have supplied.

    First, have you checked the box 'Optimize data series' in the Optimize section of the optimization parameters?

    With the added series below, these would be added for each backtest of the optimization and would not change. Each of these added series will cause OnBarUpdate to trigger as the bar updates for each series.
    Are you finding that the added series are not causing OnBarUpdate to trigger at the close times of each added series?

    I'm showing that each series added to the strategy is causing a value to be returned correctly and based on simple plots I am showing these are updating at the correct time.

    One odd behavior I will be checking with Development on to see if expected, is that if the indicator is called with an added series the indicator will only plot if there is a value set for each primary bar. This means if AddChartIndicator() is called from a strategy using the primary as a 1 minute series, and the indicator is supplied a 2 minute series, the indicator will return a value to the strategy but will not plot when added to the chart.

    A test script is added that demonstrates this. The indicator can be called with a 30 second series ok (because there will be a value set for each bar in the plot), and a 1 minute series, but doesn't show on the chart with a 2 minute series (though it still returns the correct values to the strategy).
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Chelsea,

      Yes, I noticed that the response time for the smoothed indicator using the default price data time frame was delayed. Whereas using lesser indicator time frames moved the signal (where it peaked or valleyed) to the left where I would like it to be. So I'd like to optimize the ratio of price data time frames vs indicator time frames (via selection within the strategy) vs strategy performance. And yes I'd like to be able to "Optimize Data Series" rather than having to run each back test manually for each price time frame.

      I've been really busy at my work I've downloaded and install the SelectSeriesForIndicator file but haven't been able to evaluate it yet. I'll give my feedback once I'm able to get to it.

      Regards,
      Doug

      Comment


        #4
        Hello DuggyLou,

        I'm not quite understanding.

        Are you reporting that an added series is not causing OnBarUpdate to trigger?

        Are you reporting that an indicator with an added series supplied as the input series is not plotting?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          No, I'm simply stating my intention for this strategy. I need my strategy to correctly plot and evaluate ratio of multiple price data time frames vs multiple independent indicator time frames (via selection within the strategy) vs strategy performance.

          So far the strategy defaults to the price data's timeframe when running my backtest. (is there something wrong with how I've coded my strategy?) I need it to use the timeframe that has been selected within the strategy in order to evaluate the above.

          Comment


            #6
            I've just tried your SelectSeriesForIndicator file. It seems to run ok in real time. But it runs errantly when running a backtest. If you display the chart after running a backtest using optimize data series it will always revert the indicator the the price data's time frame. I need it to use the indicator timeframe that is selected within the strategy during the backtest. In no case did it plot the 30 second or 2 minute time frames that should have been selected within the strategy.
            Last edited by DuggyLou; 05-04-2017, 07:51 AM. Reason: Additional Information

            Comment


              #7
              Hello DuggyLou,

              I was able to confirm the behavior with 'Optimize Data Series' enabled causing the indicator input series to become the primary series.

              I have reported this to development. Once I have a tracking ID for this I will post in this thread.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Sounds good. Let me know how it goes. My development is pending this. Thanks

                Comment


                  #9
                  Looking to build simple strategy. Any help appreciated. Spread Trading Strategy. With click to "GoShort" (mean short first instrument and long second instrument), "GoLong" (mean long first instrument and short second). Where can I start from? If can somebody post ready code from I can start, appreciated.

                  Comment


                    #10
                    Here are some useful references that helped me get started. Don't feel discouraged, the best way I found was to unlock the code in the editor and experiment. I hope this helps.

                    Originally posted by NinjaTrader_JessicaP View Post
                    Hello DuggyLou, and welcome to the forums and to NinjaScript!

                    If you would like to take on learning NinjaScript, we have a fully documented help guide which will help you get started. You will find language references to all of the methods and functions you will be using. You will also see a tutorial section which will help you create your first indicator and get you started with some of these concepts.
                    a link to our help guide can be found below





                    If, like me, you learn well from video, this video introducing the NinjaScript editor is an excellent resource,


                    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...



                    You will find reference samples online as well as some tips and tricks for both indicators and strategies:




                    These samples can be downloaded, installed and modified from NinjaTrader and hopefully serve as a good base for your custom works.


                    There is a also a growing library of user submitted custom indicators (100+) and strategies that can be downloaded from our support form. Please look in the NinjaScript file sharing section of our support forum as you may find what you are looking for there:





                    Finally, the following link is to our help guide with an alphabetical reference list to all supported methods, properties, and objects that are used in NinjaScript.
                    http://ninjatrader.com/support/helpG..._reference.htm

                    Comment


                      #11
                      Hello Chelsea,
                      I was running additional tests on the "SelectSeriesForIndicator" Optimizing does work normally if "Optimize Data Series" is left unchecked, but if checked it adopts the price data series regardless of the selected indicator series during backtesting. Perhaps you already noticed that.
                      Last edited by DuggyLou; 05-13-2017, 07:37 AM.

                      Comment


                        #12
                        Hello DuggyLou,

                        Our development has provided tracking IDs for these items.

                        The behavior 'Strategy indicator not plotting when initialized with added series with greater interval than primary interval and added to the chart' is being tracked with ID #NTEIGHT-11686.

                        The behavior 'Strategy indicator input series defaulting to primary series when 'Optimize Data Series' is enabled in an optimization' is being tracked with ID #NTEIGHT-11696.

                        As new releases of NinjaTrader are available, check for these items being fixed in an upcoming release in the release notes.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ScottWalsh, Today, 04:29 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post ScottWalsh  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        2 responses
                        21 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by tsantospinto, 04-12-2024, 07:04 PM
                        5 responses
                        69 views
                        0 likes
                        Last Post tsantospinto  
                        Started by cre8able, Today, 03:20 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post cre8able  
                        Started by Fran888, 02-16-2024, 10:48 AM
                        3 responses
                        49 views
                        0 likes
                        Last Post Sam2515
                        by Sam2515
                         
                        Working...
                        X