Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate optimized value using DataSeries.

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

    Calculate optimized value using DataSeries.

    I am writing my strategy that using historical data series to calculate optimal value. After obtain the optimal value, it will be used in OnBarUpdate() to execute trade.

    To achieve that, I should be able to calculate in Initialize(). However, I am unable to obtain value, such as Close, in initialize.Close[0], Close[1] etc will always return 0.

    How should I do? Thanks.

    #2
    Hello vhanded,

    Thank you for your post.

    Close[0] will not be assigned in Initialize(). Historical data will be called in OnBarUpdate(). If you need to separate logic based on Historical or real-time you can use the Historical bool: http://www.ninjatrader.com/support/h...historical.htm

    Please let me know if you have any questions.

    Comment


      #3
      Sorry for late reply.

      My strategy consist of 2 steps: calculate a parameter based on historical data, and execute the strategy using the parameter. From my understanding, you are suggesting to use Historical for calculation; while at the end of Historical, and beginning of real trading bar, use the parameter calculated from Historical in real time trading bar?

      Since Historical will always return true for back testing, is that mean, I have to run the back test to calculate the parameter, and execute a separate strategy to test the performance of the parameter?

      Any other way, like, historicalBarOnUpdate(), where it will always execute first, then execute barOnUpdate()?

      Comment


        #4
        Please use this branching in OnBarUpdate:

        if (Historical) {
        // calculate the optimal value
        } else {
        // execute orders in live data
        }

        Thanks.
        Pi
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment


          #5
          Hi Ninza,

          Thanks for your reply.

          Your code snippet will work, if in live trading. However, I can't backtest with it, since Historical will always return true.

          Comment


            #6
            Originally posted by vhanded View Post
            Hi Ninza,

            Thanks for your reply.

            Your code snippet will work, if in live trading. However, I can't backtest with it, since Historical will always return true.
            How do you backtest it?
            Last edited by ninZa; 01-17-2015, 12:57 AM.
            ninZa
            NinjaTrader Ecosystem Vendor - ninZa.co

            Comment


              #7
              Hi Ninza, this is the problem I am facing now.

              For now, I would just run the first 'backtest' strategy with the purpose of finding the parameter, then switch to another proper backtest strategy using that parameters.

              Comment


                #8
                Originally posted by vhanded View Post
                Hi Ninza, this is the problem I am facing now.

                For now, I would just run the first 'backtest' strategy with the purpose of finding the parameter, then switch to another proper backtest strategy using that parameters.
                This sounds redundant.

                Do you use Strategy Analyzer for the backtest?

                Thanks.
                Pi
                ninZa
                NinjaTrader Ecosystem Vendor - ninZa.co

                Comment


                  #9
                  Yes, I do use strategy analyzer to backtest it, and use optimizer to optimize the value. But it does not give me the confident about the 'optimized' parameter.

                  Thanks for your help.

                  Comment


                    #10
                    Originally posted by vhanded View Post
                    Yes, I do use strategy analyzer to backtest it, and use optimizer to optimize the value. But it does not give me the confident about the 'optimized' parameter.

                    Thanks for your help.
                    Ok. Have you tried this approach

                    int N = 200; // you freely define the number

                    if (CurrentBar < N) {

                    // calculate the optimal value

                    } else {

                    // use the optimal value

                    }
                    Thanks.
                    Pi
                    ninZa
                    NinjaTrader Ecosystem Vendor - ninZa.co

                    Comment


                      #11
                      Sounds like a good idea. So I need to have a lot more test data.

                      Thanks!

                      Comment


                        #12
                        Originally posted by vhanded View Post
                        Sounds like a good idea. So I need to have a lot more test data.

                        Thanks!
                        My pleasure!
                        Give it a try vhanded.
                        ninZa
                        NinjaTrader Ecosystem Vendor - ninZa.co

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        673 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        379 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        111 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        577 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        582 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X