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

Multi-timeframe indicator index out of range

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

    Multi-timeframe indicator index out of range

    I am getting an index out of range error with respect to the Ichimoku. Can you please explain how to fix the error.

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class MyCustomStrategy2 : Strategy
        {
            private SMA smaFast;
            private SMA smaSlow;
    
            private Ichimoku _Ichimoku;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver;
                    Name = "MyCustomStrategy2";
                    Fast = 10;
                    Slow = 25;
                    IsInstantiatedOnEachOptimizationIteration = false;
                }
                else if (State == State.Configure) 
                {
                    AddDataSeries(BarsPeriodType.Minute, 5);
                }
                else if (State == State.DataLoaded)
                {
                    smaFast = SMA(Fast);
                    smaSlow = SMA(Slow);
    
                    smaFast.Plots[0].Brush = Brushes.Goldenrod;
                    smaSlow.Plots[0].Brush = Brushes.SeaGreen;
    
                    AddChartIndicator(smaFast);
                    AddChartIndicator(smaSlow);
    
                    _Ichimoku = Ichimoku(BarsArray[1], true, false, 9, 26, 52, 40, Brushes.Red, Brushes.Green, 26);
    
                    AddChartIndicator(_Ichimoku);
                }
            }
    
            protected override void OnBarUpdate()
            {            
    
                if (CurrentBar < 250)
                    return;
    
                if (CrossAbove(smaFast, smaSlow, 1))
                    EnterLong();
                else if (CrossBelow(smaFast, smaSlow, 1))
                    EnterShort();
    
    
                            // In case the indicator has already been Terminated, you can safely ignore errors
                if (State >= State.Terminated)
                    return;       
            }
    
            #region Properties
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
            public int Fast
            { get; set; }
    
            [Range(1, int.MaxValue), NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
            public int Slow
            { get; set; }
            #endregion
        }
    }

    #2
    Hi Epistemophilic, thanks for your question.

    You can not use AddChartIndicator with an indicator that runs on a secondary series. You would need to replicate the way Ichimoku plots within the strategy, referencing the Plot values of the Ichimoku to fill your own plots.

    Please let me know if you have further questions on this material.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hi Epistemophilic, thanks for your question.

      You can not use AddChartIndicator with an indicator that runs on a secondary series. You would need to replicate the way Ichimoku plots within the strategy, referencing the Plot values of the Ichimoku to fill your own plots.

      Please let me know if you have further questions on this material.
      Do you have an example strat that you can post?

      Comment


        #4
        Hello Epistemophilic, I have attached an example using the Ichimoku cloud indicator. Please see attached.
        Attached Files
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mgco4you, Today, 09:46 PM
        0 responses
        1 view
        0 likes
        Last Post mgco4you  
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        8 views
        0 likes
        Last Post Rapine Heihei  
        Working...
        X