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

Symbol properties

Post by snailbeard »

During the initialization stage, the EA does a lot of pre-processing which reduces the CPU load on each tick. This also has a major affect on the duration of a backtest. String-matching and searching is one of the big CPU hoggers to be avoided. Therefore I have added a couple of flags to the active symbols. In modern programming languages this is quite trivial but in MQL it requires more work:

Code: Select all

//+------------------------------------------------------------------+
//| init_SymbolType
//+------------------------------------------------------------------+
void init_SymbolType(int iPairIndex, string strSymbol)
{

	bool bStockIndexFlag = false;
	bool bForexFlag = false;
	
	bStockIndexFlag = IsStockSymbol( strSymbol );
	setStockIndexFlag( iPairIndex, bStockIndexFlag);	
	
	bForexFlag = IsForexSymbol( strSymbol );
	setForexSymbolFlag( iPairIndex, bForexFlag);
	
	// SANITY CHECK
	if( bStockIndexFlag && bForexFlag )
	{
		Print("initSymbolType(): ERROR: Symbol cannot be both StockIndex && Forex!!! ");
		forceAppExit();
	} 
}
Now we only have to do heavy loading once during the start-up.
When i find parts of the EA which assume its dealing only with forex I can use the flags to help bypass the forex-specific code

Code: Select all

bool getForexSymbolFlag(int iPairIndex)
bool getStockIndexFlag(int iPairIndex) 
So far this only works for UK100:

Code: Select all

07:50:19 zzbb_UK100_mt4b509 _UK100,H1: AUDUSD: Forex
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: EURUSD: Forex
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: GBPUSD: Forex
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: UK100.U: Stock Index
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: USDCHF: Forex
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: USDJPY: Forex
07:50:19 zzbb_UK100_mt4b509 _UK100,H1: _UK100: Stock Index
There are even more varients of names for other instruments:
Alpari: _FRA40, _DE30, _US500
Oanda: FR40EUR, DE30EUR, SPX500USD

And finally although Alpari provides data for two variations UK100, only one of those can be traded and the untradable one is also in the list above and needs to be dropped.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

GBPUSD - Nerves of steel

Post by snailbeard »

The pound has been falling like a stone for several weeks after being far too high (historically) against the dollar. I don't like to trade against such momentum. Nevertheless, D1 ATR has moved back into a useful trading range and a I noticed ZzBb has entered a short range buy trade.

Currently price is trapped between the DP and DR1, if it manages to cross and stay above DR1 then it might work out.
GBPUSD-reverse-scalp-27Aug14.png
Afternoon delight

Well, if I had had the courage to take this trade for real then I would be smiling now:

Code: Select all

Ticket	Open Time	Type	Size	Item	Price	S / L	T / P	Close Time	Price	Commission	Taxes	Swap	Profit
4950323	2014.08.27 11:01:44	buy	0.38	gbpusd	1.65711	1.65436	1.65959	2014.08.27 14:46:47	1.65959	-2.66	0.00	0.00	100.88
You do not have the required permissions to view the files attached to this post.
Last edited by snailbeard on Wed Aug 27, 2014 2:02 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

Watch out for fatty breakfast spreads

Post by snailbeard »

Continuing the work on UK100 trades uncovered a few more issues.

The FTSE 100 has been swinging in a channel this month and I'm wondering if that will continue or is this just a summer holiday for the upward trend? There is a chance of a pullback around WR2.

However, it is good to keep an eye on the spread before taking a punt:
Alapri-UK-breakfast-spread-27Aug2014.png
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

Deceptive bends

Post by snailbeard »

ZzBb makes multiple guesses at the future direction of price, then it has to put the guesses into a hat and pick a ticket.

In the first chart there are indications of a bias to a downward move:
USDJPY-H4-falling-price-19Mar2014.png
However, both the H4 and H1 zigzag pivots hint at a reversal, especially the H1 zigzags.
There are several ways to see these hints: W patterns, upward slanting zigzag with the additional significant support at WMS1. Adding a trend line under the H1 zigzag lower pivots shows a possible rising support line.
It is generally better not to trade down into WMS1 especially when it coincides with another boundary.
USDJPY-H1-rising-boundary-19Mar2014.png
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

Better pattern recognition

Post by snailbeard »

The test results for USDJPY March 2014 are much better after adding several functions to better detect and quantify the patterns discussed above.

In the chart: March 2014: the D1 Bollinger is almost flat, ATR is low and price ranges:
USDJPY-D1-March2014-with-ATR.png
The number and quality of short-term trades has improved:

Code: Select all

