Cointoss results in less than 50% win consistently. Why?

Posted By: pascalx

Cointoss results in less than 50% win consistently. Why? - 08/31/17 16:28

Hi. I wrote a script as exercise to perform simple buy/sell for each day with plain Stop and TakeProfit levels over a bit of data. The data is sufficiently large to assume a worthy result. My expectation of the coin toss is around 50% win/loss.

Weirdly though, it consistently yields around 47% wins only. Since Stop and TakeProfit levels are supposedly identical, I assumed the chances that the price hits either one of them balances out over large amounts.

Please find attached image/scripts.

The image shows the total number of cointoss wins/losses for all traded assets.

Also: Is it possible to perform multiple runs in one test session? I wanted to rerun the simulation with new random seeds to get a better picture. I tried setting Bar=0, but that resulted in an error for too many trades.

Attached picture cointoss.png
Attached File
CointossWinLoss.c  (15 downloads)
Attached File
utils.h  (8 downloads)
Posted By: Dalla

Re: Cointoss results in less than 50% win consistently. Why? - 08/31/17 20:14

What about commision, slippage and spread? What happens if you add
Code:
Spread = RollLong = RollShort = Commission = Slippage = 0;



Regarding multiple runs; If I understand correctly what you want to do, you should use NumTotalCycles.
http://manual.zorro-trader.com/numtotalcycles.htm
Posted By: firecrest

Re: Cointoss results in less than 50% win consistently. Why? - 09/01/17 08:54

Maybe need to check the assetfix.csv to understand more.
Posted By: pascalx

Re: Cointoss results in less than 50% win consistently. Why? - 09/01/17 09:41

Thank you Dalla.

Originally Posted By: Dalla
What about commision, slippage and spread?

I added this behind selecting the asset() but it does not change the win/loss ratio of 47%.

Originally Posted By: Dalla
Regarding multiple runs; If I understand correctly what you want to do, you should use NumTotalCycles.
http://manual.zorro-trader.com/numtotalcycles.htm

That is it. Nice. I adjusted the cointoss script accordingly to run 100 cycles and change the seed() to force different buy/sells but it consistently has more losers than winners. This does not make sense to me. Find attached a new graphic and script that shows the total amount of win/loss per cycle.

Originally Posted By: firecrest
Maybe need to check the assetfix.csv to understand more.

I am not sure what to look out for. I attach that file too. Let's get to the bottom of it tongue


Attached picture cointoss2.png
Attached File
CointossWinLossCycle.c  (10 downloads)
Attached File
AssetsFix.csv  (3 downloads)
Posted By: GPEngine

Re: Cointoss results in less than 50% win consistently. Why? - 09/02/17 02:24

Try DETREND.
Posted By: johnnyp

Re: Cointoss results in less than 50% win consistently. Why? - 09/02/17 08:59

Why would that help?

The direction of each trade is random, and multiple assets are used, so the price trend can't be influencing the results and there should be an equal number of winners and losers in the long run.

And yet consistently there are fewer winners than losers. Why? What are we missing?
Posted By: pascalx

Re: Cointoss results in less than 50% win consistently. Why? - 09/02/17 11:10

I noticed when decreasing the size of Stop and TakeProfit (scaled by ATR value) the difference becomes more apperent. I set it from 0.5 * volatility to 0.2 * volatility and then the win rate becomes something around 27%.

I think the next logical step is to verify that Stop and TakeProfit have the same distance to the trade opening position. If the Stop is tighter than TakeProfit by a few pips, then that would explain the shift in winning %.
Posted By: AndrewAMD

Re: Cointoss results in less than 50% win consistently. Why? - 09/02/17 23:15

Perhaps the answer is math?

Let's take a simple example, and assume EUR/USD is trading at 1.00 and you have a TP at plus/minus 0.10.

This means TP and SL at either 1.1 or 0.9. That's a 10% loss or 10% gain, right?

.... well, wait a minute. Let's also consider the exact opposite asset USD/EUR.

0.900 EUR/USD = 1.111 USD/EUR, a 9.1% gain from 1.0 USD/EUR.

