Setting up a buying period within 10 days of a 21-day high
Author: Tobey
Creation Date: 4/19/2017 2:52 PM
profile picture

Tobey

#1
Hi Cone & Eugene,

I'd like to limit the buying time of a system to within 10 days of a 21 day high.

If Bars since last 21 day new high is less than 10
If Price is 5% less than 21 day high
BuyAtMarket

How would I create that 10 day window following the 21 day High?

Thanks again for your help
Tobey
profile picture

Eugene

#2
Hi Tobey,

Here's an example of how to implement this:

Crossing within the last 5 days
profile picture

Tobey

#3
Hi Eugene,

I tried to adapt the code you showed me but I didn't get all the way there. I'm not sure what the _howMany parameter is.

Here is my poor attempt. Is there more information, other examples or do you have another suggestion?

Thanks again for the help
Tobey


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

Eugene

#4
I think that CrossOverBar better applies to this case. Here's your entry with a dummy exit after N fixed bars:

CODE:
Please log in to see this code.


Another possibility is to declare a timeout: WealthScript Techniques | Setups, Triggers, Delays, and Timeouts.
profile picture

Tobey

#5
Hi Eugene,

Thanks for the Code! Pretty fancy with variables in the Description. I hadn't seen that before.

It looks like the code is setting the 10 day buying window from the cross to a new high. This is OK even with a couple of new high days, but with a run up of a few days you're shorting the buy window. How could the count for the buying window be set to the most resent high?

CODE:
Please log in to see this code.


Once again thanks for the help and the fancy code!
Tobey
profile picture

Eugene

#6
Tobey,

You're welcome.

A runup resets the condition, not shorting the buying window. It's always 10 days (or whatever the "Within" slider is set) since the last new high. Could you show me an example in some particular stock?
profile picture

Tobey

#7
Hi Eugene,

Yes you are right. Every thing is working.

I did add your variable code to the green background
CODE:
Please log in to see this code.

CODE:
Please log in to see this code.


I also added an additional line to your xPane just for looks.
CODE:
Please log in to see this code.


The attached chart of PVH shows what I am seeing. The detail chart show the last signal. In that case it did not pickup the 3/29/17 High of 104.28. But this could be a data issue not a code issue.

I really appreciate your help! This is fare better than where I started out.
Tobey
profile picture

Eugene

#8
Hi Tobey,

I see, good observation. I think this should get there. Set "Within" to 15 bars to get an alert for tomorrow on PVH:

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

Tobey

#9
Hi Eugene,

You got it! It works great! Many thanks!

Tobey
profile picture

Eugene

#10
You're welcome!
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).