- ago
When choosing a source for the EMA indicator, a dropdown shows a short list of options:



Is it possible to use the Extension API to add another option to that list? For example, I'm interested in the EMA of (AveragePriceHLCC*2-High).
0
351
6 Replies

Reply

Bookmark

Sort
- ago
#1
I think the quickest and simplest approach is to create an entirely new custom indicator where you can take the selected source and apply the *2-High vector operation to it as part of the custom indicator code.

CODE:
indicator = source*2-High
You might the able to inherit directly from the existing EMA indicator instead of IndicatorBase when you define your custom indicator. That approach would simplify the new indicator code.
1
- ago
#2
Good point, thank you. I will give it a try and see how it goes.
1
- ago
#3
I'm struggling a bit with this. I'm looking at the source code for the SMA indicator at the bottom of https://www.wealth-lab.com/Support/ExtensionApi/IndicatorLibrary, and it's not clear to me where I should modify the calculation. There seems to be three functions that are all using "source" in their calculation, so I suppose I would need to modify all of the functions?
0
- ago
#4
QUOTE:
it's not clear to me where I should modify the calculation. There seems to be three functions that are all using "source" in their calculation,

If you're inheriting from EMA (instead of IndicatorBase), then you already have the EMA computed in Values[...]. So all you need to do in Populate() is multiply each Values[n] by 2.0 and subtract High[n] from it in your FOR loop inside Populate.

You'll need to pass all the required EMA parameters into the "inherited" constructor line, base(source,period,...); otherwise, the EMA indicator won't know what they are. Hmm. There's probably not an example of that on the forum, but your C# textbook should show how parameters are passed into an inherited constructor.

Alternately, you could inherit from IndicatorBase (It has no parameters.), then call EMA from Populate() and pass all its parameters in at that point. But that's more work.

You'll need to update a few other parameters for the new indicator. For example, you need to give your custom indicator a new name, say EMAx2, since you're multiplying the EMA by 2.

You need to post your code for discussion. But I would search for a couple indicator examples on the forum to follow from first. I found an example, but it's Populate() method is complicated. Yours will mainly be a one- or two-line FOR loop.
https://www.wealth-lab.com/Discussion/Custom-indicator-s-value-does-not-change-11289
0
- ago
#5
Take a look at the finantic.Eval extension?
It will do what you want out of the box.
1
- ago
#6
Yes, that's actually where all this started. I purchased the Eval extension, love it, use it every day. But it's incredibly cumbersome to convert to coded strategies every single time I want to optimize the number of bars. My hope was that I could implement my most frequently used Eval strings into custom indicators so that I could optimize the number of bars using the normal building block design interface.
0

Reply

Bookmark

Sort