Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 7/26/2006 Posts: 23
|
I have two realcode questions: 1) I don't understand what the function is of pass and fail command; 2) when I run a scan for a scan consisting of a sell command first, a trade thru command section and a buy command third. When I look at the results they are all for long sales where Stockfinder has started it calculation with the first buy order and concluded it with the next sell order. How do I get the backscanner to look at the scan formulation the one I lay it out. As to the realcode I am having problem with it is trhe following.
Dim netchange As Single = price.Close - price.Open
Static Upcount As Integer = 0
Dim Myarray(15) As Integer
If netchange >= 0 Then
Upcount += 1
myarray(upcount) = upcount
myarray(upcount - 1) = upcount
upcountconst = upcount
ElseIf netchange < 0 Then
Upcount = 0
End If
If myarray(upcount - 1) >= 2 AndAlso _
price.Close(1) > price.Open(1) AndAlso _
price.Open > price.Close AndAlso _
price.Open > price.Close(1) AndAlso _
price.Close < price.Open(1) Then pass
'The code myarray(upcount-1) >= 2 AndAlso _ is meant to ensure that the bearish engulfing pattern only occurs after three green or up candles. What is does is eliminate most results of the backscan even though some of them met the condition. Appreciate your help
Eliezer
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (edrichmond) I don't understand what the function is of pass and fail command
A RealCode Rule will be default return False. If you want it to return True, then you need to use Pass. You appear to have done so in your RealCode Rule.
There is a third possibility, that the Rule is neither True nor False because a determination cannot be made. In such circumstances, you would use SetIndexInvalid instead. This is primarily useful when there isn't enough data for the calculations and you want a WatchList Column based on the Rule to use enough data in its calculations.
QUOTE (edrichmond) when I run a scan for a scan consisting of a sell command first, a trade thru command section and a buy command third. When I look at the results they are all for long sales where Stockfinder has started it calculation with the first buy order and concluded it with the next sell order. How do I get the backscanner to look at the scan formulation the one I lay it out.
There is no way to say based on your description. Please Share the Layout containing your BackScan and explain where you think it isn't working correctly.
QUOTE (edrichmond) As to the realcode I am having problem with it is trhe following.
Dim netchange As Single = price.Close - price.Open
Static Upcount As Integer = 0
Dim Myarray(15) As Integer
If netchange >= 0 Then
Upcount += 1
myarray(upcount) = upcount
myarray(upcount - 1) = upcount
upcountconst = upcount
ElseIf netchange < 0 Then
Upcount = 0
End If
If myarray(upcount - 1) >= 2 AndAlso _
price.Close(1) > price.Open(1) AndAlso _
price.Open > price.Close AndAlso _
price.Open > price.Close(1) AndAlso _
price.Close < price.Open(1) Then pass
'The code myarray(upcount-1) >= 2 AndAlso _ is meant to ensure that the bearish engulfing pattern only occurs after three green or up candles. What is does is eliminate most results of the backscan even though some of them met the condition.
I'm not a programmer. Your RealCode is a bit too complicated for me to follow. I'm not sure you need to create an array:
Static Upcount As Integer
If CurrentIndex > 0 AndAlso Price.Last(1) >= Price.Open(1) Then
Upcount += 1
Else
Upcount = 0
End If
If Upcount >= 3 AndAlso _
Price.Last(1) > Price.Open(1) AndAlso _
Price.Open > Price.Last AndAlso _
Price.Open > Price.Last(1) AndAlso _
Price.Last < Price.Open(1) Then Pass
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/26/2006 Posts: 23
|
I made a scan in SGP where the scan consisted of three rules: 1) The modified bearish engulfing pattern which you programed above and which I gave the instruction to sell on the next open; 2) if the subsequent candles made lower lows and lower highs then the scan was to stay in the trade; 3) If the candle made a higher high then the scan was to buy on the next candle. For SGP from 6/11/08 to 6/11/09 there were two trades both long - one from 6/12/08 where there was a buy signal w/o a bearish engulfing pattern preceding it, to 12/19/08 where there was a sell signal following the bearish engulfing pattern. The second long trade went from 12/24/08 where there was an expected buy to 6/10/09 where there was neither a buy or a sell. In any event I got two long trades when I should have gotten a short trade, and I got a buy signal when there should have been nothing. AAPL had four trades all long. The first trade was a buy from rule #3 when there was no engulfing pattern, and the remaining trades followed the backscan as programmed. Can you tell me why Rule #3 is being executed before rules #1 and 2.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I may be misunderstanding, but you appear to be under the impression that the Rules in BackScanner represent a Sequence of some sort. They do not (other than the fact that you can't Exit or Remain In a Trade until the Trade has been Entered). The Rules are evaluated individually from top to bottom with only the highest priority (physically above) returning True actually triggering an action in the Trade.
If you want to create a Sequence, you would need to create a Sequence Rule by Dragging and Dropping regular Rule (not RealCode Rules) onto each other and selecting Create New Sequence.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/26/2006 Posts: 23
|
Bruce,
I finally got the backscanner to do what I wanted. Obviously, if you use buy and sell rules then the program apparently assumes that you must buy first before you can sell. In my case, to get the backscanner to sell first, I had to tell it to 'sell short' and then in rule #3 'buy to cover'. The program then assumes that you have to sell first. I tried forming a sequence out of realcode items but when I put the sequence in the backscanner I was required to give an order to 'buy','sell',etc. and I couldn't do what I wanted.
Eliezer
|
|
Registered User Joined: 7/26/2006 Posts: 23
|
Bruce
Maybe I should read the reference manual a second time, because the answers were in Chapter 10. Thanks for your help
Eliezer
|
|
Registered User Joined: 7/26/2006 Posts: 23
|
Bruce
There are several issues with the backscan of the setup that I am testing
1. In order for the sell short rule, Rule #1, which we have been discussing to occur on the appropriate candle, i.e. the next open after the code is executed I need to put the "Bars from Now" at 2 instead of 1.
2. Rule #3 which should buy to cover after two green bars with the second green bar being a higher high and a higher low I needed to write the following code:
Dim netchange As Single = price.Close(0) - price.Open(0)
Static upcount As Integer = 0
'currentindex > 0 AndAlso
If netchange >= 0 Then
upcount += 1
Else
upcount = 0
End If
If upcount = 2 AndAlso _
price.high > price.High(1) AndAlso _
price.Low > price.Low(1) Then
pass
End If
I needed to set the computation to the present candle instead of the previous candle in netchange. Also I took out the "currentindex > 0 " with no obvious change.
3. After running the backscan on the SP-500, I found the following problems when I looked at the "Trades" under the SP-500 on the BackScanner
A) One the time of the day for the "Enter" and "Exit" is given as 4:00PM instead of 9:30AM as it should be since the rules ask for the action to be taken at the next open.
B) The next open arrow doesn't always occur on the candle after the two green candles but rather on the second green candle. But the value in the "Trades" table under "Exits" agrees with the value of the candle after the two green candles. In the case of the "Enter" column the value in the table does not agree with the value of the candle indicated or the candle to either side.
I am open to any comments, corrections, or coding.
Eliezer
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
QUOTE (edrichmond) In order for the sell short rule, Rule #1, which we have been discussing to occur on the appropriate candle, i.e. the next open after the code is executed I need to put the "Bars from Now" at 2 instead of 1.
I've run some tests and when I Copy and Paste your RealCode into a Realcode Rule. If I both Plot it on the Chart and use it as a BackScanner Rule that Executes at the Open 1 Bar From Now, the BackScanner Rule always seems to trigger exactly one Bar after the RealCode Rule itself triggers. When I change the BackScanner Rule to 2 Bars From Now, the BackScanner Rule always seem to trigger exactly two Bars after the RealCode Rule itself triggers.
If you Share your Layout, we'll take a look and see if we can troubleshoot the issue.
QUOTE (edrichmond) I needed to set the computation to the present candle instead of the previous candle in netchange.
As stated previously, I'm not a programmer and your RealCode was a bit too complicated for me to follow. I used previous candle values because I assumed the myarray(upcount - 1) in your RealCode was meant to get the count from yesterday. The RealCode provided was intended to provide an alternative structure that used references to previous candles to avoid the need for an array to store the previous value so it could be referenced. If this isn't what you were attempting to do with the array, I understood the intent of your RealCode less even than I originally thought.
QUOTE (edrichmond) Also I took out the "currentindex > 0 " with no obvious change.
The CurrentIndex > 0 check was intended to prevent lookups of Values that do not exist in the Price.Last(1) >= Price.Open(1) section. A better structure that would have done this for the entire thing might have been:
Static Upcount As Integer
If CurrentIndex > 0 Then
If Price.Last(1) >= Price.Open(1) Then
Upcount += 1
Else
Upcount = 0
End If
If Upcount >= 3 AndAlso _
Price.Last(1) > Price.Open(1) AndAlso _
Price.Open > Price.Last AndAlso _
Price.Open > Price.Last(1) AndAlso _
Price.Last < Price.Open(1) Then
Pass
End If
End If
QUOTE (edrichmond) One the time of the day for the "Enter" and "Exit" is given as 4:00PM instead of 9:30AM as it should be since the rules ask for the action to be taken at the next open.
As far as StockFinder is concerned, the entire Daily Bar occurs at 4:00PM (the Open, the High, the Low and the Close). As long as the Entry is at the correct Price, it is working correctly. If you really need to display a 9:30AM Trade for some reason, you would have to create a far more complicated setup using Intraday data.
QUOTE (edrichmond) The next open arrow doesn't always occur on the candle after the two green candles but rather on the second green candle. But the value in the "Trades" table under "Exits" agrees with the value of the candle after the two green candles. In the case of the "Enter" column the value in the table does not agree with the value of the candle indicated or the candle to either side.
As stated above, the Trade Arrows appear to Plotted at the correct locations for me. When I look at the Trades tab, the values appear to match the Trades Plotted on the Chart as well.
If you Share your Layout, we'll take a look and see if we can troubleshoot the issue.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 7/26/2006 Posts: 23
|
Bruce
I shared the layout "bearish engulfing modified" and after all the confusion I have one question. In the rule #1, the "modified bearish engulfing" rule, you had set
netchange as single = price.close(1) - price.open(1)
instead of
netchange as single = price.close(0) - price.open(0)
even though you did not use netchange. If I tried to use the current candle then all the backscanning results disappeared. If I used the previous candle as you had suggested, everything works find. My question is WHY?
Eliezer
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Having netchange be greater than zero when:
netchange as single = price.close(0) - price.open(0)
Contradicts:
price.Open > price.Close AndAlso _
Both can't be True at the same time.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |