Combining daily and intraday scales in a single strategy
Author: calvingee
Creation Date: 12/6/2013 3:53 PM
profile picture

calvingee

#1
Is it possible to combine daily and intraday scales in a single strategy?
profile picture

Eugene

#2
See the WealthScript Programming Guide > Multi-Time Frame Analysis.

profile picture

calvingee

#3
I took a look at it and I don't understand. Is it possible to get help with coding the following:

Bar[Volume,15] > 3 * MovingAverage[MA,Volume,20,0,15] OR
Bar[Volume,D] >= 1.5 * MovingAverage[MA,Volume,20,0,D] AND
MovingAverage[MA,Close,20,0,15] >= MovingAverage[MA,Close,20,0,15,1] AND
MovingAverage[MA,Close,20,0,D] >= MovingAverage[MA,Close,20,0,D,1] AND
Bar[Close,D] >= ParabolicSAR[PSAR,0.02,0.02,0.2,1] AND
Bar[Close,D] >= ParabolicSAR[PSAR,0.02,0.02,0.2,5] AND
Bar[Close,D] >= ParabolicSAR[PSAR,0.02,0.02,0.2,15]

Thanks in advance
profile picture

Eugene

#4
It would be optimal if you'd use English for trading rules, as it's not clear if, by analogy with the 15-min SMA on previous bar in line #3, you meant to say "take the previous value of Parabolic" - or that was "Parabolic on 1-minute bar scale" in line #5. In this ambiguous situtation I take it as 1-minute SAR.

Here's your rule:

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

calvingee

#5
Eugene,

Thanks for your reply. Below I have tried to word the rules in English to clarify your code.

The Volume over the current 15 minute period is greater than 3 times the current 20 period 15 minute Moving Average Volume OR
The Volume over the current Daily period is greater than the 1.5 times the current 20 period Daily Moving Average Volume AND
The 20 period SMA over the current 15 minute period is greater than the 20 period SMA over the prior 15 minute period AND
The 20 period SMA over the current Daily period is greater than the 20 period SMA over the prior Daily period AND
The current price is greater than the current 1 minute PSAR AND
The current price is greater than the current 5 minute PSAR AND
The current price is greater than the current 15 minute PSAR

What I looking for is a volume spike and up trending SMA and PSAR

Thanks
profile picture

Eugene

#6
Calvin,

This is what I coded. The lack of parentheses makes your rules ambiguous, too. So if your intention was to OR the 2 first conditions, add a couple of parentheses like this:

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

calvingee

#7
What would the optimum data range and scale for this strategy?
profile picture

Eugene

#8
I leave answering your question entirely up to you, as you're supposed to trade it -- not me! :) After all, now you have the right tool for this job (WLP).
profile picture

calvingee

#9
I am thinking it needs to be a 1 minute scale with a data range of 20 days to accommodate all of the time frames in the strategy.
profile picture

Cone

#10
If the idea is so that it runs as fast as possible, yes, only the load the data that you need. For live trading, I also suggest that you create a Workspace with Strategy Window(s) have as few as possible Performance Visualizers loaded. (You don't need all that backtest post-processing running every minute while you're trading.)
profile picture

hhashim1

#11
Eugene, I have used the code you have provided in post #4. Below is the code. It is giving me volume for the previous day and not today. Any idea why that would be? I have copied the whole script from post #4 and added a few more lines to it not changing the base of the script.

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

Eugene

#12
You can find that question already answered in a previous conversation: see reply #8 in this thread. The volume for today is not known since the day has not ended.
profile picture

hhashim1

#13
I am not looking for the volume of the day. I am looking for volume or other data points of the previous 15 minute bar. I understand you cannot get data for the current bar until it is closed. I am running a 1 min strategy and then checking a 15 minute data (volume for the purpose of testing). 1 min volume works fine but not 15 min. Here is the code I have so far.

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

Cone

#14
Instead of making the effort at calculating the compressed bar number, just use the Synchronized series instead. After RestoreScale(), do this:

CODE:
Please log in to see this code.

Then you can use the 1-minute bar number to get the value in the compressed scale. and, you can plot the series in the chart.
profile picture

hhashim1

#15
I made the changes that you had suggested. However, I think there is something else missing. I keep getting wrong values for 15 minute Volume regardless of the bar. The value I am getting is 91104 which is not for any bar from today or yesterday. I did go ahead and draw a pane for 15 min volume and also for RSI. It seems that the values are coming out right (at least for volume and close enough for RSI) but I cant seem to extract these values in PrintDebug statements. What am I doing wrong? Here is the code that I have so far.

