1 (edited by slipshod 2013-05-22 16:13:18)

Topic: Keltner Channels

Learning FSB indicator development, please bear with me.  These are written to be V2 compatible which means they'll work in the latest Beta of FSB & I presume the Pro version (which I haven't tried yet).

Firstly Keltner v2 is the same as the builtin Keltner, except it takes larger period values for the MA and the ATR, plus the ATR multiplier is a floating point number to 1 decimal place.

Keltner Channel Crossover was a bit more ambitious.  It includes the above, but measures whether the high or low lines of a "fast" channel have crossed those of a "slow" channel, or if they're currently above or below the slow channel.  The same could be applied to other MA based price channels, eg Bollingers, Starc Bands etc.

I hope they're helpful, and if you see anything wrong please let me know.  The chances of something being wrong, especially with the Crossover, are probably pretty high wink

Post's attachments

Keltners.zip 6.54 kb, 15 downloads since 2013-05-22 

You don't have the permssions to download the attachments of this post.

Re: Keltner Channels

Hello Slipshod, welcome in the club of FSB contributors!

Nice job with these indicators. However there is some issues with "Keltner Channel Crossover" as you supposed smile

There is a tool "Check indicators" under Tools - Custom Indicators menu. It checks more thoroughly the indicators options. When I run it, it showed:


I'm sure no one can understand what the error message means smile smile, but it must be something with 'SlotTypes.Open'.

I checked the code and found this in the constructor:

PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;

We see that you made indicator available for "Opening Points" and "Closing Points" slots, but it seems to work as  filter only.

So you should replace the upper line with:

PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter;

...

Please when you are ready, upload the indicator in the new Repo. It's under development but will be ready very soon.

About FSB, I added three new params to the indicators that are not defined there:

            IndicatorAuthor = "Andrew Sumner";
            IndicatorVersion = "2.0";
            IndicatorDescription = "Compares channels.";

I'll add them in FSB Pro at the weekend.

Re: Keltner Channels

One thing I was wondering with band crossover type indicators, how would they work with long/short mirrored trade logic?

For instance, I tell it to go long when the low of the fast band crosses above the high of the slow band.  For shorts, will it be smart enough to convert that to the high of the fast crossing the low of the slow, or would it look for fast low crossing down over slow high?

Re: Keltner Channels

Use this logic method for "band" indicators:

        /// <summary>
        ///     Calculates the logic of a band indicator.
        /// </summary>
        /// <param name="firstBar">The first bar number.</param>
        /// <param name="prvs">To use the previous bar or not.</param>
        /// <param name="adUpperBand">The Upper band values.</param>
        /// <param name="adLowerBand">The Lower band values.</param>
        /// <param name="indCompLong">Indicator component for Long position.</param>
        /// <param name="indCompShort">Indicator component for Short position.</param>
        /// <param name="indLogic">The chosen logic.</param>
        protected void BandIndicatorLogic(int firstBar, int prvs,
               double[] adUpperBand, double[] adLowerBand,
               ref IndicatorComp indCompLong, ref IndicatorComp indCompShort,
               BandIndLogic indLogic)
        {
            .....
        }

It takes already calculated bands. It cannot decide what base price (Low or High) to use, since the values of the bands are already fixed. The best practice is to use some "symmetrical" base price for the bands as Open, Close, Middle... that is meaningful for both bands. If you use High prices for the bands. Both bands in both direction will use High.

Your logic that in the upper band should use High when the Lower use Low is correct but I was not implemented it because leads to some custom cases.
If you need it, you have to implement it when you are calculating the bands.

Re: Keltner Channels

Hmmm. I probably do not understand your question well. You don't mean using High and Low prices, right?

Band should work well in the general case. Even better since there is designated code that fixes some "special" cases. I may proudly say that this code should work much better than 99% of public MQL indicators. Just because it fixes these special cases. (You have to dig in the code to see what I mean).

Anyway, if you see something suspicious, please report.

Re: Keltner Channels

slipshod wrote:

One thing I was wondering with band crossover type indicators, how would they work with long/short mirrored trade logic?

For instance, I tell it to go long when the low of the fast band crosses above the high of the slow band.  For shorts, will it be smart enough to convert that to the high of the fast crossing the low of the slow, or would it look for fast low crossing down over slow high?

Alright, doubt in everything I say as I'm mostly self-taught coder. But I would sort the issue out in one of two possible ways:
1. write custom logic. Then you control the whole lot how signals are given, both long and short;
2. utilize native logics, for example

IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, one band, the other band, ref Component[1], ref Component[2]);

Re: Keltner Channels

On second thought the native logics might not work. If you define upward cross like this

lower band of faster band > upper band of slower band

then the mirror logic would be like this

lower band of faster band < upper band of slower band

and it would be logically incorrect.

Re: Keltner Channels

Slipshod

Thanks for your efforts and contributions.....

My 'secret' goal is to push EA Studio until I can net 3000 pips per day....

9 (edited by slipshod 2013-05-23 03:02:35)

Re: Keltner Channels

footon - yes, that's exactly what I was afraid might happen.  Would there be any way to get around this using custom logic do you think?

I'm happy to program it, but I'd need to see some examples of custom logic implementations that I could learn from...

Re: Keltner Channels

