"Price crosses below price from previous day" does not always work
Author: grtrader
Creation Date: 2/23/2014 4:49 PM
profile picture

grtrader

#1
Using Rules, I am buying at market when the StochK crosses above 20.

I am trying to exit a position using a Sell at Close with "Price crosses below Price from previous day". I want to sell the long position if the Close goes below the Low of the last 3 days.

Options:

Entered for Price 1: Close
Entered for Price 2: Low
Previous Days: 3

For this, the Stock is TAN. Shows a buy on 11/27/13. Should have stopped out few bars later, but did not.

Cannot get the sell to work where StochK is below 20. I have attached a screenshot highlighting one example.

Also,

Looking at the code, there is:
if (CrossUnder(bar,Close, ROC.GetSeriesValue(bar-3,Low))).

Why is Rate of Change used here?



Thanks
profile picture

grtrader

#2
The screenshot is attached here.

profile picture

Eugene

#3
What does StochK have to do with "Price crosses below Price from previous day"? Other conditions that are not indicated can affect the system logic. Please show us how exactly have you defined the exit rules. (A screenshot or code should help.)
profile picture

grtrader

#4
This is the code generated from Rules:


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

grtrader

#5
After generating the chart, where the StochK is below 20 seems to be where the stop fails. The area I highlighted is just one of the areas it seemed to fail. I am trying to find out why.
profile picture

Eugene

#6
A few bars later where you're looking for an exit, the price crosses above price from previous day - not below. Now here's my chart which shows that there was no crossover and consequently, no exit:



Add this snippet to your code to quickly evaluate the series to be crossed:

CODE:
Please log in to see this code.

profile picture

grtrader

#7
Are we talking about the same thing?

The definition is "Price crosses below price from previous day". I selected previous days to be 3. I also selected Price 1 to be Close, and Price 2 to be Low (see screenshot).

Therefore, the stop should be initiated if the close of the current bar goes below the lowest low of the previous 3 days. Correct?

For this case, At the Buy signal,

Bar 1 (the buy signal bar) Low: 38.40
Bar 2: Low: 38.21
Bar 3: Low: 38.14

Lowest Low is 38.14

Bar 4: Close is 37.97

Bar 4 has crossed the lowest low of the last 3 days. A stop should have been initiated. Note that the close is also lower than any of the 3 days.

profile picture

Eugene

#8
QUOTE:
Therefore, the stop should be initiated if the close of the current bar goes below the lowest low of the previous 3 days. Correct?

No. You're confusing "price going below" with "price crossing below" which is a different thing. For the definition of cross over/under, please refer to the QuickRef > CrossOver, CrossUnder. This concept is important to understand as you will find crossovers/unders frequently in rules and code.

As you can see on my screenshot, the price did not cross below a few days after the buy. A cross under happened later. The exit is absolutely correct.
profile picture

grtrader

#9
Thank you for your patience. I am only a few weeks into using Wealthlab.

I did read the items in the Quick Reference.

The cross point I am referring to is the one in this new attachment. Why did a sell not occur here? This crossunder looks the same as the one you pointed out. To me, both follow the definition.

profile picture

Eugene

#10
Thanks for the clarification. The reason there's no sell on the 4th bar is as follows.

Normally, when CrossUnder/Over is being evaluated against two DataSeries (i.e. public bool CrossUnder(int bar, DataSeries ds1, DataSeries ds2)), the method takes four values: a CrossUnder happens when the current value should be below the target value at the specified bar + the previous value had been greater than or equal to the target value at the previous bar.

However, this Rule is programmed in a way that it is based on a different CrossUnder overload method which evaluates only three data items: the current and the previous value and the single target value:

CODE:
Please log in to see this code.


This overloaded call is widely used to detect crossings with oscillator thresholds e.g. RSI 30/70. So, your condition is "Close crosses below Low 3 days ago". On 12/3/2013:

Current value i.e. Close[bar] = 37.97
Target value i.e. Low>>3[bar] = 38.40

Is the current value below? YES

Previous value i.e. Close[bar-1] = 38.28
Previous target value = 38.40

Is the previous value (38.28) greater than or equal to the target value at the previous bar? NO

The point is, in this case the function accepts only the single fixed value and therefore the Rule behaves unexpectedly. This is somewhat counterintuitive but this how it works. I don't know why the rule has been code like this, maybe the developers had a reason.

Anticipating your question re: how to make this strategy work as you designed, convert the system to code and make this little change for the exit to trigger on 12/03/2013:

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

grtrader

#11
Thank you very much!

One more question, does Low>>3 refer to the low of the previous 3rd bar, or the lowest of the last 3 bars?

If it only refers to the low of the previous 3rd bar, what would be the code for the Lowest of the last 3 bars?

After 2 weeks I can pretty much put together codes in Wealthscript using the Help on your website - worst part is dealing with the brackets.

Also, since I am new to this, am I in line asking these questions?
profile picture

Eugene

#12
Low>>3 is the low of the previous 3rd bar. The >> operator shifts the DataSeries (QuickRef > DataSeries Object for more).

The Lowest of the last 3 bars is coded using the Lowest indicator. There's a companion for Highest.
profile picture

grtrader

#13
Thanks, you have been extremely helpful.
profile picture

Eugene

#14
After discussing it among us technicians, we decided to concider this a deficiency in the Rule and so will file a bug report to the development team.
profile picture

Eugene

#15
This issue has been fixed in Wealth-Lab Developer 6.8. The Pro edition has a partial fix (one rule is still affected) and thus requires a manual edit of the output code.
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).