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

MultiTimeFrame issues

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

    MultiTimeFrame issues

    Hello,
    I'm attempting to make a multi-time frame stochastic indicator. I'm adding a second time series (10 minute in this case). I think it's successful when applied to certain time charts. However, I'm receiving error messages when applied to larger timeframes like 15 or 60 minute. I've used the
    Code:
    if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired...
    but there's something else missing or incorrect.

    =====================
    Bars.BarsData.Period: 1 Min
    BarsType: NinjaTrader.Data.MinuteBarsType
    104: Error: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.Collections.ArrayList.get_Item(Int32 index)
    at NinjaTrader.Data.DataSeries.Set(Double value)
    at NinjaTrader.Indicator.MTF_Stochastics_ChartControl _v02.OnBarUpdate()
    I'm not aware how to modify the code to avoid this situation. If there's a way to make it a multiple of the chart on which it is applied, that is what I'm trying to achieve.
    Any help you can give me is much appreciated.
    kz
    Attached Files
    Last edited by zeller4; 08-16-2014, 03:17 PM.

    #2
    Hello Zeller4,

    Thank you for your post.

    something in the code is calling an index value that is bigger than the actual size of the collection.

    Like accessing 5 when there are only 4 objects in the collection.

    You would want to run through some prints in the code to see where it might be breaking the script.
    http://www.ninjatrader.com/support/h...html?print.htm
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I've read the help section "standard answer" of why it happens. Unfortunately, it has to do with something about bars required, days loaded, or some way of checking higher time frames against added dataseries time frames... Do you have some specific help you could offer?

      Comment


        #4
        The problem might be here

        Code:
        if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[1] < per){
                        Direction.Set(0);
                        Signal.Set(0);
                        DirectionMTF.Set(0);
                        SignalMTF.Set(0);
                        
                        return;
                    }
        In some cases you try to set values when there are no bars.

        Try


        Code:
        if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[1] < per){
                        
                        return;
                    }
        instead.

        Comment


          #5
          Thanks Harry,
          Do you have a suggestion how or where I need to set these initial zero values then?

          Kirk

          Comment


            #6
            Originally posted by zeller4 View Post
            Thanks Harry,
            Do you have a suggestion how or where I need to set these initial zero values then?

            Kirk
            I would also change line 96:

            Code:
            _stoch = Stochastics(Closes[0], periodD, periodK, smooth);
            If you wish to set values to the DataSeries objects, you need to check whether BarsInProgress == 0, so you could use the code

            Code:
            if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[1] < per){
                            if(BarsInProgress == 0){
                               Direction.Set(0);
                               Signal.Set(0);
                               DirectionMTF.Set(0);
                               SignalMTF.Set(0);
                            }
                            return;
                        }
            In that case the value will only be set when there is a current bar of the first Bars object.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DayTradingDEMON, Today, 09:28 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            8 responses
            31 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by helpwanted, Today, 03:06 AM
            2 responses
            22 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by navyguy06, Today, 09:28 AM
            0 responses
            5 views
            0 likes
            Last Post navyguy06  
            Started by rjbtrade1, 11-30-2023, 04:38 PM
            2 responses
            77 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Working...
            X