Registered User Joined: 7/23/2006 Posts: 132
|
Thbe following PCF's do a fair job representing bottoms.
PCF1: (MAXC10>(MINL10.20+((MAXH10.20-MINL10.20)*.1))AND
MINC10<(MINL10.20+((MAXH10.20-MINL10.20)*.2)))
PCF2: ((MINL10>MINL10.20*.96) AND (MINL10<MINL10.20*1.04))
PCF3: (C<MAXC10.10 AND C>MAXC10.10*.95)
How can these be converted to do the same for tops?
Thanks for the help.
Bernie
|
|
Registered User Joined: 7/23/2006 Posts: 132
|
Can these formulas be improved on?
Bernie
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (thebernie) PCF1: (MAXC10>(MINL10.20+((MAXH10.20-MINL10.20)*.1))AND MINC10<(MINL10.20+((MAXH10.20-MINL10.20)*.2)))
All of the following are guesses to a great extent.
MAXC10 < MAXH10.20 - (MAXH10.20 - MINL10.20) * .1 AND MINC10 > MAXH10.20 - (MAXH10.20 - MINL10.20) * .2
QUOTE (thebernie) PCF2: ((MINL10>MINL10.20*.96) AND (MINL10<MINL10.20*1.04))
MAXH10 > MAXH10.20 * .96 AND MAXH10 < MAXH10.20 * 1.04
QUOTE (thebernie) PCF3: (C<MAXC10.10 AND C>MAX10.10*.95)
C > MINC10.10 AND C < MINC10.10 * 1.05
QUOTE (thebernie) Can these formulas be improved on?
Maybe, but I'm probably not the person to do so. I can generally help somebody implement their specific unambiguous objective criteria within our products, but I can't normalyl help develop the criteria.
You may wish to review the following for information on pattern recognition in TeleChart:
Falling wedge
Cup with a handle formation
PCF for cup with a handle
Scanning for Chart Patterns
Scanning for Stocks Printing a Double or Triple Bottom
PCFs for pennants and flags
PCF's for Triangles
Does TeleChart support Elliott Wave indicators?
Double top/bottom trend
Finding Double Tops and Double Bottoms
CUP AND HANDLE AGAIN
Finding Continuation Triangles And Wedges With Telechart
Cup & Handle PCF
That said, I personally do not think complex pattern recognition is practical in TeleChart using Personal Criteria Formulas and EasyScans. This is true of pattern recognition in general with the exception of fixed size candlestick patterns (which are fairly straightforward as long as the pattern is well defined):
Boolean PCFs for Candlestick Patterns
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I was reading ejr39's post on finding double bottoms in tc2000 - Post #5402. How can that code be converted to Stockfinder's 'Realcode?' Additionally, I am new to Stockfinder and I find a lot of people kick enough to post bits and pieces to code but is there something showing how to put it all together into a working Realcode code? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I don't see a lot of RealCode fragments getting posted to be honest. Most of what I post that is RealCode related for example is complete RealCode Conditions, Indicators or Paint Schemes.
The EasyScan portion of ejr39's Saturday, May 21, 2005 2:36:59 PM ET post could be replaced with the following RealCode Condition:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Double Bottom ejr39
'|******************************************************************
If 10 <= Price.Last AndAlso _
Price.Last <= 30 AndAlso _
Volume.Value >= 1000 AndAlso _
Price.MinLow(10, 20) + (Price.MaxHigh(10, 20) - _
Price.MinLow(10, 20)) * .1 < Price.MinClose(10) AndAlso _
Price.MinClose(10) < Price.MinLow(10, 20) + _
(Price.MaxHigh(10, 20) - Price.MinLow(10, 20)) * .2 AndAlso _
Price.MinLow(10, 20) * .96 < Price.MinLow(10) AndAlso _
Price.MinLow(10) < Price.MinLow(10, 20) * 1.04 AndAlso _
Price.MaxHigh(10, 10) * .95 < Price.Last AndAlso _
Price.Last < Price.MaxHigh(10, 10) Then Pass
While the Custom Indicator could be reproduced using the following RealCode Indicator:
'|******************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Indicator:Volume as Percent
'|******************************************************************
If CurrentIndex >= 5 AndAlso _
Volume.MaxClose(5) > Volume.MinClose(5) Then
Plot = 100 * (Volume.Value - Volume.MinClose(5)) / _
(Volume.MaxClose(5) - Volume.MinClose(5))
Else
Plot = Single.NaN
End If
None of the rest of the instructions would relate to any RealCode that I can discren. It is mostly instructions on how you would want to set up your charts and interpret them before making any trades.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I should have been more specific in my quote as there are a lot of variables I do not want included and I am having problems removing them. As the learning curve is steep, I do not know what each line of code means. I greatly appreciate your help.This is exactly what I was looking for, in plain English:The first bottom (1st support) occurs between 15 and 40 trading days ago and the stock must have dropped between 5% to 40% within the prior 15 days to forming bottom #1.The rally off the 1st bottom should be between 9% and 22%.The second bottom should form within 1% above to 4% below the previous low.Today's close (2nd low) is within 6% of the middle point of the 'W' pattern.Proprietary indicator 'DK's' value = Value at the second low >= value at the 1st low. Thank you in advance for your prompt response and help. I really do appreciate it.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Understand that I am only converting from ejr39's formula. I didn't develop it and do not know how or even if it works (and I actually find some of the comparisons odd based on the original English language description provided by ejr39).
Your description does not correlate exactly with ejr39's technique so a direct conversion cannot be completely made. The Saturday, May 21, 2005 2:36:59 PM ET post has three major periods of time with each of those periods having the same length:
There is the First Bottom between 20 and 30 Trading Days Ago being represented by everything with (10, 20) in it (this actually represents the period from 20 to 29 Bars Ago as it is the 10-Bar Period ending 20-Bars Ago).
There is the Advance off the First Bottom between 10 and 20 Trading Days Ago being represented by everything with (10, 10) in it (this actually represents the period from 10 to 19 Bars Ago as it is the 10-Bar Period ending 10-Bars Ago)
There is the Second Bottom between today and 10-Trading Days Ago being represented by everything with (10) in it (this actually represents the period from 0 to 9 Bars Ago as it is the 10-Bar Period ending 0-Bars Ago).
The Price.Last section represents the current Value and is the Alert section. It is compared to the Advance off the First Bottom period of time.
We can eliminate the Price Range and Volume requirements from the RealCode:
10 <= Price.Last AndAlso _
Price.Last <= 30 AndAlso _
Volume.Value >= 1000 AndAlso _
To get:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Double Bottom without Price and Volume
'|******************************************************************
If Price.MinLow(10, 20) + (Price.MaxHigh(10, 20) - _
Price.MinLow(10, 20)) * .1 < Price.MinClose(10) AndAlso _
Price.MinClose(10) < Price.MinLow(10, 20) + _
(Price.MaxHigh(10, 20) - Price.MinLow(10, 20)) * .2 AndAlso _
Price.MinLow(10, 20) * .96 < Price.MinLow(10) AndAlso _
Price.MinLow(10) < Price.MinLow(10, 20) * 1.04 AndAlso _
Price.MaxHigh(10, 10) * .95 < Price.Last AndAlso _
Price.Last < Price.MaxHigh(10, 10) Then Pass
Now we can convert the First Bottom to be between 15 and 40 Trading Ago by changing every instance of (10, 20) to (26, 15) instead.
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Double Bottom 15 to 26 First Bottom
'|******************************************************************
If Price.MinLow(26, 15) + (Price.MaxHigh(26, 15) - _
Price.MinLow(26, 15)) * .1 < Price.MinClose(10) AndAlso _
Price.MinClose(10) < Price.MinLow(26, 15) + _
(Price.MaxHigh(26, 15) - Price.MinLow(26, 15)) * .2 AndAlso _
Price.MinLow(26, 15) * .96 < Price.MinLow(10) AndAlso _
Price.MinLow(10) < Price.MinLow(26, 15) * 1.04 AndAlso _
Price.MaxHigh(10, 10) * .95 < Price.Last AndAlso _
Price.Last < Price.MaxHigh(10, 10) Then Pass
We can change the 10 to 20% in ejr39's version to 9 to 22% by changing .1 to .09 and .2 to .22, the second bottom being within 4% of the first bottom to within 1% above and 4% below by changing the 1.04 to a 1.01 and the current Close being within 5% of the midpoint High of the W pattern to 6% by changing .95 to .94:
'|*****************************************************************|
'|*** StockFinder RealCode Condition - Version 5.0 www.worden.com
'|*** Copy and paste this header and code into StockFinder *********
'|*** Condition:Double Bottom Percentages Adjusted
'|******************************************************************
If Price.MinLow(26, 15) + (Price.MaxHigh(26, 15) - _
Price.MinLow(26, 15)) * .09 < Price.MinClose(10) AndAlso _
Price.MinClose(10) < Price.MinLow(26, 15) + _
(Price.MaxHigh(26, 15) - Price.MinLow(26, 15)) * .22 AndAlso _
Price.MinLow(26, 15) * .96 < Price.MinLow(10) AndAlso _
Price.MinLow(10) < Price.MinLow(26, 15) * 1.01 AndAlso _
Price.MaxHigh(10, 10) * .94 < Price.Last AndAlso _
Price.Last < Price.MaxHigh(10, 10) Then Pass
The result however leaves the Advance off the First Bottom as the 10-Trading Days ending 10-Trading Days Ago and the Second Bottom as being the most recent 10-Trading Days (as these periods were not redefined in your request). This means the Advance overlaps the First Bottom.
There is also no provision to check for the First Bottom having droppped between 5% to 40% and no obvious way to add it within the structure provided by ejr39. Is this based on the High of the 15-Bar Period ending 41-Bars Ago?
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I appreciate all your help. I will review your notes and the charts and give you an exact detailed and accurate feedback tonight. This is very close and with a few tweaks, would really be helpful to the community.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
erj's post just showed me that what I had intended on doing can be done but by no means did I just want to take his work and change the #s around or convert into Realcode. The basis for my logic is my system I have been running for years. What I am looking for is a scan that makes a distinct double bottom (W pattern) that signals me when the 1st low is retested, prior to the 2nd bounce starting.
I overlapped the periods to add more flexibility to the scan. In the original scan by ejr, everything was so structured, many good plays would be missed. I thought (and maybe the logic cannot work in the coded world), the 1st low can occur anywhere from 15 to 40 days ago. This must be a low and not a minor spike in a tight ranged consolidation (or flat range-bounded) trading environment. That is why I added a criteria that the stock must drop between 5% and 40% into that 1st low. Since this is a reactionary bounce, there must actually be a sell off into this 1st low. The steeper the 1st selloff, better the bounce if the second low actually holds.
The Advance off the First Bottom should start at the 1st low and obviously must end before the 2nd low is retested. The time was not as important but the absolute best signals have 7-11 candles between the 2 lows. It is best to leave more room for flexibility. The bounce in between lows must take 3 days at the least.
On 6/3/2010 on the SPY chart, the hit from your coding (with my changes) generates a hit at the high off of the bounce. If anywhere, that hit should have been generated on 5/21 or 5/25/10 (2nd bounce after the initial bounce at 5/6/10).
5/6/10 through 5/25/10 is an excellent example of what I am looking for. FOSL dropped about 30% (between the 5% and 40% I required), 1st bottoming on 5/6/10. It then bounced before selling off again to a within 1% of the 1st low on 5/25. A signal on 5/25 would be correct.
I would like to eliminate the line where you stated " the current Close being within 5% of the midpoint High of the W pattern to 6% by changing .95 to .94:" Once we retest the 1st low, the buy is on the next candle to break that test days HOD. Additionally, my indicator 'DK' must have a higher value at test 2 then it had on the 1st test. That was left out of the scan and is a key part to the scan. Any 1 line indicator can really be used, such as RSI.
You stated "There is also no provision to check for the First Bottom having dropped between 5% to 40% and no obvious way to add it within the structure provided by ejr39. Is this based on the High of the 15-Bar Period ending 41-Bars Ago?" Would it be possible to just have a line of code saying the 1st low must be 5% or more lower than the high 5 to 20 days before? This would eliminate signals coming out of chop. Thanks again for all your help. Hopefully this ramble was clear enough but if you need any clarifications, please ask.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Hi Bruce. Did you have a chance to look at my most recent post (above) from March 28, 2011 @ 9:22:48 PM? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I'm working on it, but the question has a lower priority than other questions. I'm not going to make other questions wait until this one is done as the RealCode is taking me many hours to create (keep in mind, I'm not a programmer).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
No problem and I appreciate your help. I just didn't know if I lost you or not. Thanks for the update.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I will need to know more about the DK Indicator in order to be able to include it. Don't worry, I don't need to know how it is calculated. I do need to know enough to be able to synchronize the Indicator with Price however. Does the Indicator start outputting Values immediately with the first Price Bar? If not, once it starts outputting Values, does it output a Value at each Price Bar?
Please try replacing everything below the Inherits line in the Class tab of the RealCode Editor of a RealCode Condition with the following:
Sub New
AutoLoop = False
End Sub
Public Overrides Sub CallUserCode()
Dim FirstLowPeriod As Integer = 26
Dim FirstLowOffset As Integer = 15
If Price.Bar.Count > FirstLowOffset + FirstLowPeriod + 15
Dim FirstLow As Single = Single.MaxValue
Dim FirstLowIndex As Integer = 0
Dim FirstLowCount As Integer = 0
Dim High As Single = Single.NaN
Dim HighIndex As Integer = 0
Dim SecondLow As Single = Single.NaN
Dim SecondLowIndex As Integer = 0
Dim CheckIndex As Integer = -1
Dim i As Integer = FirstLowOffset + FirstLowPeriod + 14
Dim FLO As Integer = i - FirstLowOffset
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
For i = FirstLowOffset + FirstLowPeriod + 15 To Price.Bar.Count - 1
FLO = i - FirstLowOffset
If Price.Bar.LowValue(FLO) < FirstLow Then
FirstLow = Price.Bar.LowValue(FLO)
FirstLowCount = 1
FirstLowIndex = FLO
Else If Price.Bar.LowValue(FLO) = FirstLow
FirstLowCount += 1
FirstLowIndex = FLO
End If
If Price.Bar.LowValue(FLO - FirstLowPeriod) = FirstLow Then
FirstLowCount -= 1
End If
If FirstLowCount = 0 Then
FirstLow = Single.MaxValue
FirstLowCount = 0
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
End If
If Price.Bar.HighValue(i) >= High Then
High = Price.Bar.HighValue(i)
HighIndex = i
Else If FirstLowIndex >= HighIndex Then
High = Single.MinValue
For j As Integer = FirstLowIndex + 1 To i
If Price.Bar.HighValue(j) > High Then
High = Price.Bar.HighValue(j)
HighIndex = j
End If
Next
End If
If i > HighIndex Then
If Price.Bar.LowValue(i) <= SecondLow Then
SecondLow = Price.Bar.LowValue(i)
SecondLowIndex = i
Else If HighIndex >= SecondLowIndex Then
SecondLow = Single.MaxValue
For j As Integer = HighIndex + 1 To i
If Price.Bar.LowValue(j) < SecondLow Then
SecondLow = Price.Bar.LowValue(j)
SecondLowIndex = j
End If
Next
End If
End If
If i > SecondLowIndex AndAlso _
CheckIndex <> SecondLowIndex AndAlso _
SecondLowIndex > HighIndex AndAlso _
HighIndex > FirstLowIndex AndAlso _
SecondLowIndex >= FirstLowIndex + 3 AndAlso _
1.09 * FirstLow <= High AndAlso _
High <= 1.22 * FirstLow AndAlso _
.96 * FirstLow <= SecondLow AndAlso _
SecondLow <= 1.01 * FirstLow AndAlso _
Price.Bar.HighValue(i) > Price.Bar.HighValue(SecondLowIndex) Then
Dim FirstLowTrue As Boolean = False
For j As Integer = FirstLowIndex - 15 To FirstLowIndex - 1
Dim Ratio As Single = FirstLow / Price.Bar.HighValue(j)
If .6 <= Ratio AndAlso Ratio <= .95 Then
FirstLowTrue = True
Exit For
End If
Next
If FirstLowTrue = True Then
CheckIndex = SecondLowIndex
AddToOutput(Price.Bar.DateValue(i), True)
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Next
End If
End Sub
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Thanks a lot. DK starts outputting values after the 10th candle closes. Then it generates every candle.
That is a lot of code. I really appreciate the help. I started to go through the charts and so far it looks pretty good. I will need a day or two to go through all the data and see how well it preforms.
One quick question, I was looking at the backtesting vehicle inside Stockfinder and the entry and exit variables are pretty minimal. I can not exit in multiple tiers and it does not have commands such as "when the stock is up x%, move stop to entry." Is this something a more experienced coder can accomplish using Realcode and somehow exporting everything into excel?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
BackScanner doesn't have any money or portfolio management features. You are either all in or all out of any given position. The Trade-Based Rules are limited to those given. Only one Rule can be Triggered or Executed on any given Bar. You can only Enter or Exit on the Open, High, Low, Close or Midpoint of the Bar specified in whatever Rule is Triggered.
It would be possible to export the trades and/or Conditions and have somebody that is good with Excel possibly create a spreadsheet to do more sophisticated backtesting (but we can't help you at all with third party products such as Excel).
It might also be possible to basically rewrite BackScanner as a bunch of RealCode Indicators and RealCode Conditions, but that would be beyond my abilities as a non-programmer to really help you create (my attempt at a basic framework for such a thing can be found in the Indciators and conditions topic).
I've added tests for DK to the following RealCode. As before, start by replacing everything below the Inherits line in the Class tab of the RealCode Editor of a RealCode Condition with the following RealCode.
In addition, you will need to replace the '# DK = indicator.Library.Relative Strength Index (RSI) line with a line that references your custom DK Indicator by Dragging and Dropping the Indicator from the Chart or by selecting Import Indicator if you have saved the DK Indicator.
One note is that the Watchlist Columns may not match the chart if the DK indicator relies on any cumulative or exponential calculations. It would be possible to resolve this by adding a '# Cumulative line to the RealCode, but you will not want to do so unless absolutely necessary as it could significantly slow down calculating the Condition when used in a Watchlist.
Sub New
AutoLoop = False
End Sub
Public Overrides Sub CallUserCode()
'# DK = indicator.Library.Relative Strength Index (RSI)
Dim FirstLowPeriod As Integer = 26
Dim FirstLowOffset As Integer = 15
If Price.Bar.Count > FirstLowOffset + FirstLowPeriod + 15 Then
Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count
Dim FirstLow As Single = Single.MaxValue
Dim FirstLowIndex As Integer = 0
Dim FirstLowCount As Integer = 0
Dim High As Single = Single.NaN
Dim HighIndex As Integer = 0
Dim SecondLow As Single = Single.NaN
Dim SecondLowIndex As Integer = 0
Dim CheckIndex As Integer = -1
Dim i As Integer = FirstLowOffset + FirstLowPeriod + 14
Dim FLO As Integer = i - FirstLowOffset
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
For i = FirstLowOffset + FirstLowPeriod + 15 To Price.Bar.Count - 1
FLO = i - FirstLowOffset
If Price.Bar.LowValue(FLO) < FirstLow Then
FirstLow = Price.Bar.LowValue(FLO)
FirstLowCount = 1
FirstLowIndex = FLO
Else If Price.Bar.LowValue(FLO) = FirstLow
FirstLowCount += 1
FirstLowIndex = FLO
End If
If Price.Bar.LowValue(FLO - FirstLowPeriod) = FirstLow Then
FirstLowCount -= 1
End If
If FirstLowCount = 0 Then
FirstLow = Single.MaxValue
FirstLowCount = 0
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
End If
If Price.Bar.HighValue(i) >= High Then
High = Price.Bar.HighValue(i)
HighIndex = i
Else If FirstLowIndex >= HighIndex Then
High = Single.MinValue
For j As Integer = FirstLowIndex + 1 To i
If Price.Bar.HighValue(j) > High Then
High = Price.Bar.HighValue(j)
HighIndex = j
End If
Next
End If
If i > HighIndex Then
If Price.Bar.LowValue(i) <= SecondLow Then
SecondLow = Price.Bar.LowValue(i)
SecondLowIndex = i
Else If HighIndex >= SecondLowIndex Then
SecondLow = Single.MaxValue
For j As Integer = HighIndex + 1 To i
If Price.Bar.LowValue(j) < SecondLow Then
SecondLow = Price.Bar.LowValue(j)
SecondLowIndex = j
End If
Next
End If
End If
If i > SecondLowIndex AndAlso _
CheckIndex <> SecondLowIndex AndAlso _
SecondLowIndex > HighIndex AndAlso _
HighIndex > FirstLowIndex AndAlso _
SecondLowIndex >= FirstLowIndex + 3 AndAlso _
1.09 * FirstLow <= High AndAlso _
High <= 1.22 * FirstLow AndAlso _
.96 * FirstLow <= SecondLow AndAlso _
SecondLow <= 1.01 * FirstLow AndAlso _
Price.Bar.HighValue(i) > Price.Bar.HighValue(SecondLowIndex) AndAlso _
DK.Line.Value(SecondLowIndex - DKOffset) > _
DK.Line.Value(FirstLowIndex - DKOffset) Then
Dim FirstLowTrue As Boolean = False
For j As Integer = FirstLowIndex - 15 To FirstLowIndex - 1
Dim Ratio As Single = FirstLow / Price.Bar.HighValue(j)
If .6 <= Ratio AndAlso Ratio <= .95 Then
FirstLowTrue = True
Exit For
End If
Next
If FirstLowTrue = True Then
CheckIndex = SecondLowIndex
AddToOutput(Price.Bar.DateValue(i), True)
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Next
End If
End Sub
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I did as instructed but I went from 9000 hits to 0. The name of the indicator is DK1511 as I included the date it was written, so I changed all the DK's to DK DK1511.
I assume Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count needs to be changed to
Dim DK1511Offset As Integer = Price.Bar.Count - DK1511.Line.Count
where I changed the DKoffset too. Correct? If so I changed it but an still not getting a single hit. Any ideas?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It could be something specific to the DK1511 Indicator, but since that is top secret, let's start under the assumption that this is not the case. Are you getting any error messages?
I'm assuming the following line:
'# DK = indicator.Library.Relative Strength Index (RSI)
Ending up looking something like (don't worry about what is after the = sign as long as it was created using Drag and Drop or Import Indicator):
'# DK1511 = chart.DK1511
You could just change it to:
'# DK = chart.DK1511
And leave everything else in the RealCode alone. If you really want it to be DK1511 instead of DK, you only need to change three things.
Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count
Should become:
Dim DKOffset As Integer = Price.Bar.Count - DK1511.Line.Count
And:
DK.Line.Value(SecondLowIndex - DKOffset) > _
DK.Line.Value(FirstLowIndex - DKOffset) Then
Should become:
DK1511.Line.Value(SecondLowIndex - DKOffset) > _
DK1511.Line.Value(FirstLowIndex - DKOffset) Then
If you decide you really need to change the DKOffset variable to DK1511Offset for some reason, you will need to change it throughout the RealCode as well.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 2/28/2005 Posts: 825
|
When this is finished could you post the code in its entirety please.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I am going to make this easy and just resave the indicator as DK. That way I only have to change the 1 line from RSI. I will get to that right after dinner and let you know how it fairs. Thanks again for everything.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Hi Bruce. I have reviewed the trades and it is almost there but a long way from being productive. There are a few issues.
First, the scan had 817 hits in the SP500 alone in the last calendar year. I normally run it on all stocks and ETFs with vol over 900k and price between $5 and $600 (slightly over 2000 stocks)and I get nearly 2000 trades a year. This is because it really isnt highlighting double bottoms but it has a lot of trades in congestion.
A prime example would be ADM. I ran the scan and got a long hit on 4/22 which is in the middle of an 11 day congestion area. The scan should have hit on 5/6 which was almost a perfect set up and would have paid nicely. It did not signal a buy on 5/6 though.
Another long hit was on AMAT on 6/11, again in the middle of a consolidation.
DNB hit on 6/1/10 and was a very nice catch. A nice double bottom with a steep retrace in between the lows with any indicator diverging and it rallied hard off the signal. This is exactly the set up I want!!!
Any idea how we can eliminate the consolidation signals? Maybe by including a range criteria for the previous few days (5-15 days must have a range of more than x% of price or signal is denied). Just a thought as right now there are too many signals and eliminating the chop signals would help a ton. Thanks a lot.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (truetrend) This is because it really isnt highlighting double bottoms but it has a lot of trades in congestion.
It is finding symbols meeting the objective requirements given by you for a double bottom. If these objective requirements are the definition of a double bottom, then it is in fact finding double bottoms by definition.
If the symbols being found are what you subjectively see as trades in congestion instead of double bottoms, then it is a matter of the objective definition not matching your subjective impressions of what a double bottom should be. This would tend to indicate that the objective definition is flawed in some way and needs to be refined (you appear to have already come to the same conclusion).
QUOTE (truetrend) Any idea how we can eliminate the consolidation signals?
No. I can help you attempt to implement your objective definition within our programs. I cannot help you with actually developing an objective definition that meets your subjective expectations.
QUOTE (truetrend) Maybe by including a range criteria for the previous few days (5-15 days must have a range of more than x% of price or signal is denied). Just a thought as right now there are too many signals and eliminating the chop signals would help a ton.
We can add a check for this. All of the directions from my Thursday, March 31, 2011 3:03:49 PM ET post still apply as does everything you learned in the follow-up questions.
Sub New
AutoLoop = False
End Sub
Public Overrides Sub CallUserCode()
'# DK = indicator.Library.Relative Strength Index (RSI)
'# MinRangePeriod = UserInput.Integer = 15
'# MinRangePercent = UserInput.Single = 1
Dim FirstLowPeriod As Integer = 26
Dim FirstLowOffset As Integer = 15
If Price.Bar.Count > FirstLowOffset + FirstLowPeriod + 15 Then
Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count
Dim FirstLow As Single = Single.MaxValue
Dim FirstLowIndex As Integer = 0
Dim FirstLowCount As Integer = 0
Dim High As Single = Single.NaN
Dim HighIndex As Integer = 0
Dim SecondLow As Single = Single.NaN
Dim SecondLowIndex As Integer = 0
Dim CheckIndex As Integer = -1
Dim i As Integer = FirstLowOffset + FirstLowPeriod + 14
Dim FLO As Integer = i - FirstLowOffset
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
For i = FirstLowOffset + FirstLowPeriod + 15 To Price.Bar.Count - 1
FLO = i - FirstLowOffset
If Price.Bar.LowValue(FLO) < FirstLow Then
FirstLow = Price.Bar.LowValue(FLO)
FirstLowCount = 1
FirstLowIndex = FLO
Else If Price.Bar.LowValue(FLO) = FirstLow
FirstLowCount += 1
FirstLowIndex = FLO
End If
If Price.Bar.LowValue(FLO - FirstLowPeriod) = FirstLow Then
FirstLowCount -= 1
End If
If FirstLowCount = 0 Then
FirstLow = Single.MaxValue
FirstLowCount = 0
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
End If
If Price.Bar.HighValue(i) >= High Then
High = Price.Bar.HighValue(i)
HighIndex = i
Else If FirstLowIndex >= HighIndex Then
High = Single.MinValue
For j As Integer = FirstLowIndex + 1 To i
If Price.Bar.HighValue(j) > High Then
High = Price.Bar.HighValue(j)
HighIndex = j
End If
Next
End If
If i > HighIndex Then
If Price.Bar.LowValue(i) <= SecondLow Then
SecondLow = Price.Bar.LowValue(i)
SecondLowIndex = i
Else If HighIndex >= SecondLowIndex Then
SecondLow = Single.MaxValue
For j As Integer = HighIndex + 1 To i
If Price.Bar.LowValue(j) < SecondLow Then
SecondLow = Price.Bar.LowValue(j)
SecondLowIndex = j
End If
Next
End If
End If
If i > SecondLowIndex AndAlso _
CheckIndex <> SecondLowIndex AndAlso _
SecondLowIndex > HighIndex AndAlso _
HighIndex > FirstLowIndex AndAlso _
SecondLowIndex >= FirstLowIndex + 3 AndAlso _
1.09 * FirstLow <= High AndAlso _
High <= 1.22 * FirstLow AndAlso _
.96 * FirstLow <= SecondLow AndAlso _
SecondLow <= 1.01 * FirstLow AndAlso _
Price.Bar.HighValue(i) > Price.Bar.HighValue(SecondLowIndex) AndAlso _
DK.Line.Value(SecondLowIndex - DKOffset) > _
DK.Line.Value(FirstLowIndex - DKOffset) AndAlso _
Price.MaxHigh(MinRangePeriod) - Price.MinLow(MinRangePeriod) >= _
Price.Last * MinRangePercent / 100 Then
Dim FirstLowTrue As Boolean = False
For j As Integer = FirstLowIndex - 15 To FirstLowIndex - 1
Dim Ratio As Single = FirstLow / Price.Bar.HighValue(j)
If .6 <= Ratio AndAlso Ratio <= .95 Then
FirstLowTrue = True
Exit For
End If
Next
If FirstLowTrue = True Then
CheckIndex = SecondLowIndex
AddToOutput(Price.Bar.DateValue(i), True)
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Next
End If
End Sub
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Thanks for the help. There were a few errors popping up.
Line 0 - Public overrides sub CallUserCode()' has multiple definitions with identical signatures
line 7 - Statement cannot appear within a method body. End of method assumed.
Line 7 is 'Sub New'
Line 17 - Name 'DK' is not declared
Line 17 is 'Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count'
line 17 is exactly as it was in the last code so I am stumpted
Line 101 - Line 101 - Name 'DK' is not declared
Line 101 is 'DK.Line.Value(SecondLowIndex - DKOffset) >'
Line 102 Name 'DK' is not declared
Line 102 is 'DK.Line.Value(FirstLowIndex - DKOffset) AndAlso _'
Line 127 'End Sub' must be preceded by a matching 'Sub'
Line 128 'End Class' must be preceded by a matching 'Class'
Line 125 is the last line so line 127 and 128 are blank
Thanks a ton!
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
It reads like you have copied and pasted the RealCode into the Code tab of the RealCode Editor.
You need to do exactly what you did the first time. Replace everything below the Inherits line in the Class tab of the RealCode Editor of a RealCode Condition with the RealCode provided.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
You are right. Rusty I guess. I am running it now. Thanks.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Bruce - I see what you added but I don't quite understand the coding or what its looking for or eliminating. Could you give me the brief real English description of what the additional lines are looking to eliminate? Thanks.
I ran it on a small SP500 watch list filtered to 250 stocks from 1/2011 and had no trades signaled. A far cry from the 2000 hits we had before..maybe to far lol.
If I understood the logic you coded, I could probably tweak it to get the desired results.
I am scanning an 806 stock watch list from 1/2010 with the new code and will let you know if there are any hits.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The following requirement was added:
Price.MaxHigh(MinRangePeriod) - Price.MinLow(MinRangePeriod) >= _
Price.Last * MinRangePercent / 100 Then
It checks for the Range (the Highest High minus the Lowest Low) over the MinRangePeriod to be at least MinRangePercent of Price.
MinRangePeriod and MinRangePercent are UserInputs with defaults set near the beginning of the RealCode:
'# MinRangePeriod = UserInput.Integer = 15
'# MinRangePercent = UserInput.Single = 1
If you do not adjust the defaults, the Range over 15-bars must be at least 1% of Price. You should adjust these User Inputs by editing the Condition and not the RealCode for the Condition as the RealCode only sets the defaults for the User Inputs. Changing the defaults in the RealCode after the Condition is created will not change the values of the User Inputs.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I ran the new code the same way I have run it before, from 1/2010 to today on 1300 stocks and I didn't have a single hit. Thats down from 1000+ over the same period on the same watch list, everything else being the same. To be exact, I had zero hits on 4.4 million conditions tested as opposed to 2705 hits on 1.8 millions conditions tested before the code change.
If everything else in the code is the same, this makes no sense as a 1% move is nothing. There were a ton of stock that had 5% or more moves into the signal. Something is weird. What could be causing all the hits to be disqualified? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
What's wierd is that I completely forgot that I was using AutoLoop = False. The Price.MaxHigh() and Price.MinLow() syntax is not valid when AutoLoop = True. We will need to calculate those values manually (all of the same caveats about how to create the RealCode Condition in the Class tab still apply):
Sub New
AutoLoop = False
End Sub
Public Overrides Sub CallUserCode()
'# DK = indicator.Library.Relative Strength Index (RSI)
'# MinRangePeriod = UserInput.Integer = 15
'# MinRangePercent = UserInput.Single = 1
Dim FirstLowPeriod As Integer = 26
Dim FirstLowOffset As Integer = 15
If Price.Bar.Count > FirstLowOffset + FirstLowPeriod + 15 Then
Dim DKOffset As Integer = Price.Bar.Count - DK.Line.Count
Dim FirstLow As Single = Single.MaxValue
Dim FirstLowIndex As Integer = 0
Dim FirstLowCount As Integer = 0
Dim High As Single = Single.NaN
Dim HighIndex As Integer = 0
Dim SecondLow As Single = Single.NaN
Dim SecondLowIndex As Integer = 0
Dim CheckIndex As Integer = -1
Dim i As Integer = FirstLowOffset + FirstLowPeriod + 14
Dim FLO As Integer = i - FirstLowOffset
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
For i = FirstLowOffset + FirstLowPeriod + 15 To Price.Bar.Count - 1
FLO = i - FirstLowOffset
If Price.Bar.LowValue(FLO) < FirstLow Then
FirstLow = Price.Bar.LowValue(FLO)
FirstLowCount = 1
FirstLowIndex = FLO
Else If Price.Bar.LowValue(FLO) = FirstLow
FirstLowCount += 1
FirstLowIndex = FLO
End If
If Price.Bar.LowValue(FLO - FirstLowPeriod) = FirstLow Then
FirstLowCount -= 1
End If
If FirstLowCount = 0 Then
FirstLow = Single.MaxValue
FirstLowCount = 0
For j As Integer = FLO + 1 - FirstLowPeriod To FLO
If Price.Bar.LowValue(j) < FirstLow Then
FirstLow = Price.Bar.LowValue(j)
FirstLowCount = 1
FirstLowIndex = j
Else If Price.Bar.LowValue(j) = FirstLow Then
FirstLowCount += 1
FirstLowIndex = j
End If
Next
End If
If Price.Bar.HighValue(i) >= High Then
High = Price.Bar.HighValue(i)
HighIndex = i
Else If FirstLowIndex >= HighIndex Then
High = Single.MinValue
For j As Integer = FirstLowIndex + 1 To i
If Price.Bar.HighValue(j) > High Then
High = Price.Bar.HighValue(j)
HighIndex = j
End If
Next
End If
If i > HighIndex Then
If Price.Bar.LowValue(i) <= SecondLow Then
SecondLow = Price.Bar.LowValue(i)
SecondLowIndex = i
Else If HighIndex >= SecondLowIndex Then
SecondLow = Single.MaxValue
For j As Integer = HighIndex + 1 To i
If Price.Bar.LowValue(j) < SecondLow Then
SecondLow = Price.Bar.LowValue(j)
SecondLowIndex = j
End If
Next
End If
End If
If i > SecondLowIndex AndAlso _
CheckIndex <> SecondLowIndex AndAlso _
SecondLowIndex > HighIndex AndAlso _
HighIndex > FirstLowIndex AndAlso _
SecondLowIndex >= FirstLowIndex + 3 AndAlso _
1.09 * FirstLow <= High AndAlso _
High <= 1.22 * FirstLow AndAlso _
.96 * FirstLow <= SecondLow AndAlso _
SecondLow <= 1.01 * FirstLow AndAlso _
Price.Bar.HighValue(i) > Price.Bar.HighValue(SecondLowIndex) AndAlso _
DK.Line.Value(SecondLowIndex - DKOffset) > _
DK.Line.Value(FirstLowIndex - DKOffset) Then
Dim FirstLowTrue As Boolean = False
For j As Integer = FirstLowIndex - 15 To FirstLowIndex - 1
Dim Ratio As Single = FirstLow / Price.Bar.HighValue(j)
If .6 <= Ratio AndAlso Ratio <= .95 Then
FirstLowTrue = True
Exit For
End If
Next
If FirstLowTrue = True Then
Dim MinRange As Boolean = False
Dim MaxHigh As Single = Single.MinValue
Dim MinLow As Single = Single.MaxValue
For j As Integer = 0 To MinRangePeriod - 1
MaxHigh = System.Math.Max(MaxHigh, Price.Bar.HighValue(i))
MinLow = System.Math.Min(MinLow, Price.Bar.LowValue(i))
If MaxHigh - MinLow > Price.Bar.Value(i) * MinRangePercent / 100 Then
MinRange = True
Exit For
End If
Next
If MinRange = True Then
CheckIndex = SecondLowIndex
AddToOutput(Price.Bar.DateValue(i), True)
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Else
AddToOutput(Price.Bar.DateValue(i), False)
End If
Next
End If
End Sub
End Class
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 2/28/2005 Posts: 825
|
IBD recommends a double bottom to be a minimum of 7 weeks, and the second bottom be below the first bottom (I think a max of 5%).
Once this is all working ok with TT, could this be rewritten for those parameters Bruce?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
alindsley,
If you take a look at truetrend's Monday, March 28, 2011 1:54:24 PM ET and Monday, March 28, 2011 9:22:48 PM ET posts, you will see the type of detail required. I would just substitute your parameters in and leave everything else the same, but they do not seem to be completely compatible with the existing requirements.
It might be best once we get it working to create a entirely UserInput based approach which would allow each user to input their own parameters.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
Agree Bruce. Parameters such as length of time in between peaks or minimum height of the retrace can always be adjusted afterwards (and tested), but 1st we need a working scan.
alindsley, as far as IBD's recommendation, over my 13 years of professional trading and training of other successful traders, a double top or bottom with 11 candles in between peaks had worked the best.
This is always subject to each traders target, willingness to hold the position longer and risk tolerance. A low risk trader may be looking for a quick reactionary move off the bottom (and a higher percentage trade) where a longer term swing trader who is wiling to have a bigger draw down and wider stop would obviously be looking for greater gains and bigger targets.
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
QUOTE"If you do not adjust the defaults, the Range over 15-bars must be at least 1% of Price. You should adjust these User Inputs by editing the Condition and not the RealCode for the Condition as the RealCode only sets the defaults for the User Inputs. Changing the defaults in the RealCode after the Condition is created will not change the values of the User Inputs.
Just to be clear, I need to change the 1% to say 3% to test a wider range in the green line on the top of the realcode about line 10, correct? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I suspect you are referencing the following line:
'# MinRangePercent = UserInput.Single = 1
Leave it alone. Changing it will not change the value of MinRangePercent once the RealCode Condition has already been created. The 1 at the end of the line is just a default value. Changing the default value does not change the actual value.
The line is creating a UserInput. You need to left-click on the Condition (or right-click on the Condition and select Edit) to bring up the Edit Condition window for the Condition. There will be a list of adjustable settings including MinRangePercent. You need to change the value there to adjust the value.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
I pulled up the window and there are 3 variables with the value of 1.'of the last', 'Passing' and 'MinRangePercent.' Obviously I will change the 'MinRangePercent' but do I need to change the other two? Thanks.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You don't need to change the other two. They are built into all RealCode Conditions.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
QUOTE (truetrend) alindsley, as far as IBD's recommendation, over my 13 years of professional trading and training of other successful traders, a double top or bottom with 11 candles in between peaks had worked the best..
11 days? (or all timeframes)
Thanks
diceman
|
|
Registered User Joined: 6/16/2005 Posts: 131
|
A very unscientific study as it is from my trading results and no backtested data was used, but across all time frames, 11 candles between peaks has yielded the most successful double tops and bottoms. Most of my trading is based on the 3, 9 and 30 minute charts intra-day and the daily.
|
|
Registered User Joined: 1/28/2005 Posts: 6,049
|
Thanks
|
|
Registered User Joined: 2/28/2005 Posts: 825
|
Earlier today I ran Bruce's most recent scan condition of Wednesday, April 20, 2011 4:08:39 PM on all US Stocks and received no hits whatsoever. Is this right? Seems very strange.
One other question please. Is this condition created to look for the 11 days which you have found to be most rewarding?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
alindsley,
Keep in mind that while the RealCode links to RSI, the DK Indicator is actually actually truetrend's private indicator and I have no way of testing that version.
That said, I currently get 15 symbols returning True on a Daily Chart with the Relative Strength Index (RSI) set to a Period of 9 and Smooth of 3.
EC, RELV, LOAN, PNC.WS, MDRX, CECO, AZC, CLD, MG816, BANR, WOLF, AV, CVR, AHGP, SGMA
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |