Top 10 list based on Volume
Author: hhashim1
Creation Date: 5/7/2014 3:33 PM
profile picture

hhashim1

#1
I am new to Wealth-Lab and I need help in figuring out how to code my strategy.

I need to create an intraday strategy (10 minute) using a Top 10 list that is based on my Watch list. I have 30 symbols in my watch list and on any given day, I want to start off by having a Top 10 Active Stocks based on my static watch list. I define Active Stocks by comparing their 10 day SMA with 50 day SMA. Whichever SMA is lower is what I use to compare to the intraday volume. The top 10 from this list will be used as a base watch list for additional studies from which I could go Long or Short.

Any help would be greatly appreciated!
profile picture

Eugene

#2
Welcome to the forums Hussain.

How exactly are you making this comparison with the intraday volume? That's not clear.
QUOTE:
I define Active Stocks by comparing their 10 day SMA with 50 day SMA. Whichever SMA is lower is what I use to compare to the intraday volume.
profile picture

hhashim1

#3
Eugene,

Thanks for your prompt response and your help. I do not know how to compare in Wealth-Lab. Greater than and Less than do not work when comparing the MA's. I come from ThinkorSwim and it is basic math calculation with greater than or less than to compare. Here is what I have so far in Wealth Lab but have not figured out past that.

CODE:
Please log in to see this code.


Here is the code that I have in ThinkorSwim that works. This will give you an understanding of what I am trying to do.
CODE:
Please log in to see this code.
profile picture

Eugene

#4
Here's how in C# you can use the ternary operator to compare double values:
CODE:
Please log in to see this code.


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

hhashim1

#5
Eugene,

Thanks for your help. This definitely gets me going in the right direction. I do have a question. How can I get the 10-day and 50-day volume averages? Seems like it is getting a 10 and 50 period average. Since I am running this strategy on a 10 minute chart, the averages are based on 10 minutes rather than daily.

Here is my updated code:

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

Cone

#6
The moving average volumes are positively daily, but "Volume[bar]" is in the intraday scale because you haven't created a daily Volume series.

Do this and divide dailyVolume by avg in your test.

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

hhashim1

#7
Ok. I am now getting the daily volume and averages. But not at the right time. It seems the volume and the averages are for the previous day. What am I doing wrong?

Here is sample data and code.

Sample:
4/29/2014 3:50:00 PM
Z VAR = 1.33240832410115
Z Volume = 2247047
Z SMA 10 = 1960841.6
Z SMA 50 = 1686455.24

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

Eugene

#8
Of course you're getting them for the previous, complete day. The current session has not ended yet. And you have not mentioned before that any value should represent the today's incomplete bar that can change during the day, isn't it?
profile picture

hhashim1

#9
Please see my first post when I mentioned I want to compare average volume to intraday volume. Anyways, is it possible to get the intraday Volume for what I am trying to accomplish?
profile picture

hhashim1

#10
Eugene,

I found a Wiki page that has a sample code for intraday volume. However, I need to download and install the Community Indicators and Components. I am a demo user. How can I download these extensions to be able to do what I am trying?

Here is the Wiki page if you are interested.

http://www2.wealth-lab.com/WL5Wiki/CIV.ashx
profile picture

Eugene

#11
It turned out that your specification in post #3 was misleading. Please clarify what intraday volume do you mean exactly, and which parts of the code should be modified.
profile picture

hhashim1

#12
I want to run my strategy on a 10 minute scale and compare intraday volume(todays volume during open market) to lets say 10 day SMA. Hope this helps.
profile picture

Eugene

#13
If it only takes replacing the Daily volume with today's incomplete volume, then instead of CIV you could simply sum all volume up to the current bar. I think this is going to do the trick:

EDIT: code updated, fixed 2 errors

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

hhashim1

#14
I can see how this should work but for whatever reason I am not getting the correct volume. I modified the code to run on just one stock (Z). Here is the sample. Today's volume for Z is 1,875,360 (excluding any after market volume). According to the debug data, the final volume is 1441747 which is incorrect. Thoughts?

Sample:
sv = 1283359
5/9/2014 3:50:00 PM
Z Volume = 1283359

sv = 1441747
5/9/2014 4:00:00 PM
Z Volume = 1441747


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

Eugene

#15
My code sums up the volume from intraday bars directly. If you're looking at the Daily volume, then you're comparing apples and oranges.
profile picture

hhashim1

#16
Help me understand this. Why would the sum of the volume from intraday bars be different than daily volume of the same day?
profile picture

Eugene

#17
There were two coding glitches that made it discard the first and the last bar's volume.

1. There was one error in my code above [edited], making it drop the first intraday bar's volume:
CODE:
Please log in to see this code.

Replace it as follows and the resulting number will be correct:
CODE:
Please log in to see this code.



2. Another error that I "borrowed" by copying and pasting your code that came unnoticed [edited] lead to excluding the last bar's volume:
CODE:
Please log in to see this code.

Replace:
CODE:
Please log in to see this code.


Hope this helps.

QUOTE:
Why would the sum of the volume from intraday bars be different than daily volume of the same day?


This is a question for data vendors. Explained in detail here:

43.7 - Comparing Daily Volume to Intraday Chart Bar Volume
profile picture

hhashim1

#18
Much better now :-). I did realize that the script is not taking into account Pre-Market and Post-Market data and therefore the volume is a bit off from the total daily volume. Is there a way to include Pre and Post Market Volume? I tried looking at the QuickRef but I did not find anything for Pre and Post Market. Can you help me?
profile picture

Eugene

#19
QUOTE:
Is there a way to include Pre and Post Market Volume?

On your intraday setup? I'd say no, if Fidelity's static intraday data does not include pre/after-market volume.
profile picture

hhashim1

#20
Ok Thanks. I have added the 10 day and 50 day SMA back into the script and I am now getting errors again. Here is the error I get from just the section on the bottom. I have added the top of the function to show where the calls are in the function. smaVol10 and smaVol50

Error:
Error processing symbol Z Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

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

hhashim1

#21
Please disregard the previous post. I think I figured out the problem. Has to do with the date range I have set. I am assuming not enough days for 50 day SMA.
profile picture

hhashim1

#22
Eugene, now that I have the SMA's and intraday volume working, how can I put Top 10 symbols in a list and use this list as a base for the next strategy? Or can I add all of the symbols from my watch list into a list and sort the list with Sort ID? Then I can get the top 10 from this list based on the Top 10 Sort ID's.
profile picture

Eugene

#23
For example, here's how:
CODE:
Please log in to see this code.
profile picture

hhashim1

#24
This is great. Thank you!

Ive got so much to learn :(
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).