1	2014.03.12 03:02	sell	1	0.36	102.858	0.000	0.000	0.00	10000.00
2	2014.03.12 03:02	modify	1	0.36	102.858	103.155	102.622	0.00	10000.00
3	2014.03.12 12:00	modify	1	0.36	102.858	103.135	102.622	0.00	10000.00
4	2014.03.12 16:47	t/p	1	0.36	102.622	103.135	102.622	80.30	10080.30
5	2014.03.12 19:49	sell	2	0.40	102.711	0.000	0.000	0.00	10080.30
6	2014.03.12 19:49	modify	2	0.40	102.711	102.977	102.496	0.00	10080.30
7	2014.03.13 11:30	t/p	2	0.40	102.496	102.977	102.496	78.91	10159.21
8	2014.03.13 17:18	sell	3	0.34	102.508	0.000	0.000	0.00	10159.21
9	2014.03.13 17:18	modify	3	0.34	102.508	103.428	101.622	0.00	10159.21
10	2014.03.13 18:54	modify	3	0.34	102.508	102.508	101.622	0.00	10159.21
11	2014.03.13 19:40	modify	3	0.34	102.508	101.817	101.622	0.00	10159.21
12	2014.03.13 19:41	modify	3	0.34	102.508	101.812	101.622	0.00	10159.21
13	2014.03.13 19:42	modify	3	0.34	102.508	101.805	101.622	0.00	10159.21
14	2014.03.13 19:44	s/l	3	0.34	101.805	101.805	101.622	232.40	10391.61
15	2014.03.19 11:03	buy	4	0.43	101.633	0.000	0.000	0.00	10391.61
16	2014.03.19 11:03	modify	4	0.43	101.633	101.394	101.848	0.00	10391.61
17	2014.03.19 21:01	t/p	4	0.43	101.848	101.394	101.848	87.60	10479.21
18	2014.03.28 14:34	buy	5	0.31	102.378	0.000	0.000	0.00	10479.21
19	2014.03.28 14:34	modify	5	0.31	102.378	102.037	102.684	0.00	10479.21
20	2014.03.28 16:00	modify	5	0.31	102.378	102.140	102.684	0.00	10479.21
21	2014.03.28 16:43	t/p	5	0.31	102.684	102.140	102.684	90.22	10569.43
22	2014.03.31 12:36	buy	6	0.28	103.241	0.000	0.000	0.00	10569.43
23	2014.03.31 12:36	modify	6	0.28	103.241	102.854	103.576	0.00	10569.43
24	2014.03.31 16:00	modify	6	0.28	103.241	103.105	103.576	0.00	10569.43
25	2014.03.31 17:45	s/l	6	0.28	103.105	103.105	103.576	-38.90	10530.53
The last trade made a loss, which might just be par for the course or due to quirks in the new functions.
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

The god of small things

Post by snailbeard »

Looking more closely at the failing trade:

The entry at 12:36 seems a bit late and just under WR1. Price has just moved up from WMR1 and so starting a new trade into WR1 is a bit risky. Also the Fibonacci levels are (in this case) accurate predictors of support and resistance.

The late entry would not be a problem in a multi-day trade as there is now longer term rising upward price action, but the trailing stop loss method combined with the late entry is not giving the trade a chance to breathe.

According to the log file, a potential trade is spotted much earlier, but is getting blocked by a quirk of one of the new functions:

Code: Select all

2014.03.31 11:00  : Potential Buy at DP: bDpM15H1RisingBreak
2014.03.31 11:00  : Potential Buy at WP: bWpM15H1RisingBreak
2014.03.31 11:00  : IsY1Y2H4ZzNoRoom():- 
2014.03.31 11:00  : bH4UbbInsideFlag: 1, bH4LbbInsideFlag: 0
2014.03.31 11:00  : bTooCloseToHighSR: 1, bTooCloseToLowSR: 0
2014.03.31 11:00  : USDJPY: Drop PALC entry: bY1Y2H4ZzNoRoom; iPALCentryDirection: 1
An earlier entry might turn a loss into a profit...
USDJPY-M15-late-entry-quirk-31March2014.png
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

Another one bites the dust

Post by snailbeard »

The late entry was due to a bug in the new code. After squashing that bug we see a better entry price and the trade proceeds to the target profit before the pull-back. ZzBb is also free to re-enter the swing after the pull-back.

Code: Select all

22	2014.03.31 10:22	buy	6	0.25	103.010	0.000	0.000	0.00	10569.43
23	2014.03.31 10:22	modify	6	0.25	103.010	102.578	103.393	0.00	10569.43
24	2014.03.31 12:00	modify	6	0.25	103.010	102.793	103.393	0.00	10569.43
25	2014.03.31 15:53	modify	6	0.25	103.010	103.010	103.393	0.00	10569.43
26	2014.03.31 16:23	t/p	6	0.25	103.393	103.010	103.393	90.85	10660.28
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Reference levels

Post by snailbeard »

