22/03/11

mogalef/pseudo,mogalef

DH=highest[per](high)

DB=lowest[per](low)

//////////difference entre le plushaut et le plus bas

retlungo= (dhh +dbb)/2
////////////////////////////////////////////////////
DHh=highest[perlungo](high)

DBb=lowest[perlungo](low)
if close > retlungo then
   
    alto=dhh
else
    alto=dh
endif

if close > retlungo then
   
    basso=db
else
    basso=dbb
endif
ret90=(highest[90](high)+lowest[90](low))/2
return alto as"bandaup",basso as"bandadown",basso+((alto-basso)/2) as"median bands",exponentialaverage[20](basso+((alto-basso)/2))as"media median bands",ret90 as"ret90",average[150](ret90) as"mediaret90"

06/03/11

cumulative volume delta

Some would call it Accumulation/Distribution, but whatever the name there is some useful insight to be gained by examining it.

Security:   QQQ
Position:   N/A
A common way to understand what has happened during a trading day is to calculate the Balance of Market Power, BMP (see posting "Balance of Market Power," 8/22/2001). BMP consists of the close minus the opening divided by the high minus the low:

BMP = (close-open)/(high-low).

If you multiply BMP by volume and make a running sum by adding each interval's data to the next, you get what some authors call accumulation/distribution, A/D. The calculations for this are:

A/D= cumulative sum of ((close-open)/(high-low))*volume.

However, some (Metastock and Tradestation) use:

A/D=cum((((close-low) - (high-close)) / (high-low)) * volume).

If you do the math it reduces to:

A/D=cum (((2*close-high-low)/ (high-low))*volume),

which some call intraday intensity. Putting aside the labels and dealing with A/D defined with close-open, versus 2*close -high-low, the difference is that when you use two values of closing price you are weighting the indicator towards the closes of the day. When you use a formula like BMP you are asking, how does:

range between close and open (close-open)

compare to:

range between high and low (high-low)?

The range comparison works because on bullish days the open is near to the low and the close is near the high, and just the opposite for bearish days. Between these two extremes, (c-o)/(h-l) goes from +1 to -1.

If you are going to weight volume for a trading signal, why not weight volume using BMP, and then as a refinement make your weighting scheme put emphasis on closing prices. The end result is A/D. So the rule you can use to invent your own volume indicator is to take whatever you have that measures the daily bullishness or bearishness, multiply by volume, and accumulate. When you start to classify indicators as being a form of range sensitivity measurement you'll find that a lot of indicators can be thrown into that category. Inside days, outside days, and NR4 days are examples.


You can go one step further in building your own volume indicators and, rather than accumulate, you could normalize over a period of days. John Bollinger suggests the following:

Sum((2*close-high-low)/(high-low)*volume,21)/Sum(volume,21),

which is to sum your volume-weighted indicator over a period of time and divide by the sum of volume over the same period of time. In the example a 21-day sum of volume weighted by 2*close-high-low is divided by the 21-day sum of volume and I am going to call this normalized A/D.



Figure 1: QQQ Daily Price and Volume (bottom chart) and Normalized A/D (top chart). Normalized A/D is well behaved because: (1) Despite differences in average volume it still moves between the same extremes of +0.3 and -0.3, (2) While QQQ was trending up it was predominantly positive and while QQQ was trending down it was predominantly negative and (3) When normalized A/D exceeds .12 or so it will often continue onto an extreme. Could 0.12, or something close to it, be used as threshold?
Graphic provided by: MetaStock.
Graphic provided by: Data vendor: eSignal<.

If you plot this indicator of a normalized version of A/D, or intraday intensity, of daily QQQ you notice that it is predominantly positive when QQQ is bullish and predominantly negative when QQQ is bearish (Figure 1: top chart). Another nice feature is that when you compare the volume in 1999 with that in 2001 you notice there is considerably more volume for QQQ, but because you have normalized, the extremes of normalized A/D still range between -0.3 and +0.3 (more on this later). The question naturally arises, is this indicator tradeable?


Figure 2: Daily QQQ Price and Volume for 2000 (bottom two charts), ZigZag(75%) Overlaid on Normalized A/D (third chart from top), True/False Conditions for Two Events (second chart from top) and Equity Performance (top chart). Each green up arrow is a long entry, with the exit denoted by a red sign with 'EXIT' in white, and each red down arrow is a short entry with a red exit sign. The third chart from the top shows the true/false condition for long entry, with +1 being the true condition for long entry and -1 the condition for short entry. When ZigZag(75%) exceeds the threshold of +0.12 and is increasing, the long position is true, and when ZigZag(75%) goes below the threshold of -0.12 and is decreasing, the short position is true. The time spent in either a long or short position is equivalent to how long ZigZag(75%) spends going up or down after exceeding the threshold of +0.12 or -0.12.

