Zigzag Bollinger Band

Post Reply
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Results of ATR based entry filtering

Post by snailbeard »

Great results from carefully applying ATR to the timing of entries:
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Possible use of ATR to help with early exits

Post by snailbeard »

I am wondering if I can use the ATR checks to spot trades which are not moving.
The code is already there and it needs testing:

Code: Select all

20140425.log:108477: , xbWeakAtrExit: 1, xbVeryWeakAtrExit: 1
20140425.log:115108: , xbWeakAtrExit: 1, xbVeryWeakAtrExit: 1
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

A tale of two indicators

Post by snailbeard »

I have been reworking the ATR logic a bit for better performance on EURUSD which was a bit sluggish recently. Very few trades as ZzBB used Bollinger width as a clue to volatility. However, on reflection perhaps it is better to use Bollinger width to adjust the targets. The additional analysis from ATR means it is possible to enter less ambitious trades at better times, rather than late entries at better Bollinger width but suboptimal ATR.
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Crouching tiger, hidden dragon

Post by snailbeard »

ZzBb has been struggling to find tradable entries on EURUSD. Is it an issue with ZzBb or is it an issue with my expectation that it should find more entries?
Does this weekly chart of EURUSD answer any doubts?
You do not have the required permissions to view the files attached to this post.
Last edited by snailbeard on Tue Apr 29, 2014 12:21 pm, edited 1 time in total.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Is MetaCrap still running cached EA?

Post by snailbeard »

After lots of compiler iterations and several restarts of MetaCrap how does it manage to show the old revision number?
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

MetaCrap now finally shows the latest version

Post by snailbeard »

I deleted the .ex file and restarted MetaCrap,
it reported an error loading the EA,
then closed MetaCrap again,
recompiled the ZzBb,
restarted MetaCrap,
added ZzBb to a chart from the Navigator and finally...
the correct version!
What a palaver :roll:
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Variations on a theme

Post by snailbeard »

The correct timing of entries reduces the chance of hitting a stop-loss or running out of swing.
I have recently discovered that ZzBb often has suboptimal entry timing, which does not seem to be a problem in trending markets but is more important when the market is sluggish.

If there are other pairs moving well then it would be better to ignore the sluggish pairs, but if that is not possible then making better entries in a weak pair is an option. In the chart below the market is moving mostly sideways. Watching ATR and ADX can help improve the timing:
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Waiting for Godot

Post by snailbeard »

I seem to end up wasting a lot of time do nothing productive due to reported errors in the log file. These errors can occur when changing from one pair ro another pair or from old history data to recent history or copying the EA onto a different broker or version of MetaCrap. Things would be more staight forward if there was just one version of the platform and one dataset. However, an EA has to be tested against different brokers and different pairs. Usually an error in the log file is a bug in the EA due to code changes but occassionally it is just crappy broker data with missing bars on one time frame or another.

There is already some code which waits for several days of history to elapse before trying to do anything, but I recently had a new issue with GlobalPrime's recent history, which had got better but now I find that about two months of M15 bars are missing from September/November 2013. Normally its the M1 bars which don't go back as far as the higher timeframes so that is what I have relied on so far until now.

It is not hard to check the history of all timeframes for enough bars so I added a couple of functions to help skip over the initial history until all timeframes are available. Instead of getting reams and reams of secondary errors in the log file it is now reduced to a few lines and the reason for it.

"TotalMissingBars" is wrong it is actually the number of ticks/minutes that elapsed until all the required bars were found.

Code: Select all

06:40:47 2013.09.20 10:13  zzbb_mt4b509 GBPUSD,M1: *** init() FINISHED ***
06:40:47 2013.09.20 10:13  zzbb_mt4b509 GBPUSD,M1: Need more D1 bars: counted so far: 1
06:40:47 2013.09.23 00:00  zzbb_mt4b509 GBPUSD,M1: Need more D1 bars: counted so far: 2
06:40:47 2013.09.23 00:01  zzbb_mt4b509 GBPUSD,M1: Need more D1 bars: counted so far: 3
06:40:47 2013.09.24 00:00  zzbb_mt4b509 GBPUSD,M1: Need more D1 bars: counted so far: 4
06:40:47 2013.09.25 00:00  zzbb_mt4b509 GBPUSD,M1: Need more D1 bars: counted so far: 5
06:40:47 2013.09.26 00:00  zzbb_mt4b509 GBPUSD,M1: Now have enough D1 bars to start back testing: counted: 6
06:40:47 2013.09.26 00:00  zzbb_mt4b509 GBPUSD,M1: checkBacktestForMissingBars() : iTimeFrame:15, waiting for enough bars in history
06:40:47 2013.11.26 23:30  zzbb_mt4b509 GBPUSD,M1: checkBacktestForMissingBars() : stiTotalMissingBars: 63226
History now has enough bars to continue
Here is the code in case anyone else finds this useful:

Code: Select all

