- ago
This code snippet:
CODE:
public override void Initialize(BarHistory bars) {                   // calculate: Close - SMA(TR(Bars), 2)          var tr = new TR(bars);          var sma = new SMA(tr, 2);          var result = new MathIndOpInd(bars,             new TimeSeriesIndicatorWrapper(bars.Close),             MathOperation.Subtract,             sma);          PlotTimeSeries(result, "Close-SMA(TR(bars),2))", "Price"); }

produces the wrong results. It should show
CODE:
Close - SMA(TR(Bars), 2)
This is a line very close to the prices.

Instead the line in chart looks more like
CODE:
Close - SMA(Close, 2)
A line close to zero.


0
548
Solved
10 Replies

Reply

Bookmark

Sort
- ago
#2
The online description of MathIndOpInd says:
QUOTE:
MathIndOpInd cannot be nested.

What does this mean?
Which cases are covered?
Why is it so?
0
Cone8
 ( 3.70% )
- ago
#4
You can't use a MathIndOpInd as an "Ind" in a MathIndOpInd.

Corrected - see Post #10
0
- ago
#5
BTW: MathIndOpValue has a similar Problem. Let me know if you need a (not)working example.
0
Cone8
 ( 3.70% )
- ago
#7
Transformer indicators are meant primarily for operations in Block Strategies, and there exists the limitation:
Indicator parameters cannot be "indicators of indicators", e.g., SMA(TR, 2).

The Blocks U.I. imposes this limitation by only allowing you to select PriceComponents (Open, High, .. AverageHL, etc) as argurments for the indicator parameters.

In a C# coded strategy just perform the simple TimeSeries math operation:

CODE:
         TR tr = new TR(bars);          SMA sma = new SMA(tr, 2);          TimeSeries result = bars.Close - sma;          PlotTimeSeries(result, "Close-SMA(TR(bars),2))", "Price");
0
Best Answer
- ago
#8
Re: limitation: we may need to stress this point in the help a bit more.
0
Cone8
 ( 3.70% )
- ago
#9
Already ahead of you.
0
Cone8
 ( 3.70% )
- ago
#10
Re: MathIndOpInd cannot be nested.
I just realized that my answer in Post #4 is wrong [now], because Build 58 gave the ability to nest Transformer Indicators. The nesting not allowed in Transformer indicators is the "Indicator of an Indicator" type.

However, if you really want to replace the simple math operation above with the Transformer style, you can using the SmoothedInd or IndOnIndTransformer for the SMA(TR) and that result could be applied to MathIndOpInd, etc.
0

Reply

Bookmark

Sort