1.100 EUR/USD = 0.909 USD/EUR, a 11.1% loss from 1.0 USD/EUR.

To win a long position, you have to gain 10% vs 10%.
To win a short position, you have to gain 9.1% vs 11.1%.

Your scale would be smaller, but it might not be insignificant enough to skew the results in a particular direction.


EDIT: Hmm. If I comment out the enterLong line, I get 47% ish wins, whereas if I comment out the enterShort line, I get about 45% ish wins. I think I'm partially correct, but I'm not sure why they're both under 50%.
Posted By: pascalx

Re: Cointoss results in less than 50% win consistently. Why? - 09/03/17 08:57

I attached an updated version to CointossWinLossCycle.c that will print total win/loss percentage after all accumulated cycles.

I wanted to inspect the TRADE values of a given trade but weirdly it has no correct values. Find attached StopVsProfit.c. Also I was wondering why the TRADE struct stores its values with float precision only. Wouldn't you assume that double is generally preferred? I don't know if there is a practical difference in this case, just thought it is odd because everything else is treated as double.

Code:
void run()
{
	if (Bar == StartBar)
	{
		Stop = 50*PIP;
		TakeProfit = 50*PIP;
		TRADE* pTrade = enterLong();
		
		if (pTrade)
		{			
			printf("nEntryPrice [%.7f]", pTrade->fEntryPrice); // 0.000000
			printf("nStopLimit [%.7f]", pTrade->fStopLimit); // 0.000000
			printf("nProfitLimit [%.7f]", pTrade->fProfitLimit); // 0.000000 why???
		}
	}
}




Code:
typedef struct TRADE
{
	float	fEntryPrice;	// buy price, or premium without multiplicator
	float	fExitPrice;	// sell price per unit, without spread
	float fResult;		// current profit of the trade
	float	fEntryLimit;	// buy entry limit
	float	fProfitLimit;	// profit limit price
	float fTrailLock;	// profit target distance to initial price, positive (long) or negative (short)
	float	fStopLimit;	// stop loss limit price
... Much float. Many wow.
} TRADE;



Attached File
CointossWinLossCycle.c  (8 downloads)
Attached File
utils.h  (5 downloads)
Attached File
StopVsProfit.c  (5 downloads)
Posted By: GPEngine

Re: Cointoss results in less than 50% win consistently. Why? - 09/04/17 16:40

The tradeoff here is RAM usage.
Posted By: pascalx

Re: Cointoss results in less than 50% win consistently. Why? - 09/04/17 18:53

Originally Posted By: GPEngine
The tradeoff here is RAM usage.

Ye. I realized the float is ok for price value storage. If it would just give me a value at all... any idea?
Posted By: pascalx

Re: Cointoss results in less than 50% win consistently. Why? - 09/04/17 23:42

Just stumbled over this setting in the manual which explains the coin toss result.
I enabled this setting and finally win/loss yields closer to 50%.
It's good to learn it the hard way. Won't forget it now :-)
"Mystery" solved. Fox Mulder would be proud.

Quote:
TICKS
Tick-precise simulation. Not only the Open, Close, High, and Low of a bar, but also the real price curve inside a bar is used for calculating entry, exit, and profit of trades. TMFs are run on every tick in the simulation, instead of only once per bar. This flag gives a more accurate simulation result, but also requires more time for a simulation cycle, and allocates more memory.
If this flag is not set, an intra-bar approximation is used for simulating entry and exit. In this approximation, a stop loss is always triggered before a profit or trail target, and trades closed by trade functions are sold at the open price of the next bar. This causes a less accurate simulation, which is however sufficient in most cases. TICKS should be used for better precision when many trades enter and exit within the same bar, when stop loss or takeprofit distances are small, or when tick functions or TMFs are used.

http://zorro-trader.com/manual/en/mode.htm
Posted By: johnnyp

Re: Cointoss results in less than 50% win consistently. Why? - 09/05/17 17:26

So, if I understand this right...

Your script enters at the beginning of each bar and exits via the stoploss or takeprofit. Without TICKS, the stoplosses are systematically triggered earlier than takeprofits which explains why there are more loosing trades than winning trades.

Well spotted!
© 2024 lite-C Forums