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

Zero spreads

Post by snailbeard »

Coming from brokers like Alpari and IG the idea of zero spreads seemed like science fiction. Their monster spreads and spread widening events made it seem that there can never be any such thing as a zero spread, but recently I opened a demo account with FxOpen and noticed warning messages from ZzBb about zero spreads. On investigating further I opened a New-Order dialog and watched the spread for a while and sometimes the spread actually goes briefly to zero. I don't know if it is possible to open or close trades when the spread is zero but it will be interesting to try.

I'll add a flag to ZzBb to only trade on zero spreads and see if it ever opens any trades.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Basket case

Post by snailbeard »

After another week of tweaks, single-pair back-testing, multi-pair forward-testing the results are some what baffling, at least difficult to understand without a lot of effort. Perhaps I have pulled the carpet from under my own feet with too many things happening at once and trying to manage some live trades at the same time. I need a lie down
:uff:

The first thing I noticed is some dodgy forward-test trades that are correctly filtered out in back-tests. One possible explanation is contamination of variables when looping through different pairs. This would not happen if I had develop the trading logic in a proper language and avoided shared temporary variables which I use to speed up MetaCrap's script for run time analysis and back testing. Forward testing is one shot, so if I don't have enough information in the log file first time when an event happens then each time I need more debugging it could be days before I might get a similar event.

A simple solution is not to basket trade at all, instead run one copy of ZzBb per pair. I'm also thinking about using a separate log file for each pair with more verbose logging, which would be easier to cross reference with back-tests. That would make it easier to spot cross-contamination of variables.
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

logging with MetaCrap

Post by snailbeard »

MetaCrap provides some new classes for file handling but they don't provide some typical methods that are mandatory in modern programming languages: example: Append()

It was hard work to do such a simple thing and difficult to find much in the way of examples, so I provide one here:

Code: Select all

//+------------------------------------------------------------------+
//| LogIt() 
//+------------------------------------------------------------------+
void LogIt( string strFileSuffix, string strMessage )
{
	// filename format: yyyymmdd + "_" + pair + ".txt"
	
	CFileTxt cFileLog;
	
	string strFileName;
	datetime dtDate = TimeCurrent();
	string strTime = "";

    stStrToday = getTodayString(); // yyyymmdd
    	
	if( StringLen(stStrToday) < 1 )
	{
		strLastLogName = "";
		Print("LogIt: incomplete file name!");
		strFileName = "";

		return;
	}
	strFileName = stStrToday + "_"+ strFileSuffix + ".txt";
	
    //uint uHandle = cFileLog.Open(strFileName, FILE_WRITE); // recreate file
    uint uHandle = cFileLog.Open(strFileName, FILE_READ|FILE_WRITE); // almost append
    if( uHandle < 1 ) {
		strLastLogName = "";
		Print("CFileTxt: Open: Name:"+ strFileName+ " FAILED!");
		return;
	}

	FileSeek(uHandle, 0, SEEK_END); // because MetaCrap lacks .Append()
	
	strTime = clockTimeAsString() + " "; // HH:MM
	strMessage = strTime + strMessage + "\n";
	
	uint uBytes = cFileLog.WriteString(strMessage);
	if( uBytes < 1 ) {
		Print("CFileTxt: WriteString to:"+ strFileName+ " FAILED!");
		strLastLogName = "";
	}
	
	strLastLogName = strFileName;
}
This should work in forward test as well as back test and it should be easier to cross reference any differences between the two.

The file location depends on the mode:
Empty4-runtime-logging-by-day.png
and finally the content needs the time of the event as well, but the name of the pair not necessary but is useful if using 'grep':
Empty4-daily-tracking-by-pair.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

buy EURUSD???

Post by snailbeard »

That is not a recommendation!

However, the monthly Fibonacci Levels tell an interesting story about monthly cycles.
Taking the high and low of June as the reference levels then we get several falling extension levels:
161.8, 261.8 & 423.6
These levels are important to somebody or something and so are the weekly pivot and mid-pivot levels so we see pauses at these levels and the daily bars just dance around these levels for a while.
The Euro had a nose bleed in early September and reached 423.6 ahead of schedule, the price has moved too far too soon and now crawls upwards. This might continue for a while or there could be another nose bleed. However, 1.30 has long term significance and it'll be interesting to see how the rest of this month plays out.

