Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Need Filter or Realcode help in Stockfinder Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
techohio
Posted : Tuesday, January 29, 2013 1:50:01 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Hi, can you help me create a filter that will find stocks who's price has exceeded the close of any bar within the last 5 days when the volume exceeded 2 times the 50day moving average volume?

Breaking this down a bit further into components, we have to figure out which bar in the past met the condition of the the volume exceeding 2 times the 50-day moving average.  Then we have to determine what the close of that bar was so that we can filter real time if the current close exceeds the close of that bar.

I'm not sure if a filter is the answer or some combination of real code conditions and indicators along with a filter.

Appreciate any help you can provide.

Thanks,

StockGuy
Posted : Tuesday, January 29, 2013 2:19:33 PM

Administration

Joined: 9/30/2004
Posts: 9,187

You could create a RealCode condition using the following:

If (price.value > price.value(1) and volume.value(1) > 2 * volume.avg(50,1)) or (price.value > price.value(2) and volume.value(2) > 2 * volume.avg(50,2)) or (price.value > price.value(3) and volume.value(3) > 2 * volume.avg(50,3)) or (price.value > price.value(4) and volume.value(4) > 2 * volume.avg(50,4)) or (price.value > price.value(5) and volume.value(5) > 2 * volume.avg(50,5)) then Pass

 

Bruce_L
Posted : Tuesday, January 29, 2013 2:34:53 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Maybe something similar to the following RealCode Condition?

'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com 
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Price Above High Volume
'|******************************************************************
If CurrentIndex >= 55 Then
	Dim Bench As Single = Single.MinValue
	For i As Integer = 1 To 5
		If Volume.Value(i) > 2 * Volume.AVG(50, i) Then
			Bench = System.Math.Max(Bench, Price.Last(i))
		End If
		If Bench > Single.MinValue Then
			If Price.Last > Bench Then
				Pass
			End If
		End If
	Next
Else
	SetIndexInvalid
End If

Please note that the above RealCode compares the current price to the highest close during the prior 5-bars where Volume is more than twice the 50-Period Simple Moving Average of Volume when there is more than one such bar.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Tuesday, January 29, 2013 2:53:48 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Won't that only tell me which stocks met that condition over the last 5 days?  How does it tie today's current price, at this very moment,  to the close of "n" bars ago?  

Here's what I'm looking for example, if the last time stock XYZ's volume was greater than 2 x the 50-day moving average volume was 4 days ago (or 2 days ago), and the close 4 days ago (or 2 days ago) was $100, but right now its trading at $99, I want a filter or condition that will tell me when stock XYZ crosses back above $100 real time (right now).

This allows me to scan for the stocks that meet that criteria every minute. Some of those stocks will jump in and out of my filtered list through out the day, i.e. some will cross above $100 and show up in my filtered list and some will cross back below and disappear from my filtered list.  

Does that make sense and is that achievable to create a condition or filter that compares the current realtime price with a price from "n" bars ago based on a condition being met "n" bars ago?

 

 

techohio
Posted : Tuesday, January 29, 2013 2:55:24 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Bruce,  my last response was in reply to StockGuy.  I just read your response.   Will that accomplish was I tried to explain further to StockGuy?

Thanks

techohio
Posted : Tuesday, January 29, 2013 2:56:40 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Also for Bruce, what is the significance of CurrentIndex >=55?  Please explain the 55.

 

Thanks,

Bruce_L
Posted : Tuesday, January 29, 2013 2:59:36 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

The CurrentIndex check is to make sure there is enough data to calculate a 50-Period Simple Moving Average of Volume for the oldest of the five bars against which the current price might potentially be checked.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Tuesday, January 29, 2013 3:03:01 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Ok.. so if I want to compare against a 100 - Period Simple Moving average, I need to say

CurrentIndex >=110 , for example?

StockGuy
Posted : Tuesday, January 29, 2013 3:03:22 PM

Administration

Joined: 9/30/2004
Posts: 9,187

QUOTE (techohio)

Won't that only tell me which stocks met that condition over the last 5 days?  How does it tie today's current price, at this very moment,  to the close of "n" bars ago?  

You're right.  Corrected my code.  No need to set Passing 1 of 5 with this.

Bruce_L
Posted : Tuesday, January 29, 2013 3:08:33 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

If you were to change:

		If Volume.Value(i) > 2 * Volume.AVG(50, i) Then

To:

		If Volume.Value(i) > 2 * Volume.AVG(100, i) Then

Then you would also need to change:

If CurrentIndex >= 55 Then

