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 futtrader, 04-21-2024, 01:50 AM
        5 responses
        56 views
        0 likes
        Last Post NinjaTrader_Eduardo  
        Started by PeakTry, Today, 10:49 AM
        0 responses
        2 views
        0 likes
        Last Post PeakTry
        by PeakTry
         
        Started by llanqui, Today, 10:32 AM
        0 responses
        5 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by StockTrader88, 03-06-2021, 08:58 AM
        45 responses
        3,992 views
        3 likes
        Last Post johntraderuser2  
        Started by TAJTrades, Today, 09:46 AM
        0 responses
        8 views
        0 likes
        Last Post TAJTrades  
        Working...
        X