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

ROC Indicator

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

    ROC Indicator

    I have a strategy that uses ROC indicator and compares current price with price that was 40 bars ago. I am running this stragtegy on stock for which I have 1 min data from Aug 2014 to March 2015, I back-tested strategy from 1st October 2014 to 1st March 2015

    When I examined back test results, I realized that Ninja was computing ROC of first 40 candles incorrectly. It was computing ROC relative to the very first Candle of 1st October and not looking back into any earlier data even though it existed. This causes strategy to enter trade little sooner.

    Reason for premature trades is fairly obvious once I saw the ROC code. First line of ROC sets barsAgo to lesser of CurrentBar and Period.

    protected override void OnBarUpdate()
    {
    int barsAgo = Math.Min(CurrentBar, Period);
    Value.Set(((Input[0] - Input[barsAgo]) / Input[barsAgo]) * 100);
    }

    Question one When Ninja has data of September, why did it not use that data to compute ROC?

    Question 2) Is there a way to make Ninja look at data immediately prior to back test dates? I want to make Ninja use data for computing/plotting but not taking back-test trades.

    I also happen to have Amibroker with identical data. Amibroker back-test did compute ROC of first 40 candles relative to actual 40th Candle in september. Net net, Amibroker handles strategy as I expected ...

    #2
    For the purpose of calculating indicator values, NinjaTrader processes the bars loaded by the chart.

    Each indicator applied to a chart has a training period. During this period the indicator either does not show any values or the values should not be used for the purpose of trading or backtesting.

    If you backtest a strategy, you need to make sure that no trade is entered while one of the indicators used has not yet completed its training period. This requires that you enter a second time line, which is used as a starting point for entering trades. Unfortunately, the second time line needs to be coded into the strategy manually.

    first timeline: sets the time for the first bar on your chart
    second timeline: sets the time for the start of the backtest

    The time between the first and second timeline should be sufficient to allow for the training of all indicators (see screenshot attached).
    Attached Files

    Comment


      #3
      ROC Indicator

      Harry

      Thank you....

      Yes, having two start times; One for the Indicator calculations and another for strategy to look for trading would solve the problem (as long as they are sufficiently spaced apart).

      Are you in position to send me the code snippet that created the image that you had attached in the earlier post? Alternatively, pls send me at least, the snippet/lead/directions on how to go about creating the necessary code.

      Just off the top of my head, I think I could add if statement encapsulating entire strategy

      if (CurrrentBar > 50) { <Entire Strategy Execution> ... }

      but is that right? and more importantly, is that an elegant way to go about it?
      Last edited by cdjindia; 04-05-2015, 01:13 AM.

      Comment


        #4
        Originally posted by cdjindia View Post
        Harry

        Thank you....

        Yes, having two start times; One for the Indicator calculations and another for strategy to look for trading would solve the problem (as long as they are sufficiently spaced apart).

        Are you in position to send me the code snippet that created the image that you had attached in the earlier post? Alternatively, pls send me at least, the snippet/lead/directions on how to go about creating the necessary code.

        Just off the top of my head, I think I could add if statement encapsulating entire strategy

        if (CurrrentBar > 50) { <Entire Strategy Execution> ... }

        but is that right? and more importantly, is that an elegant way to go about it?
        This is correct. But please make sure

        - to encapsulate the part of the strategy that triggers the orders
        - but not to encapsulate the part of the strategy that calculates the indicator values

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Max238, Today, 01:28 AM
        2 responses
        26 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by Shansen, 08-30-2019, 10:18 PM
        25 responses
        949 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        8 responses
        41 views
        0 likes
        Last Post JonesJoker  
        Started by timko, Today, 06:45 AM
        0 responses
        5 views
        0 likes
        Last Post timko
        by timko
         
        Started by Waxavi, 04-19-2024, 02:10 AM
        2 responses
        40 views
        0 likes
        Last Post poeds
        by poeds
         
        Working...
        X