ZzBb has bought the EURUSD twice recently and made the target, whereas my attempt to follow this trade just made me nervous and I killed it so that I could concentrate on GPBUSD, AUDUSD, USDCAD.
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

compare the broker dot com

Post by snailbeard »

There are several forward tests running including: Armada, GlobalPrime and FxOpen. However, the comparisons should be taken with a pinch of salt because the setups are not exactly the same and duration too short to be reliable.

Armada is the odd one out because it is running in basket mode whereas the other two are running one EA per chart.

One trade which is common to all was: 22:00 sell AUDUSD and that was running, although, I thought it might have been filtered out by reversal detection. It did actually run a profit for a while and would have made a good short trade, more on that later, but first the broker results:

Unless anyone has information to the contrary these are all genuine brokers who don't interfere with the trades of their customers like the market-maker brokers:
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

bugzilla for metaquotes Empty4

Post by snailbeard »

After discovering another bug in metaquotes Empty4 I am wondering if we should start an independent bugzilla for recording some of the more fundamental bugs that crawl out of Empty4 but don't get squished by the developers.

The latest discovery affects strategy tester which used to work until recently.

The problem relates only to PERIOD_MN1 and iClose/iOpen etc.
It only manifests when trying to back test a short period of recent history, I never noticed it before
========================================================================
When using the strategy tester 'Use date' option:

15:10:41 Expert zzbb_mt4b670 USDCAD,M1: loaded successfully
15:10:41 TestGenerator: spread set to 20
15:42:24 2014.09.15 00:00 zzbb_mt4b509 USDCAD,M1: Now have enough D1 bars to start back testing: counted: 6
<snip>
15:42:24 2014.09.15 00:00 zzbb_mt4b509 USDCAD,M1: checkBacktestForMissingBars() : iTimeFrame:43200, waiting for enough bars in history

========================================================================

Untick strategy tester 'Use date' option:

16:04:57 2014.04.28 00:00 zzbb_mt4b670 USDJPY,M1: Now have enough D1 bars to start back testing: counted: 6
16:04:57 2014.04.28 00:00 zzbb_mt4b670 USDJPY,M1: OK: checkBacktestForMissingBars() : iTimeFrame:1, iMinBackBars: 1440, dClose: 102.31200
<snip>
16:04:57 2014.04.28 00:00 zzbb_mt4b670 USDJPY,M1: OK: checkBacktestForMissingBars() : iTimeFrame:43200, iMinBackBars: 1, dClose: 103.21400
16:04:57 2014.04.28 00:00 zzbb_mt4b670 USDJPY,M1: Run once DoFirstRunSetup()

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

Jumping stops

Post by snailbeard »

There are no perfect stop trailing and profit locking mechanisms. However, one currency pair might require a different method to another pair and even the same pair requires different methods according to the market or how far the trade has gone.

Sometimes the method of trailing makes the difference between a method which is profitable or lossy.

This week there were more losing trades than last week and analysis of the losses suggested several improvements and bug fixes. In this chart we have a perfectly good entry turned into a loss by the jumping stop method coming into play too soon:
usdchf-h1-bad-jumping-stop-17Sept14.png
Which led to the following:

Code: Select all

4	2014.09.17 17:55	buy	2	0.30	0.93479	0.00000	0.00000	0.00	10089.86
5	2014.09.17 17:55	modify	2	0.30	0.93479	0.93126	0.93775	0.00	10089.86
6	2014.09.17 20:00	modify	2	0.30	0.93479	0.93305	0.93775	0.00	10089.86
7	2014.09.17 21:01	s/l	2	0.30	0.93305	0.93305	0.93775	-57.82	10032.04
After improved logging and introducing a delay before jumping:
20:00 USDCHF: : JumpSL: bUseJumpingH4HLStop: bDoneMinHoursForJump:false
...
21:01 USDCHF: : Switched from Previous JumpSL to ExtraProfitLock because: closer to target

Code: Select all

4	2014.09.17 17:55	buy	2	0.30	0.93479	0.00000	0.00000	0.00	10089.86
5	2014.09.17 17:55	modify	2	0.30	0.93479	0.93126	0.93775	0.00	10089.86
6	2014.09.17 21:02	t/p	2	0.30	0.93775	0.93126	0.93775	92.56	10182.42
Until I have looked at other pairs and over a logger period I won't know if this is generally correct or requires more tweaking...
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

