FunctionSimple<T>

Questions about MultiCharts .NET and user contributed studies.
HellGhostEvocatorX
Posts: 81
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

FunctionSimple<T>

Postby HellGhostEvocatorX » 17 May 2023

https://www.multicharts.com/trading-sof ... _Variables

Hello, I took the function from the link as a template to add a simple bar counter as a function. As you can see in the screenshot, it counts up double from one bar to the next. I have tried all the examples from the website, always the same result. I can't explain this behavior, according to the description on the page, it should count up from 34 to 35. if I put a simple variable object<int> counter in my signal it works as it should and only counts up for the close. If I use the function, the count is wrong.
Data series 1 is daily chart and data series 2 minutes.
I observe the behavior in playback mode
Attachments
Counter.png
(146.7 KiB) Not downloaded yet

HellGhostEvocatorX
Posts: 81
Joined: 10 Feb 2022
Has thanked: 52 times
Been thanked: 11 times

Re: FunctionSimple<T>

Postby HellGhostEvocatorX » 18 May 2023

Code: Select all

using System; namespace PowerLanguage { namespace Function { public sealed class BarZählerSeries : FunctionSeries<System.Int32> { private VariableObject< DateTime >startTime; private VariableObject<int> startBarNumber; private bool resetFlag; private bool countUp; public BarZählerSeries(CStudyControl _master) : base(_master) { resetFlag = false; countUp = true; } public BarZählerSeries(CStudyControl _master, int _ds) : base(_master, _ds) { resetFlag = false; countUp = true; } protected override void Create() { startTime = new VariableObject<DateTime>(this); startBarNumber = new VariableObject<int>(this); // create variable objects and function objects } public void SetStartTime(DateTime _startTime) { startTime.Value = _startTime; } public void SetStartBarNumber(int _startBarNumber) { startBarNumber.Value = _startBarNumber; } public void SetCountDirection(bool _countUp) { countUp = _countUp; } public void Reset() { resetFlag = true; } protected override void StartCalc() { { startTime.Value = DateTime.MinValue; startBarNumber.Value = 0; // assign inputs } } protected override System.Int32 CalcBar() { if (resetFlag) { resetFlag = false; startBarNumber.Value = 0; return startBarNumber.Value; } if (startTime.Value != DateTime.MinValue && Bars.Time[0] < startTime.Value) { // return startBarNumber.Value; } //if (startBarNumber.Value >= 0 && Bars.CurrentBar < startBarNumber.Value) //{ // // return startBarNumber; //} Output.WriteLine("1111111___{0},{1}", startBarNumber.Value, Bars.FullSymbolData.Current); // if (Bars.Status == EBarState.Close) //if (Bars.Time[1] < Bars.Time[0]) { if (countUp) { startBarNumber.Value++; } //else //{ // startBarNumber.Value--; //} } //return ++startBarNumber.Value; Output.WriteLine("2222222___{0},{1}", startBarNumber.Value, Bars.FullSymbolData.Current); return startBarNumber.Value; } } } }
Function series doesn't work properly either. If I add the query Ebarstate.close (or open) (it is excluded in the code) then it seems to count correctly, but always at the "last tick" and not when the new bar appears, as is the case with VariableObject <int> counter in Code happens - because of the IntraBarPersist.
How can I create this state in the function?

and the question remains whether I misunderstood something or whether the wiki entry is incorrect...

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: FunctionSimple<T>

Postby Polly MultiCharts » 19 May 2023

Hello HellGhostEvocatorX,

The same values might be displayed because there might be several calculations on the same bar as the script might refer to additional series.

If you’d like us to investigate the issue in detail please send us the following files to our support email:
  1. The workspace where the behavior is reproduced.
  2. Export of used symbols (with data) from QuoteManager in .qmd archive.
  3. The exported scripts with all dependent functions that are used on the workspace.
  4. The screenshots demonstrating the situation.
  5. Step-by-step instruction on how to reproduce the situation.


Return to “MultiCharts .NET”