When I examine June through October 2000 in detail (Figure 2), I see that as I approach a major peak or valley of normalized A/D, QQQ prices are following nicely and all I need to do is exit as soon as the peak or valley is reached. In order to encode a description that a trading system could use, I applied ZigZag at 75% to normalized A/D (Figure 2: third chart from top). Seventy five percent for ZigZag was arrived at by just some quick eyeballing to eliminate unwanted changes in ZigZag so I could capture the major peaks and valleys.

Unfortunately even at 75% I was still seeing small changes about the zero line of normalized A/D so I had to add a filter. I ignored any value of ZigZag(75%) less than 0.12. Now I wanted to see what logic indicators would look like for:

condition1 = ZigZag(75%) increasing and greater than 0.12,

and

condition2= ZigZag(75%) decreasing and less than -0.12.

I got the result I'd hoped for (Figure 2: second chart from top) when I plotted condition1 as 0, +1 and condition2 as 0, -1. I then built the system test and it made a profit (Figure 2: top chart).




Figure 3: QQQ Daily Price and Volume (bottom two charts), True/False Conditions for Long and Short Entry (second chart from top) and Equity Performance. Green long entries predominate during bullish runs of QQQ, while red short entries dominate during bearish runs of QQQ.

The entire performance (Figure 3) met my expectations, including the drawdown in December, 2000. December saw a lessening of bearishness, followed by increased bearishness. This problem could be addressed by using something more sensitive than 75% ZigZag. Figure 3 shows that with a trading system going long when condition1 is true and short when condition2 is true, and exiting whenever they are false, that long trades predominated when QQQ is bullish and short trades when QQQ is bearish.

If you want to get in earlier, then reduce the 0.12 filter for ZigZag; but of course you might want to change ZigZag to something other than 75%. But this is the crux of using this approach. What I did to make it work was observe that normalized A/D is well behaved. Not only it did fluctuate between -0.3 and +0.3 but I also counted on having it either make small changes (abs(normalized A/D) < +-0.12) or major changes. Whether or not this holds for the future depends on how well the market can be measured by BMP or
(2*close-high-low)/(high-low). The Metastock formulas I used are cut and pasted below. You'll notice that I did no optimization.

Long entry:
II:=Sum((2*CLOSE-HIGH-LOW)/(HIGH-LOW)*VOLUME,21)/Sum(V,21);
var1:=Zig(ii,75,%);
cond1:=var1>Ref(var1,-1) AND var1>.12;
cond1>0

Long exit:
II:=Sum((2*CLOSE-HIGH-LOW)/(HIGH-LOW)*VOLUME,21)/Sum(V,21);
var1:=Zig(ii,75,%);
cond1:=var1>Ref(var1,-1) AND var1>.12;
cond1<1

Short entry:
II:=Sum((2*CLOSE-HIGH-LOW)/(HIGH-LOW)*VOLUME,21)/Sum(V,21);
var1:=Zig(ii,75,%);
cond2:=var1cond2>0

Short exit:
II:=Sum((2*CLOSE-HIGH-LOW)/(HIGH-LOW)*VOLUME,21)/Sum(V,21);
var1:=Zig(ii,75,%);
cond2:=var1cond2<1

The statistics are: annual pct/gain loss= 69.23% versus annual buy/hold pct/gain loss=-8.69%, with 22 winning trades, 5 losing trades, average win=$91.96, average loss=-$25.30, biggest win=$447.14, and biggest loss=-$65.59.

A word of caution: Using ZigZag in this kind of trading strategy has an element of looking ahead since ZigZag sees where a turning point is by virtue of knowing prices before and after the turning point. In reality you have two choices you can make to overcome the ZigZag "look ahead." First, given that normalized A/D is well behaved then when it reaches +0.3, or -0.3, then either get out or reverse your position. But obviously +0.3 or -0.3 aren't always going to work because normalized A/D isn't always going to reach those extremes. The second choice is to look at how steep the ascent or descent is of normalized A/D. The detail of Figure 2 is chosen on purpose to illustrate this conjecture. If you compare each of the ZigZag peaks and valleys you'll see the greatest value of normalized A/D was reached when the slope of the ZigZag was the greatest, after breaking the threshold (Figure 2: third chart from the top at the end of August). If you now look at Figure 1 again with the rate of change in mind, you'll see that both negative extremes occurred with the steepest descents. This is a conjecture; the limitations of Metastock do not allow me to explore it in detail, but I suspect that a refinement in looking for an extreme could be found using this technique. In any event, normalized A/D is certainly worthwhile as a confirming indicator and used in conjunction with Bollinger upper- or lower-band walkers should work rather well.





Dennis Peterson
www.finanza.com
info.gif (242 byte)