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

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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by frankthearm, Today, 09:08 AM
        7 responses
        28 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by NRITV, Today, 01:15 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by maybeimnotrader, Yesterday, 05:46 PM
        5 responses
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by quantismo, Yesterday, 05:13 PM
        2 responses
        16 views
        0 likes
        Last Post quantismo  
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X