Issue with incorrect value of previous bar in data serie

Questions about MultiCharts .NET and user contributed studies.
vincat
Posts: 4
Joined: 24 Aug 2014
Has thanked: 1 time
Been thanked: 4 times

Issue with incorrect value of previous bar in data serie

Postby vincat » 24 Aug 2014

Hi, I'm looking into the possibilities of Multicharts.NET and for a better understanding on how to program in it, I had a go at converting the TTM Squeeze indicator from an easylanguage-version I found on the net.

I've got the indicator almost working, but I encounter a strange issue when referring to the previous bar of the dataseries returned by the "LinearRegValue" function. I use it to determine the coloring in the Momentum Oscillator histogram, but as the previous value is not correct the wrong color is chosen from time to time.

You can see it in the picture below: the momentum is still rising, yet the color for falling momentum is used.
Momentum Curve.PNG
(1.42 KiB) Downloaded 521 times
The current version of the indicator is attached below. If someone with more experience could have a look and check what I did wrong? The issue arises in the CalcBar-method in the "Part 2" section. Was the way I've implemented the LinRegValue function correct? Any other suggestions for improvement?
TTM_Squeeze.pln
(2.01 KiB) Downloaded 495 times
One other thing that is not clear to me is why different helper-functions have to be called in different ways. I.e. AvgTrueRange.AverageTrueRange(this, Length) is a static function, Bars.Close.StandardDeviationCustom(Length, 1) is a DataSeries-method, highestFc, lowestFc, xAverage and linRegValue are separate powerlanguage.net functions and all use different naming conventions for their parameters. Is there an overview of what functions are available and how to use them?

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

Re: Issue with incorrect value of previous bar in data serie

Postby Henry MultiСharts » 25 Aug 2014

Hello vincat,

In order to reference previous values you need to use Series variables. More information can be found here. Please find the fixed version of the code attached.
Attachments
TTM_Squeeze_fix.pln
(2.03 KiB) Downloaded 492 times

vincat
Posts: 4
Joined: 24 Aug 2014
Has thanked: 1 time
Been thanked: 4 times

Re: Issue with incorrect value of previous bar in data serie

Postby vincat » 25 Aug 2014

Hello Henri,

Thank you for the quick reply, the coloring looks ok now. Time to do the final polishing.

So if I understood the issue correctly, the function LinearRegValue() recalculates it's historical values on each new bar? I guess I'll need some extra experimenting to fully understand the internals. :-)

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

Re: Issue with incorrect value of previous bar in data serie

Postby Henry MultiСharts » 26 Aug 2014

So if I understood the issue correctly, the function LinearRegValue() recalculates it's historical values on each new bar?
That is not correct. LinearRegValue is a simple function. It does not have historical values. In order to preserve the historical values of this function you need to assign them to a series variable. It will keep all of the assigned values.


Return to “MultiCharts .NET”