- ago
A noob question, I know, but how do I sum up indicator values to create a custom indicator (without creating it in a Builder, but just in code)? I naively thought '+' operator would be overloaded, but it doesn't seem to be.
Something like:
CODE:
ind1 = new EMA(bars.Close,26); ind2 = new EMA(bars.Close,13); PlotIndicator(ind1+ind2, WLColor.FromArgb(255,128,128,128), PlotStyle.Line);
0
195
Solved
3 Replies

Reply

Bookmark

Sort
- ago
#1
CODE:
ind2 = EMA.Series(bars.Close,26); ind1 = EMA.Series(bars.Close,13); ind3 = ind1 + ind2; PlotIndicator(ind3, WLColor.FromArgb(255,128,128,128), PlotStyle.Line);


Alternatively, since what you've created is not an indicator you should call PlotTimeSeries on it:
CODE:
PlotTimeSeries(ind1 + ind2, "sum", "sum", WLColor.FromArgb(255, 128, 128, 128), PlotStyle.Line);
1
- ago
#2
QUOTE:
since what you've created is not an indicator

Did you follow that?

So the "+" and "-" operators are overloaded for a TimeSeries, but not an indicator. Since an indicator is also a TimeSeries, C# converts the indicator to a TimeSeries before applying the "+" operator. But the resulting sum is now a TimeSeries, so you need to use PlotTimeSeries (not PlotIndicator) to plot the sum.

Indicators contain additional field variables that help methods like PlotIndicator() set defaults. But once you morph them with a "+" operator, some of those field variables are now undefined, so the result reverts to a simpler TimeSeries without those undefined indicator field variables.

You wouldn't know this unless you studied the internals of the TimeSeries and Indicator class objects, which you will do if you eventually write your own class libraries. Happy computing.
3
Best Answer
- ago
#3
Thanks all!
0

Reply

Bookmark

Sort