Tried to use custom indicator that I have built in "Building Block" and get the following error messages:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at WealthLab.MyIndicators.swingLOW.Populate()
at WealthLab.Indicators.IndicatorFactory.ReconcileIndicator(IndicatorBase ib, BarHistory bh, List`1 indicators)
at WealthLab.Indicators.IndicatorFactory.ReconcileDummy(IndicatorBase ib)
at WealthLab.Core.Parameter.GetIndicatorDesc()
at WealthLab.Backtest.LimitStopEntryExit.get_Description()
at WealthLab.Backtest.SellAtLimitStop.get_Description()
at WealthLab8.ucBuildingBlockPanel.ApplyParameters(ParameterList allParameters)
at WealthLab8.BuildingBlockContainer.RemoveBlock(ucBuildingBlockPanel bbp, Boolean applyParameterChanges)
at WealthLab8.ucBuildingBlockPanel.CreateDecorator(Object reference, RoutedEventArgs connection)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at WealthLab.WPF.WLButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
How can I fix the issue?
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at WealthLab.MyIndicators.swingLOW.Populate()
at WealthLab.Indicators.IndicatorFactory.ReconcileIndicator(IndicatorBase ib, BarHistory bh, List`1 indicators)
at WealthLab.Indicators.IndicatorFactory.ReconcileDummy(IndicatorBase ib)
at WealthLab.Core.Parameter.GetIndicatorDesc()
at WealthLab.Backtest.LimitStopEntryExit.get_Description()
at WealthLab.Backtest.SellAtLimitStop.get_Description()
at WealthLab8.ucBuildingBlockPanel.ApplyParameters(ParameterList allParameters)
at WealthLab8.BuildingBlockContainer.RemoveBlock(ucBuildingBlockPanel bbp, Boolean applyParameterChanges)
at WealthLab8.ucBuildingBlockPanel.CreateDecorator(Object reference, RoutedEventArgs connection)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at WealthLab.WPF.WLButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
How can I fix the issue?
Rename
Chances are there is a bug in your custom indicator's (undisclosed) code that has to be fixed prior to be used in Blocks.
I want to revisit an issue that I raised quite some time ago. The code of my custom indicator is shown below.
These other custom indicators that I wrote work perfectly when used in the charting environment. For example, the previous LOW indicator was drawn on the Price pane when it was dragged to a chart.
However, when I tried to key in any custom indicator name in the CODE BLOCK indicator field, the error message shown in the earlier post came out.
Is there any configuration that I need to set in order to use Custom indicator in CODE BLOCK. I checked my indicator code and did not find any potential error in it.
Please advise.
The code of my custom indicator is as follows:
These other custom indicators that I wrote work perfectly when used in the charting environment. For example, the previous LOW indicator was drawn on the Price pane when it was dragged to a chart.
However, when I tried to key in any custom indicator name in the CODE BLOCK indicator field, the error message shown in the earlier post came out.
Is there any configuration that I need to set in order to use Custom indicator in CODE BLOCK. I checked my indicator code and did not find any potential error in it.
Please advise.
The code of my custom indicator is as follows:
CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.MyIndicators { public class prevLOW : IndicatorBase { //parameterless constructor public prevLOW() : base() { } //for code based construction public prevLOW(TimeSeries source, Int32 lookbackper) : base() { Parameters[0].Value = source; //Parameters[1].Value = lookbackper; Populate(); } //static Series method public static prevLOW Series(TimeSeries source, Int32 lookbackper) { return new prevLOW(source, lookbackper); } //name public override string Name { get { return "prevLOW"; } } //abbreviation public override string Abbreviation { get { return "prevLOW"; } } //description public override string HelpDescription { get { return "The local LOW preceding the current Bar. Can be used as STOP LOSS for RISK MANAGEMENT."; } } //price pane public override string PaneTag { get { return "Price"; } } //default color public override WLColor DefaultColor { get { return WLColor.FromArgb(255,46,139,87); } } //default plot style public override PlotStyle DefaultPlotStyle { get { return PlotStyle.Line; } } //populate public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; //Int32 lookbackper = Parameters[1].AsInt; DateTimes = source.DateTimes; //modify the code below to implement your own indicator calculation /* for (int n = 0; n < source.Count; n++) { Values[n] = source[n]; } */ Values[0] = source[0]; Values[1] = Math.Min(source[0], source[1]); Values[2] = Math.Min(Values[1], source[2]); for (int n = 3; n < source.Count; n++) { Values[n] = Values[n - 1]; if ((source[n - 2] < source[n - 3]) && (source[n - 2] < source[n - 1])) { Values[n] = source[n - 2]; } } } //generate parameters protected override void GenerateParameters() { AddParameter("Source", ParameterType.TimeSeries, PriceComponent.Low); //AddParameter("lookbackPer", ParameterType.Int32, 250); } } }
QUOTE:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at WealthLab.MyIndicators.swingLOW.Populate()
So the error we're talking about is in the swingLOW code, and not the prevLOW code. So my question is why provide the prevLOW code at all when swingLOW is the real culprit?
Several other comments:
1) It's a C# standard to start all class names with a capital letter. So prevLOW and swingLOW should be renamed PrevLow and SwingLow (camel case) to follow with C# convention.
2) The namespace should be called "WealthLab.Indicators" not "WealthLab.MyIndicators". This is significant so the compiler checks to be sure there aren't any name conflicts within WealthLab.Indicators when compiling your code. You definitely want that check.
3) Why are you including using statements you don't need in your prevLOW code?
CODE:
using System; using System.Drawing; using WealthLab.Indicators;
My apology for the confusion in my message. The Error Message was based on an older version of the code.
The current error message is as follows:
================
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at WealthLab.MyIndicators.prevLOW.Populate()
at WealthLab.Indicators.IndicatorFactory.ReconcileIndicator(IndicatorBase ib, BarHistory bh, List`1 indicators)
at WealthLab.Indicators.IndicatorFactory.ReconcileDummy(IndicatorBase ib)
at WealthLab.Core.Parameter.GetIndicatorDesc()
at WealthLab.Backtest.IndicatorCompareIndicator.get_Description()
at WealthLab8.ucBuildingBlockPanel.ApplyParameters(ParameterList allParameters)
at WealthLab8.ucBuildingBlockPanel.paramValueChanged(Object sender, ParameterEventArgs e)
at WealthLab.WPF.ParameterEditorPanel.DeleteRule(Parameter setup)
at WealthLab.WPF.ParameterEditorPanel.ConcatRule(Object asset, SelectionChangedEventArgs vis)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.ComboBox.OnSelectionChanged(SelectionChangedEventArgs e)
at System.Windows.Controls.Primitives.Selector.SelectionChanger.SelectJustThisItem(ItemInfo info, Boolean assumeInItemsCollection)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetCurrentValueInternal(DependencyProperty dp, Object value)
at System.Windows.Controls.ComboBox.TextUpdated(String newText, Boolean textBoxUpdated)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
at System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
at System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
at System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(Tuple`2 postProcessInput, ProcessInputEventArgs processInputEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(Tuple`2 postProcessInput, ProcessInputEventArgs processInputEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
=======================
On point 3), the "Using" statements was generated by the "Code Generator" of the New indicator function.
I tried to figure out what was wrong with the code but couldn't find any clue. When using the indicator for the chart it was OK.
However, when I treid to use this (and any other custom indicators that I have created), I had error message similar to the above.
That's why I was wondering is there any setting or configuration I have missed.
Any advice to me to test?
The current error message is as follows:
================
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.set_Item(Int32 index, T value)
at WealthLab.MyIndicators.prevLOW.Populate()
at WealthLab.Indicators.IndicatorFactory.ReconcileIndicator(IndicatorBase ib, BarHistory bh, List`1 indicators)
at WealthLab.Indicators.IndicatorFactory.ReconcileDummy(IndicatorBase ib)
at WealthLab.Core.Parameter.GetIndicatorDesc()
at WealthLab.Backtest.IndicatorCompareIndicator.get_Description()
at WealthLab8.ucBuildingBlockPanel.ApplyParameters(ParameterList allParameters)
at WealthLab8.ucBuildingBlockPanel.paramValueChanged(Object sender, ParameterEventArgs e)
at WealthLab.WPF.ParameterEditorPanel.DeleteRule(Parameter setup)
at WealthLab.WPF.ParameterEditorPanel.ConcatRule(Object asset, SelectionChangedEventArgs vis)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.ComboBox.OnSelectionChanged(SelectionChangedEventArgs e)
at System.Windows.Controls.Primitives.Selector.SelectionChanger.SelectJustThisItem(ItemInfo info, Boolean assumeInItemsCollection)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetCurrentValueInternal(DependencyProperty dp, Object value)
at System.Windows.Controls.ComboBox.TextUpdated(String newText, Boolean textBoxUpdated)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
at System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
at System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
at System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(Tuple`2 postProcessInput, ProcessInputEventArgs processInputEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(Tuple`2 postProcessInput, ProcessInputEventArgs processInputEventArgs)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
=======================
On point 3), the "Using" statements was generated by the "Code Generator" of the New indicator function.
I tried to figure out what was wrong with the code but couldn't find any clue. When using the indicator for the chart it was OK.
However, when I treid to use this (and any other custom indicators that I have created), I had error message similar to the above.
That's why I was wondering is there any setting or configuration I have missed.
Any advice to me to test?
I will try out your suggestions 1), 2) and 3) and post the result later.
HM
HM
When designing with building blocks there aren't any values in source (your first parameter). But, you're attempting to access source[0] and that's why you get the exception. Do the following in Populate():
CODE:
if (source.Count < 3) return; Values[0] = source[0]; // rest of your code...
QUOTE:
When using building blocks there aren't any values in source [in the Populate() method] ...
Thanks for that fix. I didn't know that, but I have never used Building Blocks.
Thanks. Any the code to check source.count fix the Exception issues in CodeBlock.
Your Response
Post
Edit Post
Login is required