We can use IndicatorCrossesAnotherIndicatorUpwardLogic and IndicatorCrossesAnotherIndicatorDownwardLogic to calculate separately the signals for long and for short positions. Since these functions calculate both directions, I'll use a dummy component that is ignored by the charts for the direction I do not need.

// Saving the components
Component = new IndicatorComp[9];

...

Component[8] = new IndicatorComp
    {
        CompName = "Dummy component",
        ShowInDynInfo = false,
        ChartType = IndChartType.NoChart,
        FirstBar = iFirstBar,
        DataType = IndComponentType.IndicatorValue,
        Value = new double[Bars]
    };

...


switch (IndParam.ListParam[0].Text)
{
    case "Fast Channel High crosses Slow Channel Low upward":
       IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, previous, adUpBandFast, adDnBandSlow, ref Component[6], ref Component[8]);
       IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, previous, adDnBandFast, adUpBandSlow, ref Component[8], ref Component[7]);
       break;
    case "Fast Channel High crosses Slow Channel High upward":
       IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, previous, adUpBandFast, adUpBandSlow, ref Component[6], ref Component[8]);
       IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, previous, adDnBandFast, adDnBandSlow, ref Component[8], ref Component[7]);
       break;
...

case "Fast Channel High crosses Slow Channel High downward":
   IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, previous, adUpBandFast, adUpBandSlow, ref Component[6], ref Component[8]);
   IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, previous, adDnBandFast, adDnBandSlow, ref Component[8], ref Component[7]);
   break;

Re: Keltner Channels

Test this. It should work, but logic must be checked (in the code and on the chart) smile

I also changed the arrangement of the MA Method list boxes to fit visually to the corresponding params below.
http://s10.postimg.org/ujc4idzol/keltner_cross.jpg

Re: Keltner Channels

Since central MA is not part of the logic rules, I hide it from the chart and from the dynamic info.
Also I painted slower channel brown.

Attached "Keltner Channel Crossover" v2.2


Component[2] = new IndicatorComp
    {
        CompName = "Fast Moving Average",
        DataType = IndComponentType.IndicatorValue,
        ShowInDynInfo = false,        // <--------------------
        ChartType = IndChartType.NoChart,        // <--------------------
        FirstBar = iFirstBar,
        Value = adMAFast
    };

Component[3] = new IndicatorComp
    {
        CompName = "Slow Moving Average",
        DataType = IndComponentType.IndicatorValue,
        ShowInDynInfo = false,        // <--------------------
        ChartType = IndChartType.NoChart,        // <--------------------
        FirstBar = iFirstBar,
        Value = adMASlow
    };

Please, when you are ready with the indicator, upload it in the repo.

Re: Keltner Channels

There is a problem with the short positions logic. I'll try to fix it shortly.

Re: Keltner Channels

This must be better:

Post's attachments

Keltner Channel Crossover.cs 26.96 kb, 23 downloads since 2013-05-23 

You don't have the permssions to download the attachments of this post.

Re: Keltner Channels

Wonderful, thanks Miroslav!  I've got a long optimization running right now, as soon as its finished I'll start running tests.

cheers,
Andrew

Re: Keltner Channels

Appears to be working perfectly.  Would you like me to progress through adding crossover logic to the other band-type indicators using this as a template?

Re: Keltner Channels

slipshod wrote:

Appears to be working perfectly.  Would you like me to progress through adding crossover logic to the other band-type indicators using this as a template?

Please feel free to upload your creation to http://repo.forexsb.com/repository_indicators/upload

Re: Keltner Channels

Done smile

Re: Keltner Channels

slipshod wrote:

Appears to be working perfectly.  Would you like me to progress through adding crossover logic to the other band-type indicators using this as a template?

You are welcome to contribute to the project. Once you have a working model, you can use for other similar indicators.

If it works well, will be good to open a separate topic for Crossover Bands Indicators where to explain how the logic works in both directions. There you can announce these indicators. Also the topic can be link from the corresponding Repository records.

...

I already posted about one dozen of indicators in the repo. It has some minor issues but it looks it works well. The real fun will be "one click install" of custom indicators from FSB Pro.

Re: Keltner Channels

I'm happy to help where-ever I can.  I've been a software developer for 20-odd years, and am much better at it than trading wink  FSB looks like helping me earn considerable pips, so its only right that I contribute whatever I can in return.

Re: Keltner Channels

I think we can remove these two components since they are not used in the logic.

            Component[2] = new IndicatorComp
                {
                    CompName = "Fast Moving Average",
                    DataType = IndComponentType.IndicatorValue,
                    ShowInDynInfo = false,
                    ChartType = IndChartType.NoChart,
                    FirstBar = iFirstBar,
                    Value = adMAFast
                };

            Component[3] = new IndicatorComp
                {
                    CompName = "Slow Moving Average",
                    DataType = IndComponentType.IndicatorValue,
                    ShowInDynInfo = false,
                    ChartType = IndChartType.NoChart,
                    FirstBar = iFirstBar,
                    Value = adMASlow
                };

Re: Keltner Channels

I uploaded a fixed version without these components.

Re: Keltner Channels

Thanks Popov, sorry I hadn't gotten to it yet.

Re: Keltner Channels

Is the control of the previous bar values correct? I don't think so because the results are too good to be true! lol

Re: Keltner Channels

Indicator was edited to work only on Close price.
Other base prices were removed because of wrong set of "Use previous bar value".