Parameters:
Scale=1 Minute
Data Range = 5/12/2014 - 5/13/2014
Symbol = Z

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

Eugene

#16
QUOTE:
I keep getting wrong values for 15 minute Volume regardless of the bar. The value I am getting is 91104 which is not for any bar from today or yesterday.

The value is taken from 15-min compressed data built up from 1-minute source. Don't look it up in ATP, Yahoo Finance, Bloomberg, or the "genuine" 15-minute chart for comparison (which again would be comparing apples to oranges). The compressed values should be correct if compared to the source 1-min data.
profile picture

hhashim1

#17
I am comparing the values from PrintDebug to the values on the chart in Wealth-Lab.
profile picture

Eugene

#18
To be precise, you're comparing one value at fixed bar #25 (roughly at the start of the data).

I'm doing that too and the values always match:
CODE:
Please log in to see this code.


Not seeing any problem.
profile picture

hhashim1

#19
Voila!!! I had tried the same code from above but I was getting an error Out of Range: index or something of that nature so I changed it to static bar number for the purpose of debugging. It works now! Not sure why it would not work before. You are a genius!!! :-)

Thank you!
profile picture

hhashim1

#20
Ok. I am pulling my hair on this one. I cant figure out how to make this script work for what I have in mind. The code is below. Make sure to only have 3 symbols in the dataset if you plan on running the script as it may take a while to run due to debug messages.

The script runs for the most part but the output numbers are incorrect. What I mean is that this script is supposed to add daily volume per symbol and add it to a variable to keep a running total. What I would like is that the running total gets reset at the end of the day or start of the day and the total is kept for each symbol. The way it works now is that the volume keeps added to sv and eventually to todVol from start to end of the time range and for all symbols and the variable does not keep track of volume per symbol. Hope this makes sense. Can you help me figure out how to accomplish this? I have tried to work with lists but cant get them to work like I want them to work.

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

Eugene

#21
QUOTE:
What I mean is that this script is supposed to add daily volume per symbol and add it to a variable to keep a running total.

Let's start by finding out what is the objective of your script? Why do you think you need the running total for each given symbol? Just to make sure we won't be reinventing some wheel (there may be an existing prototype).
profile picture

hhashim1

#22
The objective of have a running total volume for each symbol goes back to our discussion of having the ratio of intraday volume to its average volume. If I access the Volume call on a daily bar, the value I get is of yesterday which is the last completed bar. Anything less than daily would give me the value for the last completed bar and running total with 1 minute bar gives me the closest intraday volume. In the final sorted list I need to have the symbol, its running intraday volume and the average ratio between intraday and average volume. I hope this helps.
profile picture

Eugene

#23
And what's most important, what are you planning to do with that final sorted list? The script has worked as of post #19, so why this complication in the subsequent post?
profile picture

hhashim1

#24
Well, its the same concept. In your post #18, you had helped me with 15 minute bar. I realized that 15 minute was too large of a number for what I am trying to do. That is why I dropped it down to 1 minute. But regardless of 1 minute or 15 minute, the problem is still there. If I run the script on an intraday live chart, the calculations would come out right as there is not past data on the chart and only intraday. But as soon as I backtest and add historical data, the volume does not get reset everyday. On top of that, the script from #18 only works for one symbol and not multiple symbols in a dataset. The cummalative volume includes all of the symbols in the dataset and includes all of the historical data included in the data range.

The reason why I have this script is to create a dynamic watch list that I can further add studies on. This is like my first cut of the watch list before I move on to the next. If you remember one of my other posts of Top 10 list based on Volume -> http://www.wealth-lab.com/Forum/Posts/Top-10-list-based-on-Volume-34074
profile picture

Eugene

#25
In my post #23 in the thread you've just cited, there's an easter egg. Check this method out:

public double GetPartialBarVolume(string symbol)

This method grabs the partial Daily volume from Yahoo! in real-time (actually, there may be 15-minute delay which isn't so important). You can use that instead of compressing the source series. As a bonus, your code will get simplified. If you get to employing the method, please consider discussing its use in the original thread.
profile picture

hhashim1

#26
Yahoo data is 15 minutes delayed and that is why I did not end up using that function. 15 minutes delay is too long for day trading.

Let me ask you this - Is this tool not intended for day trading?
profile picture

Eugene

#27
To update daily SMA on intraday chart, you might want to give this a go:

Mixing intraday and daily data > Updating a Daily indicator using Intraday values
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).