Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (AndrewAMD, fogman, Grant, juanex), 972 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Having trouble with TimeFrame #434126
12/13/13 17:32
12/13/13 17:32
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Hello,
I'm trying to understand how to properly use the TimeFrame feature. I'd like to have the capability to use multiple timeframes in some of my strategies.

The problem might be my understanding of how this works: if I'm understanding the manual correctly, it seems that BarPeriod is the smallest increment of time, and TimeFrame would be a multiple.

If that understanding is correct, then theoretically:
BarPeriod = 60

should be "roughly equivalent" to:
BarPeriod = 5
TimeFrame = 12

...except for the issues regarding day/hour boundaries that are noted in the manual.

So I tried to utilize the sample code like this:
Code:
// Let time frame start when Event == true
// f.i. frameAlign(hour() == 0); aligns to midnight
function frameAlign(BOOL Event)
{
	TimeFrame = 1;
	vars Num = series(0); // use a series for storing Num between calls
	Num[0] = Num[1]+1;    // count Num up once per bar
	if(!Event) 
		TimeFrame = 0;      // continue current time frame
	else
	{
		TimeFrame = -Num[0]; // start a new time frame
		Num[0] = 0;          // reset the counter	
	}
}

function run()
{
	BarPeriod = 5;
	TimeFrame = 12;
	frameAlign(minute() == 0);
...



But unfortunately this doesn't seem quite right either. I am trying to simulate BarPeriod = 60 via the code above, but the results are way off.

Thanks in advance for any tips on this laugh

Re: Having trouble with TimeFrame [Re: dusktrader] #434145
12/14/13 16:24
12/14/13 16:24
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Here's another example that might be easier to follow (you can actually test it). I just took Workshop 4 and added the TimeFrame code (taken from another example in the manual).

I am just trying to understand what I'm doing wrong that these to examples are not equal.

The default Workshop 4 with BarPeriod 60 gives me:
Quote:
Lookback set to 141 bars
BackTest: dt-timeframe-Workshop4_2 EURUSD 2008..2013
Profit 62$ MI 1$ DD 25$ Capital 26$
Trades 336 Win 23% Avg +18.5p Bars 107
AR 52% PF 1.49 SR 0.61 UI 15.4% Error 41%


Then commenting out the BarPeriod=60 and commenting-in the TimeFrame section I get:
Quote:
Lookback set to 141 bars
BackTest: dt-timeframe-Workshop4_2 EURUSD 2008..2013
Profit 31$ MI 0$ DD 13$ Capital 15$
Trades 339 Win 14% Avg +9.2p Bars 804
AR 47% PF 1.36 SR 0.41 UI 27.4% Error 46%

(the Result charts look very different as well)

Code:
// Workshop 4: Trend Trading ///////////////////
#include <profile.c>

function run()
{
	BarPeriod = 60;

/*
	BarPeriod = 5;
	TimeFrame = 12;
	// create a top-of-the-hour-aligned price series
	static int numBars = 0;
	numBars++; // count the number of bars per hour
	TimeFrame = 0; // during the frame
	if(minute() == 0) { // top-of-the-hour
		TimeFrame = -numBars; // end the frame
		numBars = 0;
	}
*/

	vars Price = series(price());
	vars Trend = series(LowPass(Price,1000));
	vars Signals = series(0);
	
	Stop = 4*ATR(100);
	
	if(valley(Trend)) {
		Signals[0] = 1;
		if(Sum(Signals+1,3) == 0)  // no signals in the previous 3 bars?
			enterLong();
	} else if(peak(Trend)) {
		Signals[0] = 1;
		if(Sum(Signals+1,3) == 0)
			enterShort();
	}
	
	PlotWidth = 600;
	PlotHeight1 = 300;
//	plotTradeProfile(50);
	set(LOGFILE); // log all trades
}


Re: Having trouble with TimeFrame [Re: dusktrader] #435177
01/03/14 17:39
01/03/14 17:39
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
jcl, could you please comment if this is an issue with "TimeFrame" not working correctly, or if I am doing something wrong here?

I'd love to be able to use multiple TimeFrames in a multi-asset strategy, but so far I do not understand how it is working (or if there is something wrong).

THANKS

Re: Having trouble with TimeFrame [Re: dusktrader] #435448
01/08/14 09:38
01/08/14 09:38
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
As far as I see, your code looks correct and the result also looks correct.

Setting a time frame is similar, but not exactly identical to setting the bar period. There are subtle differences. For instance, the stop loss in your example above will normally be triggered at a different time, because there are several bars inside the time frame and not just one. You can see the differences in detail when you compare both logs.

Re: Having trouble with TimeFrame [Re: jcl] #435586
01/09/14 11:54
01/09/14 11:54
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Thanks for your reply jcl. I'm still researching this.

Could you please take a look at this screenshot comparing the above example with BarPeriod (left) vs. TimeFrame (right) and see if it looks normal?

I understand there may be slight differences between entry/exit triggers due to the differences in the way the bars align when using TimeFrame.

But can you explain how multiple trades show the same entry/exit values yet calculate a different profit? I just want to understand how this can be possible.

Thanks

Attached Files barperiod-vs-timeframe.png
Re: Having trouble with TimeFrame [Re: dusktrader] #435597
01/09/14 14:10
01/09/14 14:10
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
Due to different slippage. At least that would be my immediate guess. In the simulation, slippage is simulated and does not currespond to a real price on the price curve, so it is not visible in the Entry and Exit price.

Set Slippage to 0 and then run the simulation again - do you now get the same profit?

Re: Having trouble with TimeFrame [Re: jcl] #435602
01/09/14 14:47
01/09/14 14:47
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
Yes they are now identical. Thank you for clearing this up! I learned something new.

Re: Having trouble with TimeFrame [Re: dusktrader] #435828
01/14/14 21:05
01/14/14 21:05
Joined: Jul 2013
Posts: 522
D
dusktrader Offline OP
User
dusktrader  Offline OP
User
D

Joined: Jul 2013
Posts: 522
When using a different TimeFrame for each asset (in a basket portfolio), is it necessary / recommended / required to align the frames?

The reason I ask is because I'm wondering why it would matter, if the strategy can be profitable without aligning the frame. For example, if you have a BarPeriod of 5 and a nonstandard TimeFrame of 7 (that would be 35min bars)... is there a necessity to align the frame to the 0 minute?

When you start a simulation with Zorro is it building that first 35-minute bar from the start date specified? In that case, it seems like it could be a problem because then in live trading it would build from the time you pressed Trade.

I'm just trying to visualize why or if a frameAlign routine is necessary. It adds extra processing and I'm wondering if it is needed.

Thanks

Re: Having trouble with TimeFrame [Re: dusktrader] #435831
01/14/14 23:17
01/14/14 23:17
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi dusktrader. Not sure I follow your question exactly, but have you looked at BarOffset and FrameOffset? They seem to do what you're talking about and the manual states they default to 0...

The manual also includes this Remark:

Code:
If multiple time frames and different trade time offsets are not required, set the time frame with BarPeriod only. This uses the lowest possible number of bars and results in the highest speed for testing and training.



So it appears you may do whatever Offset(s) you like, presumably including optimizing them.

Re. sim start, I recall being told that in Test Zorro picks the exact start of the 1st Bar - it may not be the exact Start boundary - which would also of course determine the 1st Frame...

If your strategy is time-critical to the minute, I would think yes, you'd have to code some kind of alignment delay to enforce it. OTOH, that would also seem to be a pretty fragile strategy? Possibly even dangerous?

HTH.

Re: Having trouble with TimeFrame [Re: DdlV] #435838
01/15/14 07:46
01/15/14 07:46
Joined: Jul 2000
Posts: 27,935
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,935
Frankfurt
According to our experiences, strategies with time frames less than 4 hours should work regardless of aligning. From 4 hours on aligning becomes important, especially with one-day time frames, and different assets will require different alignment.

Note that when aligning time frames you can't use oversampling anymore.

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1