A lack of price movement in most pairs has encouraged me to look at the history of the Euro. The Euro only came into being in 1990s and therefore has a fairly limited history, however, in this short time it has managed to do some bizarre things. It is difficult to image the Euro surviving much longer given the nature of politicians, the power of public-sector unions, and the disparate nature of individual economies. In this chart we see some wild swings:
eurusd-weekly-longterm-drop-in-ATR-Sep2014.png
Closer to home: is Scotland moving closer to independence? In the end the uncertainty of walking alone is a concern for many voters. However, Scotland could introduce its own currency and have it backed by an asset such as Scottish Porridge Oats, perhaps it would be called the Groat. For simplicity lets say 1 Groat = 1Kg of Oats, then the new Scottish Banks could promise to pay 1Kg of oats in exchange for each Groat. Of course variations in harvests and consumption could cause some interesting swings in the exchange rate. :D

This would also require some new crosses, for example
GBPGRO
EURGRO
USDGRO

However, there is the possibility of Wales and NI going independent as well so we better use a country prefix
SGR - Scottish Groat
WGR - Welsh Groat
NGR - Northern Ireland Groat

And a lot of people in the North of England feel neglected as well, so perhaps Manchester, Liverpool, Sheffield, Leeds and Newcastle could be part of a new country, in which case Manchester would be the capital, so we also introduce another set of crosses based on MGR - Manchester Groat.

It is a big step to get a divorce, especially when your partner subsidizes your life style, so in the end comfort will probably win over ideology. It was a bribe that convinced the Scots to sell their independence in the first place!

Those of you familiar with works of the genius E.F. Schumacher will remember 'Small Is Beautiful' and Scotland is certainly that. His arguments are too rational for most politicians who generally prefer to spend more than a country can afford to borrow.

In the long term having a proper local currency and careful management of imports (e.g. trade balance) can provide employment and a stable economy. However, my Grandparents had an expectation of income and standard of living which was more realistic and achievable than how we live now. So there could be a significant gap between expectations and reality.

On a more serious note, academics have looked at the concept of regional currencies. Many of our inhumane-economic problems stem from credit, and a trade imbalance is a form of credit. There is a theory that local economies can thrive if they have a regional currency and are not swamped by cheap imports produced in dubious far away factories. However, this is not place for interesting theories...

I was surprised to see such a sharp fall in the value of GBP especially as it happened 'instantly'. Who has the power to make a major currency jump by 70 pips? In the long term this is of no significance. However, EURGBP has two reference levels an old one at 0.7000 and a more recent one at 0.8000. It is amusing to see the euro gain against the pound while the French are pushing their economy and the euro towards a collapse
Des chimères
eurgbp-longterm-view-Sept2014.png
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

Empty4 4 compiler bug update

Post by snailbeard »

MetaCrap still has the the arraysize returning null issue,
(when an array is passed by reference to a function)
which I first reported last century it seems but they do not seem to be interested in fixing it,
which is why the I am still keeping the EA backwards compatible with build 509.
:arrrg:
Now that there are several modern alternative platforms based on .Net in the pipeline I am very excited about using better platforms in the future.

12:48:11 Expert Test670ArraySize: loaded successfully
12:48:11 TestGenerator: spread set to 20
12:48:12 Test670ArraySize test started
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: testTryPassByRef() results:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ix: 5, dy: 5.1, az[ix-1]: 4.0
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ---
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:

Using Dynamic array: test_bwaShift2DimArrayOfInt():
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(localDynArr1) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(testDataIn) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Two dimensions:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArrayRange: iDim0 = 5, iDim1 = 2

12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: : maxsize: 0, dim1: 5, dim2: 2
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ERROR ArraySize returned Zero!
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:

Using Local Static array: test_bwaShift2DimArrayOfInt():
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(localStaticArr1) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(testDataIn) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Two dimensions:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArrayRange: iDim0 = 5, iDim1 = 2

12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: : maxsize: 0, dim1: 5, dim2: 2
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ERROR ArraySize returned Zero!
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:

Using Global array: test_bwaShift2DimArrayOfInt():
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(glbArr1) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(testDataIn) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Two dimensions:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArrayRange: iDim0 = 5, iDim1 = 2

12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: : maxsize: 0, dim1: 5, dim2: 2
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ERROR ArraySize returned Zero!
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Test Failed: testbwaShift2DimArrayOfInt()
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Leaving Oninit()


12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Entering OnTick() First Run...

12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:

Test using GLOBAL array:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:

Using Dynamic array: test_glbShift2DimArrayOfInt():
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(localDynArr1) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArraySize(glbTestDataIn) : 10
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Two dimensions:
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ArrayRange: iDim0 = 5, iDim1 = 2

12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: bwaShift2DimArrayOfInt(): maxsize == 0
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: : maxsize: 0, dim1: 5, dim2: 2
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: ERROR ArraySize returned Zero!
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1: Test Failed: [glb] testbwaShift2DimArrayOfInt()
12:48:12 2013.09.25 05:21 Test670ArraySize AUDUSD,M1:
Leaving OnTick() First Run...
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

ZzBb now compiles & runs on build 670

Post by snailbeard »

Actually, ZzBb compiled many moons ago, but now I have added a work around for the Empty4 ArraySize bug, so that it runs without errors. I no longer need them to fix their crappy software, at least not for this issue.
:party:
Post Reply

Return to “Automated trading systems”