Is this a bug or bad coding?

Questions about MultiCharts .NET and user contributed studies.
Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Is this a bug or bad coding?

Postby Ram » 02 Feb 2015

I have an array of trend lines, i use it for setting dynamic patterns with multiple legs, I set the number of legs via the indicator input, the problem seems to be that if i load the indicator with a default value of 4 for ex. and then change it to a bigger number using the user interface I get an error of "Object Reference Not Set" meaning when changing the input the "Protected Overrides Sub Create()" doesn't fire and set the new number of trend lines..

here's a code sample to reproduce this:

Code: Select all

Imports System
Imports System.Drawing
Imports PowerLanguage
Imports PowerLanguage.Indicator
Imports PowerLanguage.Function
Imports System.Linq

Namespace PowerLanguage.Indicator
Public Class Henry_Bug_v1
Inherits IndicatorObject

Public Sub New(ByVal _ctx As Object)
MyBase.New(_ctx)
Number_Of_legs = 4
End Sub

<Input()> Public Property Number_Of_legs As Integer
Private TrendLine_Item(10) As VariableObject(Of ITrendLineObject)

Protected Overrides Sub CalcBar()

End Sub

Protected Overrides Sub Create()
For i As Integer = 0 to Number_Of_legs
Me.TrendLine_Item(i) = New VariableObject(Of ITrendLineObject)(Me)
Next i
End Sub

Protected Overrides Sub StartCalc()
For i As Integer = 0 to Number_Of_legs
Me.TrendLine_Item(i).Value = DrwTrendLine.Create(New ChartPoint(Bars.Time.Item(0), 0), New ChartPoint(Bars.Time.Item(0), 0))
Next i
End Sub

End Class
End Namespace
once compiled add it to a chart.

next, change the "Number_Of_legs" input to a higher value and get this error
Image

Image

The easy fix is to set the input to the max array number but its just a workaround..

Another small but annoying thing is when setting "VariableObject(Of ITrendLineObject)" as array like so:

Code: Select all

Private TrendLine_Item(10) As VariableObject(Of ITrendLineObject)
the code auto complete doesn't work well and suggest wrong object (should have shown the "Value"):
Image

if trying to use the ".End.Price" for ex. as the auto complete suggest I get an error, if I add the ".Value" by hand then the code compiles..

Best,
R.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Is this a bug or bad coding?

Postby Henry MultiСharts » 04 Feb 2015

Hello Ram,

Create method is called once after the study is created. When input is modified - Create method has been called already. You need to move the code that fills the array from Create to StartCalc. You also need to redefine the StopCalc method - remove the drawings and clear the array there.

Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Re: Is this a bug or bad coding?

Postby Ram » 04 Feb 2015

Hello Ram,

Create method is called once after the study is created. When input is modified - Create method has been called already. You need to move the code that fills the array from Create to StartCalc. You also need to redefine the StopCalc method - remove the drawings and clear the array there.
Bad coding it is then :)
Thx much.


Return to “MultiCharts .NET”