Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 946 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
BarPeriod + TimeFrame issue #461742
08/18/16 21:40
08/18/16 21:40
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I developed a script with a BarPeriod of 1440 and then wanted to integrate that one into a portfolio script that used a BarPeriod of 60.

For this to work I set the TimeFrame for the code of this script to 24 so that again it would result in daily trade signals.

I expected the simulation results to be the same but they weren't. With BarPeriod 60 and TimeFrame 24 I got a much lower AR.

Running the following script with different settings shows what I mean. Not only the AR but also the number of trades is different.

Code:
function run()
{
	BarPeriod = 1440;
	TimeFrame = 1;
	
	//BarPeriod = 60;
	//TimeFrame = 24;
	
	StartDate = 2015;
	EndDate = 2016;
	
	asset("EUR/USD");
	
	Stop = 20 * PIP;
	if (NumOpenTotal == 0)
		enterLong();
}



From the documentation about TimeFrame I assumed this should be the same. What am I missing?

Re: BarPeriod + TimeFrame issue [Re: trenki2] #461743
08/19/16 09:46
08/19/16 09:46
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It is not the same, but very different. Use the frameSync function for synchronizing time frames. Details are explained in the manual under "BarPeriod" with several examples.


Re: BarPeriod + TimeFrame issue [Re: jcl] #461746
08/19/16 10:05
08/19/16 10:05
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
Ok, I tried to use frameSync() as in the examples but I still get very different results. What else might be wrong:

Code:
#define H24 (1440/BarPeriod)	

function run()
{
	//BarPeriod = 1440;
	//TimeFrame = 1;
	
	BarPeriod = 60;
	TimeFrame = frameSync(H24);
	
	StartDate = 2015;
	EndDate = 2016;
	
	asset("EUR/USD");
	
	Stop = 20 * PIP;
	if (NumOpenTotal == 0)
		enterLong();
}


Re: BarPeriod + TimeFrame issue [Re: trenki2] #461751
08/19/16 11:04
08/19/16 11:04
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Probably because your 1440 version ignored intrabar prices for the stop. Use the TICKS flag.

You can find out yourself why your strategy does what it does by looking into the log. Compare the logs and you see where any differences come from.

Re: BarPeriod + TimeFrame issue [Re: jcl] #461752
08/19/16 11:18
08/19/16 11:18
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I tried with set(TICKS). It just made the simulation slower, but the results were almost exactly the same.

Will have to take a look at the logs ...

Re: BarPeriod + TimeFrame issue [Re: jcl] #461755
08/19/16 11:50
08/19/16 11:50
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
I looked at the logs and found some differences:

* The logs start at different dates:
60: [1: Fri 02.01.15 02:00] 1.20660
1440: [1: Tue 06.01.15 00:00] 1.19460

* The first trade happens at different times.
60:
[19: Sun 04.01.15 23:00] 1.20090
[EUR/USD::L1901] Long 1@1.2000 Risk 2$ at 23:00

1440:
[1: Tue 06.01.15 00:00] 1.19460
[EUR/USD::L0101] Long 1@1.1936 Risk 2$ at 00:00

* Sunday trades don't happen at midnight but at 23:00.
So frameSync() does not help that trades get opened at daily bar starts?

[19: Sun 04.01.15 23:00] 1.20090
[EUR/USD::L1901] Long 1@1.2000 Risk 2$ at 23:00

* The number of trades is different
60: 39
1440: 19

I tried to set Lookback = 0 as i suspected it might have something to do with the logs starting at different times but that was not it.

Here is the code that generated my logs:

Code:
function run()
{
	set(TICKS + LOGFILE);
	LookBack = 0;
	
	if (0)
	{
		BarPeriod = 1440;
		TimeFrame = 1;		
	}
	else
	{
		BarPeriod = 60;
		TimeFrame = frameSync(24);		
	}
	
	StartDate = 2015;
	EndDate = 2016;
	
	asset("EUR/USD");
	
	Stop = 20 * PIP;
	if (NumOpenTotal == 0)
		enterLong();
}


Attached Files
Testtest60.txt (2 downloads)
Testtest1440.txt (1 downloads)
Last edited by trenki2; 08/19/16 12:03.
Re: BarPeriod + TimeFrame issue [Re: trenki2] #461758
08/19/16 15:18
08/19/16 15:18
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
For starting at a certain date, use a 8-digit start date such as 20150102 (must not be a weekend). And for trading at Monday 00:00, set StartWeek = 10000.

Re: BarPeriod + TimeFrame issue [Re: jcl] #461763
08/19/16 16:17
08/19/16 16:17
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
When I set StartDate = 20150101 and StartWeek the logs still start at different times:

