A programmable trading plan using only price bars

tss42

Active member
Messages
159
Likes
21
This journal thread is a follow up to my earlier ramblings in the Price Volume forum.

I aim to define and test a strategy based on price bars.

A lot of the foundations have been 'borrowed' from Dunnigan, although the strategy I have in mind is not a copy of his work.

The trading plan will be 100% programmable with no room for subjectivity/interpretation/emotion.

Although I have made a big song and dance about trading with price alone, I am reluctantly forced to use a moving average to define trend. If I find a better (programmable) method of telling the trend, I'll stop using the MA.

In the next few posts I will describe the building blocks and the definitions I am going to use.
 
Last edited:
This should be of particular interest to Forex traders. Perhaps one of the mods could suggest a Forex thread or forum where you could post a link to this journal.
 
Definitions:
Long-range bar: A bar that strictly contains (i.e., no equality on either end) one or more subsequent bar in its range.

Inside bar: A bar that is strictly contained (i.e., no equality on either end) within a preceding bar.

Down bar: A bar that has a strictly lower low and a lower or equal high compared to the previous bar. Inside bars are ignored and the comparison does not resume until the high of the last long-range bar is breached. Outside bars are ignored and the comparison does not resume until the high of the outside bar is breached.
Up bars are just the other way round.

Swing low: A down bar that has an up bar on either side.
Swing high is the opposite.

Closing price reversal: A down bar that has closed above the last close with the following conditions:
- The CPR bar must either push more than halfway through the prior bar, or the CPR bar must have a greater range than the prior bar.
- The CPR bar itself must close on the top half.
Similarly for the bearish version.
(Note that this definition of CPR is my own).

Trend is defined by the direction of 15-period triangular moving average. I like this because it's double-averaged, therefore smoother than EMA or SMA, yet tracks the trend well.

I'll put up some pictures when I get a chance next.
 
Last edited:
Don't want to interrupt your rhythm, but what is the difference between a "long-range" bar and an outside bar?
 
Swings: A down swing starts with the appearance of a swing high and is in force until a swing low appears, at which point an upswing begins.

We aim to trade swings within a trend. In other words, we go long when we sense the impending end of a down swing as long as the moving average is not declining.
 
Last edited:
Some pictures.
 

Attachments

  • Untitled.PNG
    Untitled.PNG
    9.1 KB · Views: 1,531
Before we go into set ups and money management (which will be most probably tomorrow), some of the other preliminary areas (and philosphies):

I will observe only one market to start with, the ES.

Only one timeframe will be used: 1 minute.

I believe intra-day profits are short-lived, so you have to take them while they are still there. We will therefore start covering when the move starts to go our way. We will enter with 3 units of contracts (i.e., multiple of 3):
Unit 1 is covered quickly.
Unit 2 is designed to catch profits when there are strong sudden moves.
Unit 3 is designed for longer moves than what unit 2 cacthes, hence a little more relaxed.

My maximum risk (beyond which I will pass up the trade) will be a function of the ATR in the timeframe I am trading. In other words, when the 1 minute bars are on average 2 points long, there is no point for me to stick to a 1.5 point maximum risk, because I won't get any trade.
 
Last edited:
OK, the set-up and the management rules very quickly. In a hurry, will elaborate later:

Description (for longs, reverse for shorts)

Set-up 1: A swing low should form, and the up bar following the swing low bar should close on the top half. Buy when the high of the up bar is broken.

Set-up 2: A closing price reversal has occurred. Buy when the high of the CPR bar is broken.

A long set-up is cancelled if either of the following happens:
- The moving average turns down.
- A down bar appears before the signal bar is breached.

Management (for longs, reverse for shorts):
The initial stop and also the normal place for the trailing stop is below the swing low. However, on entry, as soon as we have 3 up bars in a row, three different management schemes will be employed.
First, One unit will be closed.
Second, the stop for the second unit will be trailed below the 3-bar lows.
Third, the stop for the last unit will be trailed below the swing lows.

There are two other areas on which I need to work on:
1. There has to be a mechanism to scratch a trade if we decide it's not going according to plan.
2. Apart from setting the maximum risk, we may also need a mechanism to decide when an entry no longer represents value. We don't want to chase. For example if following a swing low we get a huge up bar, it may no longer make sense to take a break of that bar.
 
Last edited:
I need to do some thinking on three points mentioned before (maximum risk, scratching and not chasing). I will post again when I have got something on either of them.
 
My maximum risk (beyond which I will pass up the trade) will be a function of the ATR in the timeframe I am trading. In other words, when the 1 minute bars are on average 2 points long, there is no point for me to stick to a 1.5 point maximum risk, because I won't get any trade.

Good luck on the thread. Sounds interesting...

I did some work on ATR settings when I first started out. How flexible are you going to be in determining when the market becomes less or more volatile? As you are trading of a 1-minute timeframe, I can see the average true range swinging from one end of the spectrum to the other...
 
How flexible are you going to be in determining when the market becomes less or more volatile?

That is correct. Don't know what I was thinking. I don't need another variable in the form of ATR, as long as I have my initial stop below the last down bar and a mechanism to pass up trades if they are 'too far away' from the swing low.

So the ATR goes into the bin.

The other thought that is playing in my mind is that I don't really like using the moving average for trend because then why not use a 10-period MA instead of 15? Why not use a 5 period one or a 20 period one? I do not have the trading maturity to decide when the market conditions change to warrant the use of a different period MA, so I will always ponder after the event (and worse, keep changing my settings retrospectively). I'd much rather use a price-based definition if there was one. I played with Dunnigan's definition but found that unworkable. I'll give it another try, may be I can modify it slightly...
 
That is correct. Don't know what I was thinking. I don't need another variable in the form of ATR, as long as I have my initial stop below the last down bar and a mechanism to pass up trades if they are 'too far away' from the swing low.

