Strategies based on multiple time frames?
Author: walzmark
Creation Date: 10/6/2011 9:41 AM
profile picture

walzmark

#1
Has any one attempted or had success with developing strategies which evaluate triggers based on multiple time analyses?
Say you have a trigger based on a moving average crossover on a 30 min basis.
I would also like to consider the state of the same moving average crossover on a daily basis.
So if the daily crossover is in an uptrend, how effective is my 30 minute strategy.
If the daily crossover is in a downtrend, then how effective is my 30 minute strategy.
Any suggestions or input is greatly appreciated.
profile picture

Eugene

#2
See the WealthScript Programming Guide > Multi-Time Frame Analysis > Intraday/Daily etc.

Plus many examples available by searching the forum for the keywords like multiple time frame, SetScaleDaily/SetScaleWeekly etc., in the Wealth-Lab Wiki (Knowledge Base section).
profile picture

sedelstein

#3
This is related. I'm somewhat suspicious of the opening prices that are officially recorded as the stocks "open"
The strategy I am looking at is daily, and generally execute via BuyAtMarket(bar+1), the next day's open

I've done some searching but have not found what I was looking for.
Is there example code that someone can point me to that uses an end-of-day signal but delays the buy until the open of the first, say, 5 minute bar? This will give me some idea of the slippage I might experience using opening prices

Thanks for the help
profile picture

Eugene

#4
Have you checked the GetSessionOpen property in the QuickRef?
profile picture

sedelstein

#5
Yes,

I know I can get the opening price out of the database. What I am saying is that the stock may have an opening range and in real trading, one never gets the "official" opening price. This opening range can be much wider than the typical bid/offer spread one might observe later in the day. By instituting a delay, I am hoping to get some idea of how different results might be by delaying. Might you have an example of how to do this?
profile picture

Eugene

#6
Well, you could access intraday data from Daily and set execution time by activating Daily Strategy Scheduling in Strategy Monitor. However, I'm not sure if execution time can be shifted to next date.
profile picture

sedelstein

#7
So there is no way to Set Scale to Daily, generate a signal at end of day, reset the scale to intraday and execute on the 2nd bar of the next day?

To be clear, are you saying that it's not possible to do this?

profile picture

Eugene

#8
Of course you can do that with intraday data. You created an impression of staying with Daily data: "The strategy I am looking at is daily,..." For examples, please refer to post #2 above.
profile picture

sjendoubi

#9
I was trying to use the Lowest.Series(Close,5) of daily time frame in an intraday strategy, but it did not work for me.
I took a code from the the WealthScript Programming Guide > Multi-Time Frame Analysis > Intraday/Daily
and modified it, but I found that I can not go back more than one day. I found out that for example
iDay.Close[bar-1] = iDay.Close[bar-2] = iDay.Close[bar-3]..... and this will note allow me to find the lowest price for 5 days.

Here Copy of the code that I was using (change the iDay.Close[bar-2] to iDay.Close[bar-1] and see for yourself that the graph does not change)
Any thoughts are really appreciated.

Thanks

CODE:
Please log in to see this code.
profile picture

Eugene

#10
QUOTE:
I was trying to use the Lowest.Series(Close,5) of daily time frame in an intraday strategy, but it did not work for me.


Not sure what's the connection of the intraday bar - 2 (you're requesting the value from) with Lowest.Series. Give this example a try:

CODE:
Please log in to see this code.
profile picture

sjendoubi

#11
I want to find the lowest value of the last 5 days closing price.
It is the Lowest.Series(Close,5), but it is not in the code submitted above, because it did not work for me.

Let's say Lowest.Series(Close,5) = Close[bar-2] for example.
If I use iDay.Close[bar-2] it gives me iDay.Close[bar-1].
if I use iDay.Close[bar-k] for k>=2 it still gives me iDay.Close[bar-1]???


if I use:

CODE:
Please log in to see this code.


I got the following error:



