Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing parameters during testing

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

    Changing parameters during testing

    Hi

    Sorry I browsed around but really couldnt find the right info on this.
    My question is simply how do I change the parameters of an indicator in a backtest?

    For example - I have a moving average crossover strategy
    In the year 2014 the EMA's must be 14 by 20
    In the year 2015 the EMA's must be 20 by 30
    In the year 2016 the EMA's must be 15 by 18 etc

    Thank you


    #2
    Hello bchip,

    Thanks for your post.

    Indicators can be called with the following syntax:

    double value = EMA(20)[0];

    Where 20 is the period. You could create logic that checks if the timestamp of the currentbar (Time[0]) has a year of X. Time[0] is a DateTime object and you can check its Year property to check the year. If the year meets your criteria, you can use a different period for the EMA. Publicly available information on DateTime.Year is includes below.



    Documentation on EMA indicator methods are linked here - https://ninjatrader.com/support/help...onential_e.htm

    Please let us know if you have any additional questions.

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello bchip,

      Thanks for your post.

      Indicators can be called with the following syntax:

      double value = EMA(20)[0];

      Where 20 is the period. You could create logic that checks if the timestamp of the currentbar (Time[0]) has a year of X. Time[0] is a DateTime object and you can check its Year property to check the year. If the year meets your criteria, you can use a different period for the EMA. Publicly available information on DateTime.Year is includes below.
      Thanks.
      Yes I would simply use the Time[0].Year to check which year, but I'm more interested in where do I change the parameters?
      If my understanding is correct
      OnStateChange() -> SetDefaults : Only runs 1 before the backtest is started
      OnStateChange() -> Configure : change here for optimizations (not for backtests)

      So the last place is then in OnBarUpdate()

      If (Time[0].Year == 2014) {
      double value = EMA(14)[0];
      double value = EMA(20)[0];
      if (crossabove...)

      } else if (Time[0].Year == 2015)
      {
      double value = EMA(20)[0];
      double value = EMA(30)[0];
      if (crossabove...)

      } else if (Time[0].Year == 2016)
      {
      double value = EMA(15)[0];
      double value = EMA(20)[0];
      if (crossabove...)

      }

      or
      If (Time[0].Year == 2014) {
      x=14;
      y=20;
      }

      double value = EMA(x)[0];
      double value = EMA(y)[0];


      Is this the right way to do it?
      Last edited by bchip; 10-09-2019, 09:18 AM.

      Comment


        #4
        Hello bchip,

        What you have posted will not compile as you are trying to create multiple double value variables in the same scope.

        int x, y;

        If (Time[0].Year == 2014) {
        x=14;
        y=20;
        }
        else
        {
        x = 1;
        y = 1;
        }

        double value = EMA(x)[0];
        double value2 = EMA(y)[0];


        The above would compile and could move you forward. I recommend using the Strategy Builder to create simple logic and using the View Code button to see the resulting code to better understand how to write proper syntax. While we do not provide programming education services in the support department, we do have some light programming education material in the NinjaTrader 7 Help Guide and more robust materials on C# can be found external to NinjaTrader.

        NT7 Basic Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

        Please let us know if we can be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        30 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X