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

Multiple Timeframe trading back testing issues

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

    Multiple Timeframe trading back testing issues

    I am developing a strategy where I am trading on ranged bars intraday, but want to include an 7 day Average Daily Range indicator that runs on daily bars. I am seeing some odd issues with the calculation of the ADR being left at 0, while other times it calculates fine.

    The indicator I am referring to is here:


    Then I am using it like this:

    Code:
     protected override void Initialize()
     {
    	Add(PeriodType.Day, 1);
    	...
     }
     
     protected override void OnBarUpdate()
     {
    	_stopAdr = RangePT(BarsArray[1], .1, 7).RAPT[0];
     }
    However the _stopAdr above, or even the regular ADR (if I don't give the .1 percentage), ends up as 0. Is there something wrong with the code, or something with backtesting that I am doing wrong?

    #2
    Hello banach,

    You may see the following error in your log:
    Error on calling 'OnBarUpdate' method for indicator 'YourIndicatorName' on bar 0: You are accessing an index with a value that is invalid since its out of range

    Basically you are calling the indicator before the first bar of the secondary series (the 1 day series) has occurred.

    Please see this working updated code:
    Code:
    protected override void Initialize()
    {
        Overlay				= false;
    	Add(PeriodType.Day, 1);
    }
    protected override void OnBarUpdate()
    {
    	if(CurrentBars[1] < 1) return;
    	Print(RangePT(BarsArray[1], 0.1, 7).RAPT[0]);
    }
    Please let me know if you continue to experience difficulties or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      When I add the Overlay = false to Initialize() it won't even compile. It tells me Overlay doesnt exist in the current context.

      Furthermore, when I connect to real-time data and run the strategy, the CurrentBars[1] always has a value of 0 in it, even though I am getting valid values back from the RangePT indicator for BarsArray[1].

      Comment


        #4
        Hello banach,

        I apologize for accidentally including Overlay = false. I was testing in a slightly different setup instead and that is not relevant to your situation.

        What I was trying to convey is that you have to make sure the BarsArray has at least 1 bar before passing it to the indicator.

        I highly recommend reading through our Help Guide document to get better acquainted with how CurrentBars[1] works and how multi-timeframe strategies work in general: http://ninjatrader.com/support/helpG...lightsub=multi

        Please make sure to check your Days To Load property in your Data Series window (Right click chart -> Data Series) to verify that you are loading more than 1 day of data, or CurrentBars[1] will never be greater than 0).

        Please let me know if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by r68cervera, Today, 05:29 AM
        0 responses
        2 views
        0 likes
        Last Post r68cervera  
        Started by geddyisodin, Today, 05:20 AM
        0 responses
        3 views
        0 likes
        Last Post geddyisodin  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        34 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,239 views
        0 likes
        Last Post Leafcutter  
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        6 views
        0 likes
        Last Post AveryFlynn  
        Working...
        X