• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Zenersev, 10-19-2019, 02:11 PM
        7 responses
        52 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by Lancer, Today, 10:39 AM
        4 responses
        24 views
        0 likes
        Last Post Lancer
        by Lancer
         
        Started by koganam, Today, 11:50 AM
        2 responses
        12 views
        0 likes
        Last Post koganam
        by koganam
         
        Started by koganam, Today, 10:33 AM
        4 responses
        14 views
        0 likes
        Last Post koganam
        by koganam
         
        Started by FREEN, Today, 10:17 AM
        4 responses
        12 views
        0 likes
        Last Post FREEN
        by FREEN
         
        Working...
        X