- ago
I am trying to create an indicator that plots the Average(SMA) of Volume bars see image below. But I can not find Volume in the list in IndOnInd nor in the list in WealLab script. Please advice. Thanks.



0
250
8 Replies

Reply

Bookmark

Sort
- ago
#1
For block strategies, use IndOnInd. Volume is way up top with Open, Close, etc...



For C#...

CODE:
private SMA VolAvg; public override void Initialize(BarHistory bars) { VolAvg = SMA.Series(bars.Volume, 20); // etc...
0
GlitchA
 ( 3.37% )
- ago
#2
Just use SMA, not IndOnInd. You can select Volume for SMA, the standard OHLCV series are at the top of the list.
0
- ago
#3
Thanks, I get this error when using IndOnInd applied to Volume. It works ok when using SMA as mentioned by Glitch.



0
- ago
#4
Quick question I noticed there are 2 methods to plot an indicator in the QuickRef Catalog (see code below) Is there any advantage of one over the other or just personal preference?

CODE:
private SMA VolAvg; public override void Initialize(BarHistory bars) {          VolAvg = SMA.Series(bars.Volume, 50);          PlotIndicator(VolAvg, WLColor.AquaMarine); }


CODE:
public override void Initialize(BarHistory bars) { IndicatorBase volAvg = new SMA(bars.Volume, 50);          PlotIndicator(volAvg, WLColor.AquaMarine); }


0
- ago
#5
In my post above, I was not correct. As Glitch noted, you can select Volume for SMA. (I didn't actually try it earlier, I just took the snapshot.)

Also, I just tried IndOnInd (SMA on Volume, as noted is not correct thing to do), and I too got an exception with the same stack trace. Even though it is not the correct thing to do, I guess it shouldn't cause an exception.
0
- ago
#6
Maybe it should be removed from the IndOnInd scroll down options I guess?
0
- ago
#7
Per your question about using Series versus new... Keep in mind that SMA is a subclass of IndicatorBase. In any case, using Series or new gets you an SMA object. Instead of

IndicatorBase volAvg = new SMA(bars.Volume, 50);
it can be...
SMA volAvg = new SMA(bars.Volume, 50);

Then you don't have to do any casting if you want to pick-off properties and methods that are specific to SMA, if any (I didn't check).

But, the advantage of use Series instead of new, without having the actual code to check this, is that Series will cache the result according to the parameters. new(...) typically won't do that. Hence, with Series you MAY see a performance boost depending on what operations are carried out, like perhaps optimizations. So, I just use Series.

Here is an example of a typical Series method. In this case it is a special brew of the Stochastic Momemtum Index...

CODE:
public static StochasticMomentumIndex Series(BarHistory bars, int percentDLength = 3, int percentKLength = 5) { var key = CacheKey("StochasticMomentumIndex", percentDLength, percentKLength); if (bars.Cache.TryGetValue(key, out var obj)) { return (StochasticMomentumIndex) obj; } var result = new StochasticMomentumIndex(bars, percentDLength, percentKLength); bars.Cache[key] = result; return result; }


To my knowledge, that is the typical pattern followed for an indicator in its Series method.
0
GlitchA
 ( 3.37% )
- ago
#8
It looks like a bug using Volume for IndOnInd. I’ll work on a fix.
0

Reply

Bookmark

Sort