Mystery pivot levels

Post by snailbeard »

Last week I was trying to figure out why the pivot levels on the screen were different to the levels in the debug log file of a back test. At first I thought it was a discrepancy between the Ask/Bid price and the candle close price. This certainly happens and after adding code to catch and count how many times these prices don't match it turned out to be only a small proportion of all samples.

The pivot calculation code has been well used and tested but something that caused headaches in the past was deciding how to treat Sunday candles. Options are
IFF Sunday candle exists
1 combine with Friday since Friday closes early
2 ignore Sundays
3 add Sunday to Monday

Since most people use the later this is what ZzBb and the indicators do. However, what happens if part of the history data has Sunday candles and more recent history data does not?
:uff:

Yes this was the cause of the discrepancy! So I have had to modify the Sunday candle code. It is now refreshed at the beginning of each new day. It is not a huge difference here but it can mean the difference between trade setup going ahead or not.

It seems that some brokers have changed from having Sunday candles to not having them.
You do not have the required permissions to view the files attached to this post.
Radar
Trader
Posts: 437
Joined: Fri Mar 23, 2012 5:39 pm
Location: Round the bend ;)

Bring your own Zero Hour...

Post by Radar »

Hey Snailbeard,

I've been using a basket stats indicator that shows the hourly win/loss (plus totals) for each symbol you trade. It starts with market open as hour 0.

I've had a look at the code, but I can't see how he's done it (I still have an L-plate firmly affixed to my forehead).

It got me thinking, though (not a good thing), and there may be a couple of ways around the Sunday candle "feature"...

1. Have the EA do its own time tracking, so that hour 0 is at market open, and pull the daily close price from the H1 24 hours later. That way you'll have 5 sessions of 24 hours, and it won't matter if the history has a combination of +/- Sunday. This would be easiest, as far as backtesting is concerned.

2. Run the EA on an offline chart that is configured to have 5 daily bars per week. Not so easy to backtest, though.

I think we need to get away from thinking "Sunday to Friday" (or "Monday to Saturday" for us in downunderland), and just think "Day 0 to Day 4" (or "Day 1 to Day 5", if you prefer). Anyways...

I've added the basket stats indie, and P4LPeriodCon (for making offline charts), so you can see which would be the best way to go.

Have fun!

Radar =8^)
You do not have the required permissions to view the files attached to this post.
Check out my new, (well, old now), manual trade & automatic scale-in manager,
StackManV2
User avatar
snailbeard
Trader
Posts: 615
Joined: Mon Dec 24, 2012 10:54 am
Location: Just above water somewhere between Oxford & Cambridge

Bring your own Zero Hour...

Post by snailbeard »

Radar » Sat Sep 27, 2014 7:22 am wrote:Hey Snailbeard,

I've been using a basket stats indicator that shows the hourly win/loss (plus totals) for each symbol you trade. It starts with market open as hour 0.

I've had a look at the code, but I can't see how he's done it (I still have an L-plate firmly affixed to my forehead).

It got me thinking, though (not a good thing), and there may be a couple of ways around the Sunday candle "feature"...

1. Have the EA do its own time tracking, so that hour 0 is at market open, and pull the daily close price from the H1 24 hours later. That way you'll have 5 sessions of 24 hours, and it won't matter if the history has a combination of +/- Sunday. This would be easiest, as far as backtesting is concerned.

2. Run the EA on an offline chart that is configured to have 5 daily bars per week. Not so easy to backtest, though.

I think we need to get away from thinking "Sunday to Friday" (or "Monday to Saturday" for us in downunderland), and just think "Day 0 to Day 4" (or "Day 1 to Day 5", if you prefer). Anyways...

I've added the basket stats indie, and P4LPeriodCon (for making offline charts), so you can see which would be the best way to go.

Have fun!

Radar =8^)
Hi Radar,

Thanks for sharing the utilities.

If it was only pivots which were bugging me I could spend more time on them, but the real mysteries have yet to be uncovered! More on that later.
It might be time to post a summary for September though...
Post Reply

Return to “Automated trading systems”