Thanks
profile picture

Eugene

#12
QUOTE:
I want to find the lowest value of the last 5 days closing price.

Could you put away your coding experiments and tell me in plain English what trading rules you want to have coded as clear as possible?
profile picture

sjendoubi

#13
This is what I want to do:

1) In a daily chart if the price go below the Lowest.Series(Close,5)[bar-1] then I will look if the price will bounce back today in a 15 Minutes chart.
let's say: (intraday Close[bar] = 5), Close[bar-1] = 6, Close[bar-2] = 5.2, Close[bar-3] = 5.7, Close[bar-4] = 5.1 and Close[bar-5] = 5.6
therefore Lowest.Series(Close,5)[bar-1]=Close[bar-4] = 5.1

5. < 5.1 =====> my daily condition is met.

2) Intraday price is now 5, I will watch the stock if it reverses back from here or it will continue down.
If it reverses back in a 15 Minutes Chart I want to buy the stock.

Thanks

profile picture

Eugene

#14
This makes it clearer. Here's example code to be executed on an intraday chart. It marks the bar (and price) when the intraday Close drops below the lowest 5-day Close, waits indefinitely for a pullback above the trigger price, and sells EOD. It's for backtesting only.

CODE:
Please log in to see this code.
profile picture

sjendoubi

#15
Eugene,

Thank you very much for your help. Your help was very beneficial and useful. I learned a lot from the code that you provided and I will be using the ideas and suggestions that you provided for many of my strategies.

Thank you again and keep the good work.
profile picture

Eugene

#16
Slah, glad I could be of assistance!
profile picture

tomphm

#17
Hi Eugene,

Say my strategy is operating in daily bars and if I need to get access to intraday data, can I use GetExternalSymbol to get symbols from an intraday dataset and then pass these symbols to SetContext - such that this allows the strategy to operate in intraday data mode? Thanks.
profile picture

Eugene

#18
Hi Tom,

You're right, and it's been the topic of a Knowledge Base (Wiki) article known as:

Intraday / Multi-Time Frame | Accessing Intraday data from Daily
profile picture

tomphm

#19
Eugene, thanks for the quick reply. I looked at the article and intraday data for some symbols will have short days (not all intraday bars will be present) or will have missing dates and this makes the simple shift method mentioned difficult to work properly. Also, when the intraday Bars is synchronized to that of daily Bars, intraday data will be truncated - which is not what I wanted.

What I would like to accomplish is to be able to switch from running a strategy in daily Bars mode to an intraday mode (say 5 minutes) which will having all the symbols synchronized and in 5 minutes scale. I understand this approach is not straight forward. There are couple possible approaches that I can consider:

1. Manually do the synchronization of intraday data within a strategy that operates on daily data
2. Perhaps using the multi-systems approaches mentioned in https://www.wealth-lab.com/Forum/Posts/Call-one-strategy-from-another-29752 IF it allows each system to have its own time frame (say one system is operated in daily and another is in intraday). I don't know if this is allowed - hence the approach might not possible.

Do you have a suggestion on what approach might be appropriate for what I am trying to do? Thanks.
profile picture

Cone

#20
I just reviewed and corrected the wiki page referenced in the post referenced by Eugene's post. (The series shift operation is not required, so the corrected solution works fine for any intraday data, missing bars, or short days, etc. )
http://www2.wealth-lab.com/WL5WIKI/kbAccessLowerTimeframe.ashx
profile picture

Cone

#21
Re: running a strategy in daily Bars mode to an intraday mode

You have to think of this the other way around. You need the base time scale to be an intraday chart to trade intraday. You can scale up to Daily by using the same type of synch operation outlined in that wiki article or using SetScaleDaily();

If we're missing something about your requirements, let us know more specifics.
profile picture

tomphm

#22
Thank you Cone for your help and for correcting the error. It really good to know the solution mentioned the article can work with incomplete intraday data. Thank you both.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).