Archive for March, 2009|Monthly archive page

Directional Bias

Trading on the correct side of the market, or with the market’s directional bias, will not only improve the profitability of your winning trades but will also help you stay out of the losing ones, which is equally important.  However, determining that directional bias (long or short) in the early part of the trading day can be difficult, mostly if the longer moving averages that you typically use to make that determination have flattened.

Dr Clayburg has offered one solution to this problem, the Directional Day Filter.  The indicator uses a few minutes of the market open as an observation period, usually the first 5 or 10 minutes, and captures the high and the low of that period.  The average of those two values then becomes the directional day filter (DDF).  The next 45 to 90 minutes of the trading day are then used to determine where the majority of the price action takes place relative to that DDF.  If the majority of the price action ends up occurring above the DDF, the directional bias for the day will be on the long side, vice versa if the majority of the price action occurs below the DDF.  If price actions is not strongly biased then the day is seen as ‘neutral’ and the trader has the choice of either staying out of what could be a choppy or range-bound market, or on the other hand he/she could take trade on both sides.

As with most of my indicators, I implement the ‘guts’ of the logic in the form of reusable Tradestation functions.  This improves the overall modularity of the code and makes it usable across the different types of Tradestation components without incurring high software maintenance costs.  This indicator is no exception.

The Tradestation function TG_DDF was implemented as follows:

inputs:
 i_DDFEvalStart(numericsimple), // start time for evaluation period of DDF
 i_DDFEvalEnd(numericsimple), // end time for evaluation period of DDF
 i_BiasEvalEnd(numericsimple), // end time for evaluation of bias in relation to DDF
 i_Percent(numericsimple), // minimum percentage required to determine bias
 oDDF(numericref), // returns DDF Value
 oBias(numericref), // returns bias
 oLowD(numericref), // returns intraday low
 oHighD(numericref); // returns intraday high
vars:
 vHighD(0),
 vLowD(9999),
 vDDF(0),
 vAboveBars(0),
 vBelowBars(0),
 vTotBars(0),
 vBias(0); // 0: neutral, 1: up, -1: down
// resets variables at beginning of the day
if date[0] <> date[1] then
begin
 vHighD = 0;
 vLowD = 9999;
 vDDF = 0;
 vAboveBars = 0;
 vBelowBars = 0;
 vTotBars = 0;
end;
// calculates DDF between  i_DDFEvalStart and i_DDFEvalEnd
if time >= i_DDFEvalStart and time <= i_DDFEvalEnd then
begin
 if H > vHighD then vHighD = H;
 if L < vLowD then vLowD = L;
 vDDF = (vHighD + vLowD) / 2;
end;
// calculates intraday low and high from i_DDFEvalStart to i_BiasEvalEnd
if time > i_DDFEvalEnd and time <= i_BiasEvalEnd then
begin
 if H > vHighD then vHighD = H;
 if L < vLowD then vLowD = L;
end;
if vDDF <> 0 and time > i_DDFEvalEnd and time <= i_BiasEvalEnd then
begin
 if L > vDDF then vAboveBars = vAboveBars + 1;
 if H < vDDF then vBelowBars = vBelowBars + 1;
 vTotBars = vTotBars + 1;
end;
if time > i_BiasEvalEnd then
begin
 vBias = 0;
 if vAboveBars > 0 then
 begin
 if vAboveBars/vTotBars > i_Percent then vBias = 1;
 end;
 if vBelowBars > 0 then
 begin
 if vBelowBars/vTotBars > i_Percent then vBias = -1;
 end;
end;
oDDF = vDDF;
oBias = vBias;
oHighD = vHighD;
oLowD = vLowD;
TG_DDF = 1;

The indicator calls that function and plots the necessary visuals:

{
Name: Directional Day Filter
Purpose: Used to determine the major trend of each day and establish a trading bias
Version 1.00 - 3/6/2009 - Initial Implementation
}
inputs:
	i_DDFEvalStart(900), // start time for evaluation period of DDF
	i_DDFEvalEnd(905), // end time for evaluation period of DDF
	i_BiasEvalEnd(1000), // end time for evaluation of bias in relation to DDF
	i_SessionEndTime(1600), // end time for plotting of DDF
	i_Percent(.55), // minimum percentage required to determine bias
	i_BiasUpColor(blue), // color for up bias
	i_BiasDnColor(red), //  color for down bias
	i_BiasNeutralColor(yellow), // color for neutral bias
	i_DDFColor(white); // color of DDF line
vars:
	vDDF(0),
	vBias(0),
	vHighD(0),
	vLowD(0),
	vColor(0),
	vDDFColor(yellow);

Value1 = TG_DDF(i_DDFEvalStart,i_DDFEvalEnd,i_BiasEvalEnd,i_Percent,vDDF,vBias,vLowD,vHighD);

// plots DDF line from i_DDFEvalEnd to i_BiasEvalEnd
if vDDF <> 0 and time > i_DDFEvalEnd and time <= i_BiasEvalEnd then plot1(vDDF,"DDF",i_DDFColor);

// plots vertical lines to display the intraday low and high as of i_BiasEvalEnd
if time = i_BiasEvalEnd then
begin
	Value1 = TL_New(date, time, vLowD, date, time, vHighD);
	Value2 = TL_SetColor(Value1,i_DDFColor);
end;

if time > i_BiasEvalEnd and time < i_SessionEndTime then
begin
	if vBias = 1 then vColor = i_BiasUpColor else
		if vBias = -1 then vColor = i_BiasDnColor else
			vColor = i_BiasNeutralColor;
	plot1(vDDF,"DDF",vColor);
end;

Once rendered on a chart, it will display the directional bias for the day.  Here I have used blue for long, red for short, and yellow for neutral.

screenhunter_03-mar-09-16191

In this case I used a 1 minute chart of the ES for this March 9, 2009.  The settings of the indicator were as follows:

screenhunter_04-mar-09-1621Today the indicator indicated a neutral day, as the price action above the DDF as of 10:00am was not clearly biased to the up side, nor to the down side.  According to Dr Clayburg, this indicator is correct 75% of the time.