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

Strategy analyzer simulate all possibilities

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

    Strategy analyzer simulate all possibilities

    Hi,

    once (a few months ago) it was possible on the strategy analyzer in addition to optimization it was possible to use a simulator that simulated all the possibilities. How can i still use that simulation mode on the strategy analyzer?

    #2
    Hello Apo84,

    Thanks for your post.

    You could use the Strategy Analyzer to backtest a strategy or optimize a strategy to see how it might perform over historical data.

    Backtesting: https://ninjatrader.com/support/help...a_strategy.htm
    Optimization: https://ninjatrader.com/support/help...a_strategy.htm

    A Genetic Optimization could be run to attempt to find the most optimal set of parameters for a strategy.

    Genetic Optimization: https://ninjatrader.com/support/help..._algorithm.htm

    The Monte Carlo Simulation could be used in the Strategy Analyzer as well. This is a mathematical technique that uses repeated random sampling ("sampling with replacement") to compute a range of possible results with their respective probability. NinjaTrader runs Monte Carlo Simulation by randomly combining the trade results in a defined series of simulations.

    Monte Carlo Simulation: https://ninjatrader.com/support/help...o_simulati.htm

    Strategy Analyzer: https://ninjatrader.com/support/help...y_analyzer.htm

    Please let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the answer.

      I need to test a strategy without optimization for a range of values. Was it once possible, is it still possible? if so how?
      I need this to see some prints on Window Output. With optimization it ruins my prints.
      Alberto
      Last edited by Apo84; 02-13-2023, 03:43 AM.

      Comment


        #4
        Hello Alberto,

        Thanks for your note.

        If you do not want to run an optimization, you could run a backtest on your strategy and see the strategy's prints print out to the NinjaScript Output window. This allows you to test how your strategy might have behaved on historical (past) data.

        See the backtesting help guide page linked above for information about how to run a backtest using the Strategy Analyzer.

        Also, please review the help guide document on the differences on real-time vs backtest (historical).
        http://ninjatrader.com/support/helpG...ime_vs_bac.htm

        Let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the answer.

          I know how the Strategy Analyzer works. Until some time ago with the Strategy Analyzer it was possible to use an option that allowed to have a range in the parameters (fast: 5;20;5), but not using the optimization. So you can see the correct printout on the Output.
          Is it possible?

          thanks Alberto

          Comment


            #6
            Hello Alberto,

            Thanks for your note.

            The only option in the Strategy Analyzer that allows you to test a range of values for parameters as you have mentioned would be by running an Optimization. When running a Backtest, there are no options available to test a range of values.

            Optimization is the process of testing a range of values through iterative backtests to determine the optimal input values over the historical test period based on your optimization fitness.

            If you want to test the range of values for a parameter, an Optimization would need to be run in the Strategy Analyzer.

            Please let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              So there is no longer the possibility to test all range of values for parameters?
              I'll have to change the code so that it displays all the tests on the Output correctly.
              Thanks Alberto

              Comment


                #8
                Hello Alberto,

                Thanks for your note.

                To test all range of values for parameters, you would run an Optimization in the Strategy Analyzer.

                There are no Backtest options for testing a range of values for parameters.

                Let me know if you have further questions.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Is there the possibility using the Optimization to have the calculations of all the possible combinations of the parameters in order to print correctly on the Output?

                  Thanks Alberto

                  Comment


                    #10
                    Hello Alberto,

                    Thanks for your note.

                    Optimization is the process of testing a range of values through iterative backtests to determine the optimal input values over the historical test period based on your optimization fitness.

                    Prints will appear in the NinjaScript Output window when an Optimization is run and the prints will reflect the values calculated by the optimization run.

                    When you mention the prints aren't correct, what exactly are you referring to?

                    I look forward to assisting further.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #11
                      I created a strategy that never enters the market, it simply uses historical data to create statistics. I have two parameters:

                      Points: 5;20;5
                      PointsToEntry: 1;5;2

                      When I use Optimization on the "Strategy Analyzer", I would like to see on the "Ninjascript Output":



                      Points: 5
                      PointsToEntry: 1
                      ....
                      Points: 5
                      PointsToEntry: 3
                      ....
                      Points: 5
                      PointsToEntry: 5
                      ....
                      Points: 10
                      PointsToEntry: 1
                      ....
                      Points: 10
                      PointsToEntry: 3
                      ....
                      Points: 10
                      PointsToEntry: 5
                      ....

                      etc until
                      Points: 20
                      PointsToEntry: 5
                      ....


                      Instead I see:


                      Points: 10
                      PointsToEntry: 5
                      Points: 5
                      Points: 5
                      PointsToEntry: 1
                      PointsToEntry: 3
                      Points: 5
                      PointsToEntry: 5
                      Points: 15
                      PointsToEntry: 1
                      Points: 20
                      PointsToEntry: 5
                      Points: 10
                      PointsToEntry: 1
                      Points: 10
                      PointsToEntry: 3
                      Points: 20
                      PointsToEntry: 3
                      Points: 20
                      PointsToEntry: 1
                      Points: 15
                      PointsToEntry: 5​
                      ....

                      Is it possible for Optimization to perform all steps without optimization?

                      Thanks Alberto​

                      Comment


                        #12
                        The Strategy Analyzer tries to optimize the simulation, I would like him to perform all the steps without skipping them and in order.

                        Comment


                          #13
                          Posting the simplified code, I didn't write the other variables and for other reasons I simulate one day at a time.



                          //This namespace holds Strategies in this folder and is required. Do not change it.
                          namespace NinjaTrader.NinjaScript.Strategies
                          {
                          public class testStrategyN11022023: Strategy
                          {
                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"Enter the description for your new custom Strategy here.";
                          Name = "testStrategyN11022023";
                          Calculate = Calculate.OnEachTick;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy = false;
                          ExitOnSessionCloseSeconds = 30;
                          IsFillLimitOnTouch = true;
                          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                          OrderFillResolution = OrderFillResolution.Standard;
                          Slippage = 0;
                          StartBehavior = StartBehavior.WaitUntilFlat;
                          TimeInForce = TimeInForce.Gtc;
                          TraceOrders = false;
                          RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                          StopTargetHandling = StopTargetHandling.PerEntryExecution;
                          BarsRequiredToTrade = 1;
                          IsUnmanaged = true;
                          // Disable this property for performance gains in Strategy Analyzer optimizations
                          // See the Help Guide for additional information
                          IsInstantiatedOnEachOptimizationIteration = true;

                          PointsToEntry = 0;
                          PointsToAttention = 2;

                          }
                          else if (State == State.Configure)
                          {
                          AddDataSeries(Data.BarsPeriodType.Tick, 1);
                          }
                          else if (State == State.DataLoaded)
                          {
                          /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
                          // ClearOutputWindow();
                          /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
                          ctrlStamp = false;
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          if ( CurrentBars[0]<BarsRequiredToTrade )
                          return;
                          /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
                          if ( !ctrlStamp )
                          {
                          Print ( string.Format(" Points: {0} ", Points));
                          Print ( string.Format(" PointsToEntry: {0} ", PointsToEntry));
                          ctrlStamp = true;
                          }
                          /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
                          if ( Times[1][0].TimeOfDay>=dateTimeInitialTimeToTrade.TimeOfDay && Times[1][0].TimeOfDay<dateTimeLastTimeToTrade.TimeOfDay )
                          {
                          if ( BarsInProgress==1 && IsFirstTickOfBar )
                          {

                          if ( Closes[1][0]<=(EnterLong1 + PointsToAttention) && !ctrlLongAttentionDistance1 && !ctrlLongEnter1 && !ctrlLongTrade1 )
                          {
                          ctrlLongAttentionDistance1 = true;
                          // Print ( string.Format(" {0} - LONG 1 under: {1} ", Times[1][0], PointsToAttention ) );
                          Print ( string.Format( "LONG" ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }

                          if ( Closes[1][0]>=(EnterLong1 + PointsToNullTrade) && ctrlLongAttentionDistance1 && !ctrlLongEnter1 && !ctrlLongTrade1 )
                          {
                          ctrlLongTrade1 = true;
                          // Print ( string.Format(" {0} - LONG 1 null: {1} ", Times[1][0], PointsToNullTrade ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }

                          if ( Closes[1][0]<=(EnterLong1 + PointsToEntry) && ctrlLongAttentionDistance1 && !ctrlLongEnter1 && !ctrlLongTrade1 )
                          {
                          ctrlLongEnter1 = true;
                          // Print ( string.Format(" {0} - LONG 1 entry: {1} ", Times[1][0], (EnterLong1 + PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }
                          if ( ( Closes[1][0]>(EnterLong1 + Points) || Closes[1][0]<=(EnterLong1 - Points) ) && ctrlLongAttentionDistance1 && ctrlLongEnter1 && !ctrlLongTrade1 )
                          {
                          if ( Closes[1][0]>(EnterLong1 + Points) )
                          {
                          // Print ( string.Format(" {0} - LONG 1 WIN: {1} ", Times[1][0], (EnterLong1 + PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          Print ( string.Format("G") );
                          Print ( string.Format("") );
                          }
                          if ( Closes[1][0]<=(EnterLong1 - Points) )
                          {
                          // Print ( string.Format(" {0} - LONG 1 LOSS: {1} ", Times[1][0], (EnterLong1 - PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          Print ( string.Format("L") );
                          Print ( string.Format("") );
                          }
                          ctrlLongTrade1 = true;
                          }
                          /*-----------------------------------------------------------------------------------------------------------------------------*/
                          if ( Closes[1][0]>=(EnterShort1 - PointsToAttention) && !ctrlShortAttentionDistance1 && !ctrlShortEnter1 && !ctrlShortTrade1 )
                          {
                          ctrlShortAttentionDistance1 = true;
                          // Print ( string.Format(" {0} - SHORT 1 under: {1} ", Times[1][0], PointsToAttention ) );
                          Print ( string.Format( "SHORT" ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }

                          if ( Closes[1][0]<=(EnterShort1 - PointsToNullTrade) && ctrlShortAttentionDistance1 && !ctrlShortEnter1 && !ctrlShortTrade1 )
                          {
                          ctrlShortTrade1 = true;
                          // Print ( string.Format(" {0} - SHORT 1 null: {1} ", Times[1][0], PointsToNullTrade ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }

                          if ( Closes[1][0]>=(EnterShort1 - PointsToEntry) && ctrlShortAttentionDistance1 && !ctrlShortEnter1 && !ctrlShortTrade1 )
                          {
                          ctrlShortEnter1 = true;
                          // Print ( string.Format(" {0} - SHORT 1 entry: {1} ", Times[1][0], (EnterShort1 + PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          }
                          if ( ( Closes[1][0]<(EnterShort1 - Points) || Closes[1][0]>=(EnterShort1 + Points) ) && ctrlShortAttentionDistance1 && ctrlShortEnter1 && !ctrlShortTrade1 )
                          {
                          if ( Closes[1][0]<(EnterShort1 - Points) )
                          {
                          // Print ( string.Format(" {0} - SHORT 1 WIN: {1} ", Times[1][0], (EnterShort1 - PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          Print ( string.Format("G") );
                          Print ( string.Format("") );
                          }
                          if ( Closes[1][0]>=(EnterShort1 + Points) )
                          {
                          // Print ( string.Format(" {0} - SHORT 1 LOSS: {1} ", Times[1][0], (EnterShort1 + PointsToEntry) ) );
                          Print ( string.Format("{0}", Times[1][0]) );
                          Print ( string.Format("L") );
                          Print ( string.Format("") );
                          }
                          ctrlShortTrade1 = true;
                          }
                          }
                          }
                          /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

                          }

                          region Properties

                          [NinjaScriptProperty]
                          [Display(Name="Points", Order=1, GroupName="Parameters")]
                          public double Points
                          { get; set; }

                          [NinjaScriptProperty]
                          [Display(Name="PointsToEntry", Order=2, GroupName="Parameters")]
                          public double PointsToEntry
                          { get; set; }

                          #endregion
                          }
                          }​

                          Comment


                            #14
                            Hello Alberto,

                            Thanks for that information.

                            Unfortunately, there are no options for forcing the optimization iterations to occur in a specific order. This is how the Optimization feature in the Strategy Analyzer is made to work in order to find the optimal combination of input values of parameters based on the best optimization fitness.

                            I have submitted a feature request to the Development team regarding having optmization iterations occur in a set order as you described. This request is being tracked under the number SFT-5770.

                            As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                            Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                            Please let us know if we may be of further assistance to you.​
                            Brandon H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by halgo_boulder, Today, 08:44 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post halgo_boulder  
                            Started by drewski1980, Today, 08:24 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post drewski1980  
                            Started by rdtdale, Yesterday, 01:02 PM
                            2 responses
                            17 views
                            0 likes
                            Last Post rdtdale
                            by rdtdale
                             
                            Started by TradeSaber, Today, 07:18 AM
                            0 responses
                            7 views
                            0 likes
                            Last Post TradeSaber  
                            Started by PaulMohn, Today, 05:00 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post PaulMohn  
                            Working...
                            X