To:

If CurrentIndex >= 105 Then

The value used is the period of the moving average plus the number of prior bars being checked.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Tuesday, January 29, 2013 3:18:39 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Thank you Bruce.  Just what I needed. 

Regards,

Paula

techohio
Posted : Thursday, January 31, 2013 2:50:05 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Bruce,

Using your example above

If CurrentIndex >= 55 Then
	Dim Bench As Single = Single.MinValue
	For i As Integer = 1 To 5
		If Volume.Value(i) > 2 * Volume.AVG(50, i) Then
			Bench = System.Math.Max(Bench, Price.Last(i))
		End If
		If Bench > Single.MinValue Then
			If Price.Last > Bench Then
				Pass
			End If
		End If
	Next
Else
	SetIndexInvalid
End If

There could be multiple bars that meet the Vol > 2* 50 period moving average volume.  This example assigns the Maximum value of the qualifying bars.  How do I set this to just assign the 1st bar the array encounters that meets this criteria.  i.e. if the 2nd (min), 3rd (max), and 4th bars back meet the criteria, this example would assign the 3rd bar to Bench.  How doI get it to assign the 2nd bar back (which would actually be the 1st  bar the loop encounters that meets the criteria?)

Bruce_L
Posted : Thursday, January 31, 2013 3:11:09 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

If you want it to be assigned to the lowest bar which meets the requirements instead of the highest bar which meets the requirements, you could alter the RealCode to:

If CurrentIndex >= 55 Then
	Dim Bench As Single = Single.MaxValue
	For i As Integer = 1 To 5
		If Volume.Value(i) > 2 * Volume.AVG(50, i) Then
			Bench = System.Math.Min(Bench, Price.Last(i))
		End If
		If Price.Last > Bench Then
			Pass
		End If
	Next
Else
	SetIndexInvalid
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Thursday, January 31, 2013 3:31:41 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

If if I am understanding this correctly, lowest bar  (system.math.min) would be the bar closest to today's bar and the highest bar (system.math.max) would be the bar that is furthest away from today's bar.

Is that correct?  If not, how can I find the bar that is closest to today's bar?

Thanks for your help.

Bruce_L
Posted : Thursday, January 31, 2013 3:37:25 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

No, highest bar is the bar that has the highest value. So 6 is higher than 5 no matter what the value is of today's bar.

I am not sure what you mean by "closest". If you mean physical proximity (as in the most recent bar), then you can exit out of the loop the first time your requirements are met:

If CurrentIndex >= 55 Then
	Dim Bench As Single = Single.MaxValue
	For i As Integer = 1 To 5
		If Volume.Value(i) > 2 * Volume.AVG(50, i) Then
			Bench = System.Math.Min(Bench, Price.Last(i))
			If Price.Last > Bench Then
				Pass
			End If
			Exit For
		End If
	Next
Else
	SetIndexInvalid
End If


-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Thursday, January 31, 2013 4:35:22 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

I do want the most recent bar that the requirements were met.  But, I plugged in your exact realcode, and didn't get any results. 

Do you get results when yours is run?

techohio
Posted : Friday, February 1, 2013 10:18:42 AM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Hi Bruce, yes,, I'm looking for the most recent bar that meets those requirements.  I think exiting out of the  For is getting me on the right track, but I don't think the realcode you provided is working for me.  I plugged in your exact code and nothing came back (I used the Banking Watchlist).  What could be wrong?

Bruce_L
Posted : Friday, February 1, 2013 10:24:23 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

I made some modifications to the RealCode in my Thursday, January 31, 2013 3:11:09 PM ET post shortly after it was originally posted. The version that is there now seems to work correctly for me if I am understanding requirements.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
techohio
Posted : Friday, February 1, 2013 1:09:24 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Not sure what I was doing wrong before, but I cleared my filters, rewrote the code as you suggested and now I get results.  Thanks again Bruce.  Have a good weekend.

techohio
Posted : Thursday, February 7, 2013 7:14:37 PM
Platinum Customer Platinum Customer

Joined: 3/5/2006
Posts: 55

Hi Bruce,

How would I apply the code you Posted : Thursday, January 31, 2013 3:37:25 PM above to TC2000 v12.3 in a condition that i could scan for?

 

Bruce_L
Posted : Friday, February 8, 2013 8:34:54 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138

Once you have created and saved your RealCode Conditon:

Writing Conditions in RealCode

You can just add it to a Filter:

Filtering Lists

Or use it as a Scan:

Scanning with Conditions

In the same way you would any other Condition.



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.