Request Rule based strategy using Stochastic
Author: sdbens20
Creation Date: 12/7/2012 4:04 PM
profile picture

sdbens20

#1
I would like to enter a long position anytime during the five days after the 30-day %K Stochastic crosses above 50 and the opening price of any day during the following five days following the crossing is greater than the high of the day the crossing occurred.

Would you please the list the rules needed create this entry point? I've been unable to create the rules list to do this. Also. if you would direct me to a reference that I could have used to perform this task, I'd appreciate it.

Thank you.

Sherm Benson
profile picture

Eugene

#2
It would probably have taken me more time playing with rules trying to achieve it using Multi-Condition Groups, rather than code it:
CODE:
Please log in to see this code.


Edit: StochK period changed from 10 to 30.
profile picture

sdbens20

#3
Thanks for working on this for me, Eugene.

I just ran the code on two year's SPY daily data and there seems to be some problems. Just one buy signal is generated on 2/7/11. This is on day 42 of the data and the 30 day Stochastic has always been above 50 to this point. No BUY should have created since no stochastic crossing up through 50 has occurred yet.

The first day the stochastic crosses 50 and stays above 50 for at least five days is 3/23/11. SPY's high for that day was 125.99. A BUY should have been generated on 3/24/11 since the open was 126.38 (higher than the high of 3/23/11). BUYS should also be generated on 6/30/11, 9/16/11, 10/7/11, 12/2/11, 12/22/11, 4/27 12, 6/19/12, 7/27/12, 10/4/12, 10/16/12, and 11/30/12.


I do not know how to code. Please tell me how to execute this strategy using rules since I'll be adding additional rules once a means of creating BUY signals is worked out.

Thanks, again.

Sherm
profile picture

Eugene

#4
QUOTE:
This is on day 42 of the data and the 30 day Stochastic has always been above 50 to this point.

It's the 10-day Stochastic in my demo code, not 30-day. You might want to change the period in the code. Sorry for the inconvenience, if any.
CODE:
Please log in to see this code.

QUOTE:
Please tell me how to execute this strategy using rules

Rule wizard is quite powerful, but it's not capable of anything. One day you find yourself in a situation when its existing capabilities are not suitable for the task, like with "the opening price of any day during the following five days following the crossing is greater than the high of the day the crossing occurred".
profile picture

sdbens20

#5
Eugene,

The code still does not work correctly after changing 10 to 30. Still shows only one incorrect BUY and misses all the dates for additional BUYS I listed in my last post.

Thanks for trying.

Sherm
profile picture

Eugene

#6
The code works absolutely correctly. You have not specified any exit rules, it's a single position system, so it takes one correct buy and stops processing.

Have a nice day.
profile picture

Eugene

#7
QUOTE:
I would like to enter a long position anytime during the five days after the 30-day %K Stochastic crosses above 50 and the opening price of any day during the following five days following the crossing is greater than the high of the day the crossing occurred.

Just to illustrate my point that you can't claim that the code above does not work correctly:
profile picture

sdbens20

#8
Eugene,

Since I'm not a coder, would you please add any simple exit rule and let me know know how the strategy runs on a year's worth of SPY?

Thanks,

Sherm
profile picture

sdbens20

#9
Eugene,

When I copy your code into the "new Strategy from Code" window, I get a yellow bar just to the right of the line number column. Line 14 shows squiggley red underlining under "= 0" at the end of the line of code. Can that be the reason for our different outcomes?

Sherm
profile picture

Eugene

#10
Sherm,
QUOTE:
Can that be the reason for our different outcomes?

No, it's a Editor's peculiarity. Simply disregard that, it's not an error.
QUOTE:
Since I'm not a coder, would you please add any simple exit rule and let me know know how the strategy runs on a year's worth of SPY?

Sure. Taking your oversold Stochastic for example:

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

sdbens20

#11
Works! Thanks, Eugene.
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).