How to Make "double[]" Global

Questions about MultiCharts .NET and user contributed studies.
Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

How to Make "double[]" Global

Postby Jobauma » 03 Apr 2020

Hi.

I'm struggling find this solution.

This works...

Code: Select all

double[] m_Array = new double[34]; for ( int I = 0; I < 34; I++ ) m_Array[I] = [ SOME CODE ];
...but it isn't global.

Any suggestions? :)

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to Make "double[]" Global

Postby JoshM » 05 Apr 2020

Good question! Do you mean with 'global' that the double array should be accessible anywhere in the same script?

Or does it need to be accessible to other scripts as well?

Or, less likely, do you perhaps want to make the array available to another application besides MultiCharts .NET?

:)

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: How to Make "double[]" Global

Postby Jobauma » 05 Apr 2020

Hi.

Thanks for your reply. :)
Do you mean with 'global' that the double array should be accessible anywhere in the same script?
Yes. :P



Best regards,
Johannes Hillestad Baumann

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to Make "double[]" Global

Postby JoshM » 06 Apr 2020

Thanks for the clarification! If you want to access the array anywhere in the same script, you have to make it in the code block that says 'public class'. So at the same level. For example:

Image

You can access it then anywhere in the same script. This indicator, for example, accesses the length of the array in the `Create()`, `StartCalc()`, and `CalcBar()` methods:

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator { public class ScriptGlobalVariable : IndicatorObject { private double[] m_Array = new double[34]; public ScriptGlobalVariable(object _ctx) : base(_ctx) { } protected override void Create() { Output.WriteLine("From Create(): Length of array: {0}", m_Array.Length); } protected override void StartCalc() { Output.WriteLine("From StartCalc(): Length of array: {0}", m_Array.Length); } protected override void CalcBar() { if (Bars.CurrentBar < 10) { Output.WriteLine("From CalcBar(): Length of array: {0}", m_Array.Length); } } } }
Attachments
2020-04-06_07-45-11.png
(9.08 KiB) Not downloaded yet

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: How to Make "double[]" Global

Postby Jobauma » 06 Apr 2020

Thank your very much. :D

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: How to Make "double[]" Global

Postby Jobauma » 06 Apr 2020

For those who was wondering what I'm using it for. :)

I use it for applying the last wave sum value ( including zigzag waves ) to the whole wave (length), and since the waves are weighted ( decreases a bit by the length ), this solution is necessary:

Code: Select all

private double[] m_Wave = new double[56]; for ( int I = 0; I < Counter && I < 55; I++ ) m_Wave[I] = Value_Sum_Wave;
And then the array has to move 1 index forward too ( for each bar ). This has to be done manually: :)

Code: Select all

if ( Bars.Status == EBarState.Close ) for ( int I = 0; I < 55; I++ ) m_Wave[ 55 - I ] = m_Wave[ 55 - I - 1 ];
Then you can use it for plotting a whole span of something, for example, beneath the lowest waves:

Code: Select all

double Lowest_Wave_Sum = new[] { m_Wave.Min(), m_Wave_Zigzag.Min() }.Min(); for ( I = 0; I < 55; I++ ) p_PlotObject.Set( I, Lowest_Wave_Sum [ "+" / "-" ] m_Value[I], Color.Empty, 0 );


Best regards,
Johannes Hillestad Baumann


Return to “MultiCharts .NET”