Global Variables and CalcBar() Sequences

Questions about MultiCharts .NET and user contributed studies.
zr6bcm
Posts: 5
Joined: 02 Jun 2014
Been thanked: 1 time

Global Variables and CalcBar() Sequences

Postby zr6bcm » 02 Jun 2014

Prelude: I am not expert yet, but I have read last few hours documentation and large parts of this forum. I have found, read and played with "C# Solution for Global Storage described ...".

Problem: I would like to have two indicators that work together. One computes a value X in each CalcBar, the second indicator must plot this value.

Background: I would like to have a set of indicators that work as "filters" that other indicators to access before generating a signal that a strategy can use to fire orders.

I have looked at the global storage things and understand roughly how it works. However, it looks for me like each indicator is calculated independent of one another.

(a) How do I get indicators to be calculated bar by bar together? Meaning A.CalcBar() is called and then B.CalcBar() is called?
(b) How can I set/control the behaviour so that always indicator A is calculated before B?

Thanks, Brian

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

Re: Global Variables and CalcBar() Sequences

Postby Henry MultiСharts » 03 Jun 2014

Hello Brian,

That is possible to create a function that will calculate the values, then use this function in an indicator or signal for doing plots and generating orders. In this case that is guaranteed that the function will be calculated first, then will be calculated the indicator.

zr6bcm
Posts: 5
Joined: 02 Jun 2014
Been thanked: 1 time

Re: Global Variables and CalcBar() Sequences

Postby zr6bcm » 03 Jun 2014

The problem is more described in the attached image.

(a) The user adds any number of indicators onto the chart. Each indicator has its own parameters and works and draws as it usually does.

(b) The indicators "send" their signals to one central engine. This decides from the sum of the signals whether to make the trade or not.

I know roughly how to get share the signals between the indicators via statics. I have looked at the global examples.

Problem: I want all the indicators to work bar by bar together so that at the end of each bar I have all the signals from all indicators. However, (maybe I am still missing a piece of the puzzle?) to me it looks like the indicators are processed separately from one another.

Or do I miss the forest because of all the trees?

Thanks, Brian
Attachments
problem description.jpg
(351.41 KiB) Downloaded 964 times
problem description.jpg
(351.41 KiB) Downloaded 949 times

zr6bcm
Posts: 5
Joined: 02 Jun 2014
Been thanked: 1 time

Re: Global Variables and CalcBar() Sequences

Postby zr6bcm » 04 Jun 2014

I am really still lost. How do I get two indicators to co-operate so that I dont have to cut-and-paste all code into one major indicator/strategy.

Multicharts: is this possible?

Here are two simple indicators (see attached image) where I have reduced the problem to the minimum. Simple: I want them both to draw the same lines, using one value from own indicator, once from other indicator. If this works, then I off to the races.

Somehow I still think I am missing something obvious, for this work in TS, etc.

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
public class A : IndicatorObject {
[Input] public int toggle { get; set; }
public A(object _ctx):base(_ctx){}
private IPlotObject plotL, plotH;
public static double valueHigh;
public static double valueLow;
protected override void Create() {
plotL = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
plotH = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Blue));
}
protected override void StartCalc() {
A.valueHigh = 27.7;
A.valueLow = 27.3;
}
protected override void CalcBar(){
A.valueLow = Bars.Low[0];
A.valueHigh = Bars.High[0];
plotL.Set(A.valueLow);
plotH.Set(B.valueHigh);
}
}
}

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator{
public class B : IndicatorObject {
[Input] public int toggle { get; set; }
public B(object _ctx):base(_ctx){}
private IPlotObject plotL, plotH;
public static double valueHigh;
public static double valueLow;
protected override void Create() {
plotL = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
plotH = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Blue));
}
protected override void StartCalc() {
B.valueHigh = 29.7;
B.valueLow = 29.3;
}
protected override void CalcBar(){
B.valueLow = Bars.Low[0];
B.valueHigh = Bars.High[0];
plotL.Set(A.valueLow);
plotH.Set(B.valueHigh);
}
}
}
Attachments
IndicatorsRunningSeparately.jpg
(250.54 KiB) Downloaded 958 times

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

Re: Global Variables and CalcBar() Sequences

Postby Henry MultiСharts » 04 Jun 2014

Brian, indicators of each chart are calculated in a separate flow. This is an asynchronous process. Here is a concept we have described earlier that can help you to implement what you need. If you need to differentiate the values on a bar by bar basis, that is possible you will need to add an additional parameter that will be passed, like the bar close time.


zr6bcm
Posts: 5
Joined: 02 Jun 2014
Been thanked: 1 time

Re: Global Variables and CalcBar() Sequences

Postby zr6bcm » 05 Jun 2014

Yes, I had already that post as well. I slightly defeats the purpose. I dont want to manually set the parameters. I dont want to have in code redraw all indicators.

I want the user to add any N number of indicators onto the chart. The user (and the backtest system!) must have access to all the indicator parameters to set them as he wants. The indicators must draw themselves. Then my engine can just get the signals and filters and make decisions.

The important aspect here is SYNCHRONOUS execution BAR-by-BAR of a specific set of indicators together.

Or probably I am just on the wrong road and need somebody to point me in the right direction.

Brian

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

Re: Global Variables and CalcBar() Sequences

Postby Henry MultiСharts » 06 Jun 2014

zr6bcm, I have sent you a PM.

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

Re: Global Variables and CalcBar() Sequences

Postby JoshM » 17 Jun 2014

zr6bcm, I have sent you a PM.
May we also know the answer to this topic?

zr6bcm
Posts: 5
Joined: 02 Jun 2014
Been thanked: 1 time

Re: Global Variables and CalcBar() Sequences

Postby zr6bcm » 17 Jun 2014

Of course! In summary, I can pay money and they will then program for me a solution. An email to MultiCharts to followup on this is still open, when I get an answer I can post here.

In my personal opinion, and in all respect to Henry, and in all positive impressions I have of MultiCharts, my impressions are: (a) Henry never really understood the problem (assume complexity of English) and (b) that this is an inherent problem of "works as designed" architecture versus "works as expected".

Personally, from looking at the problem from different sides, I have come to the conclusion there is no answer, as each indicator is computed separately on different threads and not synchronously bar-by-bar. I have for the moment put the problem to rest (and sadly also my evaluation of MC.NET) and am evaluating other options.

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: Global Variables and CalcBar() Sequences

Postby GTrader » 17 Jun 2014

Having tried every platform out there, the main problem is how certain platforms differentiate between indicators and systems/signals. You should be able to write a signal and have the ability to plot (to any pane in the chart) from within the signal directly without having to create a separate indicator. Separating the two creates a huge code redundancy.

Henry, any thoughts on allowing this functionality down the road? I understand that it is a massive change to the application to do it correctly but perhaps there is a way it could be accomplished through an extension library?

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

Re: Global Variables and CalcBar() Sequences

Postby JoshM » 22 Jun 2014

Can a singleton class be used to communicate the data? That way, the multi-thread challenge would likely be solved (if I understand this topic correctly).

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

Re: Global Variables and CalcBar() Sequences

Postby Henry MultiСharts » 23 Jun 2014

Can a singleton class be used to communicate the data? That way, the multi-thread challenge would likely be solved (if I understand this topic correctly).
Yes, that is possible to do that.


Return to “MultiCharts .NET”