So the ATR goes into the bin.

The other thought that is playing in my mind is that I don't really like using the moving average for trend because then why not use a 10-period MA instead of 15? Why not use a 5 period one or a 20 period one? I do not have the trading maturity to decide when the market conditions change to warrant the use of a different period MA, so I will always ponder after the event (and worse, keep changing my settings retrospectively). I'd much rather use a price-based definition if there was one. I played with Dunnigan's definition but found that unworkable. I'll give it another try, may be I can modify it slightly...

since you have a definition for a swing set-up, how about defining trend in terms of rising swings (HH and HL) and vice versa, thus negating the need for an arbitrary MA?

good luck on this project.

EDIT:
re: "we go long when we sense the impending end of a down swing as long as the moving average is not declining."
how are you going to quantify objectively "sense the impending"? ;)
 
since you have a definition for a swing set-up, how about defining trend in terms of rising swings (HH and HL) and vice versa, thus negating the need for an arbitrary MA?

I did think of that but price hardly ever goes up in a nice series of higher lows and vice versa. But wait, maybe we can only concern ourselves with the portion of the trend where we have a series of HH and HL (or LH and :LL for down trend) and any exception (e.g. HL mixed with LH) is treated as 'undefined' trend, in other words potential whipsaw. That's an idea. I'll work on that.

re: "we go long when we sense the impending end of a down swing as long as the moving average is not declining."
how are you going to quantify objectively "sense the impending"? ;)

In that sentence I was describing the thinking behind my set-ups. The actual definitions of the set-ups are the concrete (programmable) realisation of that thinking.
 
Rather shamelessly, I am quite tempted to look at Dunnigan's definition of trend again.

The trend is currently up if the below are true:
- If we start from the current bar and go back bar by bar, we should find a swing low the range of which is entirely above the preceding swing low, or we shoud find an an up bar in an upswing that has closed above the preceding two swing highs. Once such a point (call it bar A) has been identified, two things must happen:
a. No bar in the downswing immediately following bar A should be completely below the range of bar A.
b. The first up bar that follows the downswing following the the point A should close above the close of the previous bar (i.e. the swing low bar).
- Between point A and the current bar no signal for downtrend must have appeared.

Once bar A is identified, we can go back further to find where the uptrend started. It will be the bar that satisfied all the condition of uptrend since a signal of downtrend appeared.

Once an uptrend is established, it remains in effect until a signal for downtrend has appeared.

Complicated? That's why I had decided not to use it when I looked at it before. I will now take some time to digest it and look at some charts to see how it fits with my temperament.
 
I remember the other reason why I didn't like it the first time. I have rephrased Dunnigan's definition slightly here. Actually, in his definition of uptrend, he starts counting not from the current bar and backwards, but from what he calls 'maintrend low' and forward. Except to define 'maintrend low', you need to go back to the prior 'maintrend high' and to define that you need to go back to the 'maintrend low' before that and so on and so forth. So it's not really as well-defined as I want.

Or may be I am obsessed with definition and should see a doctor...
 
Picture of what Dunnigan trends would look like:

Red bars are end of uptrend and start of downtrend.
Green bars are end of downtrend and start of uptrend.
 

Attachments

  • Untitled.PNG
    Untitled.PNG
    15.9 KB · Views: 378
I like it better than when I looked last time. The chart is part of yesterday's action. Except for the first strong down move the market wasn't great. The trend signals are not too bad.
 
I remember the other reason why I didn't like it the first time. I have rephrased Dunnigan's definition slightly here. Actually, in his definition of uptrend, he starts counting not from the current bar and backwards, but from what he calls 'maintrend low' and forward. Except to define 'maintrend low', you need to go back to the prior 'maintrend high' and to define that you need to go back to the 'maintrend low' before that and so on and so forth. So it's not really as well-defined as I want.

Or may be I am obsessed with definition and should see a doctor...

This whole question of trend is a cul-de-sac I spent rather too many years on when I was working with a programmer. To define a trend that is meaningful and practical in terms of trading is IMO akin to finding the end of the rainbow. There are thousands of available tools ready made for Amibroker free and also at PatternExplorer - Home not to mention the ones for metatrader.

There is a concept explained in The Black Swan by Nassim Taleb. The Problem of Inductive Knowledge.

On p41 there is a graph of a turkey's life over a thousand days before and after Thanksgiving, an illustration of the fallacy of attempting to project the future from the past.

Good luck with the project.
 
Rather shamelessly, I am quite tempted to look at Dunnigan's definition of trend again.

The trend is currently up if the below are true:
- If we start from the current bar and go back bar by bar, we should find a swing low the range of which is entirely above the preceding swing low, or we shoud find an an up bar in an upswing that has closed above the preceding two swing highs. Once such a point (call it bar A) has been identified, two things must happen:
a. No bar in the downswing immediately following bar A should be completely below the range of bar A.
b. The first up bar that follows the downswing following the the point A should close above the close of the previous bar (i.e. the swing low bar).
- Between point A and the current bar no signal for downtrend must have appeared.

Once bar A is identified, we can go back further to find where the uptrend started. It will be the bar that satisfied all the condition of uptrend since a signal of downtrend appeared.

Once an uptrend is established, it remains in effect until a signal for downtrend has appeared.

Complicated? That's why I had decided not to use it when I looked at it before. I will now take some time to digest it and look at some charts to see how it fits with my temperament.

It's "complicated" only because you're putting it all into words. This is a necessary step, but one which will eventually be behind you as you internalize all the information with the help of graphics. For comparison's sake, put into words all the steps required to throw a ball toward a target.

In the end, you'll have an understanding of trend that those who don't go through this process can only dream about (and who often insist that there is no such thing).
 
Top