Code:
60:
Test: Test EUR/USD 2015..2016
[1: Fri 02.01.15 02:00]  1.20660

1440:
Test: Test EUR/USD 2015..2016
[1: Tue 06.01.15 00:00]  1.19460



The results differ less but the number of trades is still different and the times at which they are entered do not match either.

Since 20150101 is actually a holliday i tried with StartDate = 20150105.

The log with 60 now starts at the expected time. The log with 1440 has the first line with Tue 06.01.15.

The initial trades now seem to be entered at the same time and the stop loss is also triggered at the same time. But the entry and exit price is slightly different between both logs:

Code:
60:
[47: Wed 07.01.15 00:00]  -2 +0 0/1
[EUR/USD::L4702] Long 1@1.1872 Risk 2$  at 00:00
...
[EUR/USD::L4702] Stop 1@1.1852: -1.83 at 09:59

1440:
[2: Wed 07.01.15 00:00]  -2 +0 0/1
[EUR/USD::L0202] Long 1@1.1870 Risk 2$  at 00:00
[EUR/USD::L0202] Stop 1@1.1850: -1.82 at 09:59



The number of trades is also off by 1.

The trade that is entered on Monday 19.01.15 is stopped out at a different time:

Code:
60:
[231: Mon 19.01.15 00:00]  -17 +0 0/9
[EUR/USD::L3110] Long 1@1.1561 Risk 2$  at 00:00
...
[273: Tue 20.01.15 18:00]  -17 -1 0/10
[EUR/USD::L3110] Stop 1@1.1541: -1.83 at 18:14

1440:
[10: Mon 19.01.15 00:00]  -16 +0 0/9
[EUR/USD::L1010] Long 1@1.1559 Risk 2$  at 00:00

[11: Tue 20.01.15 00:00]  -16 +3 1/9
[12: Wed 21.01.15 00:00]  -16 -1 0/10
[13: Thu 22.01.15 00:00]  -16 +5 1/9
[EUR/USD::L1010] Stop 1@1.1538: -1.85 at 13:41



Trade L7911 from the 60 log does not happen in the 1440 log.

Trade L1512 from 1440 and L4713 from 60 are started at the same time but the stop time does not match. The same goes for L4918 from 1440 and L1619 from 60.

These seem to be all the differences. Is this a bug?

Current code:
Code:
function run()
{
	set(TICKS + LOGFILE);
	LookBack = 0;
	
	StartDate = 20150105;
	EndDate = 20160105;
	StartWeek = 10000;
	
	if (0)
	{
		BarPeriod = 1440;
		TimeFrame = 1;		
	}
	else
	{
		BarPeriod = 60;
		TimeFrame = frameSync(24);		
	}
	
	asset("EUR/USD");
	
	Stop = 20 * PIP;
	if (NumOpenTotal == 0)
		enterLong();
}



Attached Files
Testtest60.txt (1 downloads)
Testtest1440.txt (1 downloads)
Last edited by trenki2; 08/19/16 16:20.
Re: BarPeriod + TimeFrame issue [Re: trenki2] #461765
08/19/16 17:08
08/19/16 17:08
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
100% identical trades are unlikely due to random slippage. You can simulate no slippage by setting Slippage = 0. This should then eliminate the differences, at least all that I can think of.

Re: BarPeriod + TimeFrame issue [Re: jcl] #461766
08/19/16 17:33
08/19/16 17:33
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
Even setting Slippage = 0 does not eliminate the differences. The two trades from the logs above that started on 19.01.15 did indeed result in almost the same loss but one was stopped out two days earlier than the other. I don't think that can be because of slippage.

I've modified the example. Now I count the number of trades opened. When TradeNum is even I go long, otherwise I go short.

With BarPeriod 1440 i get 7 Trades. With BarPeriod 60 i get 18 Trades. This is a big difference.

Maybe that is because even though the entry time is the same the logs report a different entry price between the 1440 and 60 version. Why is that?

Code:
function run()
{
	Slippage = 0;
	
	set(TICKS + LOGFILE);
	LookBack = 0;
	
	StartDate = 20150105;
	EndDate = 20160105;
	StartWeek = 10000;
	
	if (1)
	{
		BarPeriod = 1440;
		TimeFrame = 1;		
	}
	else
	{
		BarPeriod = 60;
		TimeFrame = frameSync(24);		
	}
	
	asset("EUR/USD");
	
	static int TradeNum = 0;
	
	Stop = 20 * PIP;
	if (NumOpenTotal == 0)
	{
		if (TradeNum++ % 2 == 0)
			enterLong();
		else
			enterShort();
	}
}


Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1