Order of events  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Kghiasv
Posts: 2
Joined: 03 Aug 2021
Has thanked: 1 time

Order of events

Postby Kghiasv » 04 Aug 2021

Hello,

I am trying to code a system that acts based on the order of fractals prior to price breakout. One example is if price is breaking over the high of the last bull fractal, the system acts differently, if that bull fractal is the last fractal recorded or if a bear fractal happened between the time the bull fractal was recorded and the time that price breaks that bull fractals high.

The way I have tried to achieve this by trying to record the time of every bullFractal into bullFractalArray and the time of every bearFractal into bearFractalArray. Then, if price breaks above a bull fractal, the system acts differently based on whether the time of bearFractalArray[0] is greater or less than the time of bullFractalArray[0].

I am using a copy of the chaos fractals indicator to insert/test the code. I am only posting the code I am adding to it because Im not sure if posting the entire thing is allowed. If its allowed I can post the entire thing to make it easier for you guys.



First I declare the 2 arrays that will hold the times of the fractals above the indicator constructor.

Code: Select all

VariableSeries<DateTime> bullFractalArray; VariableSeries<DateTime> bearFractalArray;
Under CalcBar I create a DateTime variable and assign the last bars time to it.

Code: Select all

DateTime currentTime = Bars.Time.Value;
I then tried to use the if function that the fractal indicator uses to determine whether a fractal happened or not to assign the times of the fractals into their arrays.

Original function:

Code: Select all

if (PublicFunctions.DoubleGreater(m_value1, -1)){ Plot1.Set(0, m_value1); }
New function with inserted code:

Code: Select all

if (PublicFunctions.DoubleGreater(m_value1, -1)){ Plot1.Set(0, m_value1); bullFractalArray = currentTime; }

I then get this error:
Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'System.DateTime' to 'PowerLanguage.VariableSeries<System.DateTime>


I have tried playing around with the type of the VariableSeries<DateTime> by setting it as VariableSeries<double> and trying to return a double from the year 1900 with Bars.TimeValue as well as Bars.Time.Value but still could not test it successfully to see if I got it right.

I have also tried setting the first index of bullFractalArray but it says that it is read only.

Code: Select all

bullFractalArray[0] = currentTime;
If you could help me fix my code and tell me where I got it wrong I would appreciate it greatly. If I am trying to reinvent the wheel and you have a better way of doing this, I would love to learn. If you could do both I would be the most appreciative.

Let me know if I could improve my help post.
Thank you for your time.

User avatar
Tammy MultiCharts
Posts: 73
Joined: 06 Aug 2020
Has thanked: 2 times
Been thanked: 15 times

Re: Order of events  [SOLVED]

Postby Tammy MultiCharts » 05 Aug 2021

Hello Kghiasv,

To set variables like VariableSeries<> and VariableObject<> Value property should be used.

Please see below:

Code: Select all

VariableSeries<DateTime> bearFractalArray; bearFractalArray.Value = Bars.Time.Value;

Code: Select all

VariableSeries<DateTime> bearFractalArray; bearFractalArray.Value = Bars.Time[0];

Kghiasv
Posts: 2
Joined: 03 Aug 2021
Has thanked: 1 time

Re: Order of events

Postby Kghiasv » 14 Sep 2021

Hello Kghiasv,

To set variables like VariableSeries<> and VariableObject<> Value property should be used.

Please see below:

Code: Select all

VariableSeries<DateTime> bearFractalArray; bearFractalArray.Value = Bars.Time.Value;

Code: Select all

VariableSeries<DateTime> bearFractalArray; bearFractalArray.Value = Bars.Time[0];
Your answer helped me out to the point that I forgot to thank you.


Return to “MultiCharts .NET”