- ago
I think maybe someone will, because I think they're commonly traded this way. I'd be so very appreciative :) Thank you all for being so helpful!!!
0
225
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
CODE:
KeltnerUpper(BarHistory source, int period, double atrMultiple, int atrPeriod, bool useAtrBands);


useAtrBands set as true should be what you want (using EMA and ATR multiples).
1
- ago
#2
QUOTE:
code for an EMA-based Keltner Channel?

I'm confused. Keltner bands are based on an SMA center line follower. If you want an EMA center line (Do you?), then we cannot call them Keltner bands anymore. This question was answered in the last paragraph of Post3 at https://www.wealth-lab.com/Discussion/Bollinger-Bandwidth-as-Standard-Indicator-12754#post3

But to answer it with an example, see the code below.


CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript4 {    public class MyStrategy : UserStrategyBase    {       const int period = 10;       public override void Initialize(BarHistory bars)       {          IndicatorBase ema = EMA.Series(bars.Close,period);          IndicatorBase atrUpper = ATRBandUpper.Series(bars, ema, period, 2.0);          IndicatorBase atrLower = ATRBandLower.Series(bars, ema, period, 2.0);          PlotIndicatorBands(atrUpper, atrLower, WLColor.Goldenrod, opacity: 20);       }       public override void Execute(BarHistory bars, int idx) { }    } }
If you want to do anything that's really customize--and I think you do--then you will probably need to code it in C# or C++. You can start off with blocks, then convert it to C#, but the resulting conversion will be messy. But you can use the messy conversion to help learn C#.

Do you have a static WLUtility class library? If so, you can code this solution as a static member function in that library so you can call it as needed.
0
- ago
#3
Superticker, I appreciate your detailed response, but unfortunately I do not know much of anything about coding and think it would take quite a bit of time to learn. I understand that Keltner channels were originally created to follow SMA lines, but I believe the modern application uses mostly EMA. I used these on MotiveWave where the standard Keltner Channels follow EMAs, and I know John Carter's TTM squeeze is based on Keltner Channels that follow EMA trend lines. I just figured someone might have this code for applications like TTM squeeze, for example.

I'm really sorry for the confusion, but your code looks like a strategy, not an indicator? I see parts that say EMA but I'm not sure how to convert this code to be used as an indicator.

If there is a code library where I could easily just replace the term SMA with EMA, I could do that, but I am not sure where to access that code?
0
- ago
#4
QUOTE:
... I do not know much of anything about coding and think it would take quite a bit of time to learn.

If you haven't done any coding at all (Is that true?), then I would find a local partner that has coded in C# or C++. You appear to want to do much customization, and that customization is going to require coding.

I can rewrite my solution as a static function that your coding partner can place into a local static WLUtility class library compiled with the Visual Studio IDE. But without some custom coding, your flexibility will be limited.

QUOTE:
I understand that Keltner channels were originally created to follow SMA lines, but I believe the modern application uses mostly EMA.

... I know John Carter's TTM squeeze is based on Keltner Channels that follow EMA trend lines.

I didn't know that. I just call the Squeeze indicator. :-)
Why don't you just call the Squeeze indicator from blocks?

When the EMA is employed, are they still using the "average" price (H + L + C)/3 when computing the EMA center line? Apparently not, see reply below.
0
- ago
#5
I just ran the code below for a comparison and they both come out with matching solutions. This means the WL8 implementation of the Keltner bands (when using ATR) are employing the EMA of just the Close and not the average price. So the Keltner bands have been redefined to use the EMA(Close) instead of the SMA(average price) as their center line follower when in ATR mode. Interesting; you taught me something.

I'm assuming WL8 has it right, but someone should step forward if it doesn't.

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript6 {    public class MyStrategy : UserStrategyBase    {       const int period = 10;       public override void Initialize(BarHistory bars)       {          IndicatorBase ema = EMA.Series(bars.Close,period);          IndicatorBase atrUpper = ATRBandUpper.Series(bars, ema, period, 2.0);          IndicatorBase atrLower = ATRBandLower.Series(bars, ema, period, 2.0);          PlotIndicatorBands(atrUpper, atrLower, WLColor.Goldenrod, 1, opacity: 20);          IndicatorBase keltnerUpper = KeltnerUpper.Series(bars, period, 2.0, period, true);          IndicatorBase keltnerLower = KeltnerLower.Series(bars, period, 2.0, period, true);          PlotIndicatorBands(keltnerUpper, keltnerLower, WLColor.Goldenrod, 1, opacity: 20);       }       public override void Execute(BarHistory bars, int idx) { }    } }
0
Best Answer
- ago
#6
Yes, I see now what Ranier was saying. It appears that checking the "Use ATR Bands" box not only uses ATR multipliers, but also switches to an EMA midline. That's exactly what I'm looking for! Sorry for the confusion!
1

Reply

Bookmark

Sort