//+------------------------------------------------------------------+
//|   nextTimeFrame() 
//|   
//+------------------------------------------------------------------+
bool nextTimeFrame(int iCurrTimeframe, int& iNextTimeframe)
{
	bool bValidTimeframe = true;
	
	iNextTimeframe = 0;
	
	//int  allTimeframe[]={1,5,15,30,60,240,1440,10080,43200};
	switch(iCurrTimeframe)
	{
		case 0 : iNextTimeframe = 1; break;
		case 1 : iNextTimeframe = 5; break;
		case 5 : iNextTimeframe = 15; break;
		case 15 : iNextTimeframe = 30; break;
		case 30 : iNextTimeframe = 60; break;
		case 60 : iNextTimeframe = 240; break;
		case 240 : iNextTimeframe = 1440; break;
		case 1440 : iNextTimeframe = 10080; break;
		case 10080 : iNextTimeframe = 43200; break;
		
		default:
			return(false);
	}

	return(bValidTimeframe);
}

//+------------------------------------------------------------------+
//|   getMinBackbars() 
//|   
//+------------------------------------------------------------------+
int getMinBackbars(int iTimeframe)
{
	
	int iBarsRequired = 0;
	
	//int  allTimeframe[]={1,5,15,30,60,240,1440,10080,43200};
	//How many backbars does the EA require for each timeframe?
	// Perhaps enough for several days...
	switch(iTimeframe)
	{
		case 0 		: iBarsRequired = 0; 	break;
		case 1 		: iBarsRequired = 1440; break;
		case 5 		: iBarsRequired = 288; 	break;
		case 15 	: iBarsRequired = 250; 	break;
		case 30 	: iBarsRequired = 48; 	break;
		case 60 	: iBarsRequired = 72; 	break;
		case 240 	: iBarsRequired = 30; 	break;
		case 1440 	: iBarsRequired = 5; 	break;
		case 10080 	: iBarsRequired = 2; 	break;
		case 43200 	: iBarsRequired = 1; 	break;
		
		default:
			return(0);
	}

	return(iBarsRequired);
}

/* -----------------------------------------------------------
	checkBacktestForMissingBar()
----------------------------------------------------------- */
bool checkBacktestForMissingBars()
{
	static bool stbFullyLoaded = false;
	static bool stbReported = false;
	static int stiTotalMissingEvents = 0;
	bool bFxBarsMissing =  true;
	
	if( (IsTesting() == false) && (IsVisualMode() == false))
		return(false);
		
	if( stbFullyLoaded )
		return(false);
		
	int iMinBackBars = 0;
	int i=0;
	int tf = 0;
	int iTimeFrame = 0;
	for(tf=0; nextTimeFrame(tf, iTimeFrame); i++)
	{
		iMinBackBars = getMinBackbars(iTimeFrame);
		
		double dClose = iClose(NULL, iTimeFrame, iMinBackBars);
		
		if( dClose < EPSILON ) 
		{
			stiTotalMissingEvents++;
			
			if( stbReported == false )
			{
				Print("checkBacktestForMissingBars() : iTimeFrame:", iTimeFrame, ", waiting for enough bars in history");
				stbReported = true;
			}
			return(bFxBarsMissing);	
		}
		tf = iTimeFrame;
	}
	
	stbFullyLoaded =  true;
	if( stiTotalMissingEvents > 0 )
	{
		Print("checkBacktestForMissingBars() : elapsed ticks/minutes: ", stiTotalMissingEvents, "\n", "History now has enough bars to continue");
	}
		
	bFxBarsMissing = false;
	return(bFxBarsMissing);
}


User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Adx Atr and EMA

Post by snailbeard »

I haven't posted for a while because I thought I would wait and see if anything useful came out of some experiments with ATR, ADX and Multiple Moving Averages. It has been like going back to the start because my first autotrader was based on multiple moving averages and when there was a well defined swing it made lots of pips. However, i was at the beginning of the journey and quite out of my depth. So here I am again back where I started but hopefully armed with a few extra tricks.

The problem with MAs is that they cannot be used as described in the text book and the same applies to ADX and ATR as well. Instead there are multiple MAs on both H4 and M15. H4 is used to inhibit trading except when price is moving consitently accoridng to the H4 timeframe. I also have several fast MAs and these must be consistent with each other and the Bollinger band.

If H4 has a confirmed swing then M15 is used to narrow down a window for enries. It wasn't my intention to trade directly from ADX & MAs, but under some market conditions this alone produces fantastic results.

I started this work because the ZzBb swing/volatilty analysis became too complicated and inorder to simply that part I needed something independent to reliably identify current price direction in M15 and H4 timeframes.

So far I have not been able get any additonal benefit from adding ATR.

The idea is to now merge the good parts of ZzBB with the MTF-MA & ADX.

The following results were obtained for backtesting two months from August 2010 for AUDUSD:
You do not have the required permissions to view the files attached to this post.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

ADX and super slippage

Post by snailbeard »

Having previously said that ADX sometimes helps filter out bad entries, we must consider the cost of being late to the party and understand why experienced traders never use lagging indicators to time their entries.
I'm curious why most authors of trading books only show the positive side of these indicators, is it because they rely on most traders to lose money so that they can continue to make money?

On H4 the current swing has been confirmed to be in the sell direction, so on the M15 chart I have labelled some alternative entry levels depending on entry method. When M15 prices move smoothly ADX can give reasonable timing but in this chart M15 is a bit choppy so we get a very poor ADX based entry price.
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Automated trading systems”