Avoiding Repurchase in Rotation Strategies
Author: Carova
Creation Date: 2/18/2015 10:16 AM
profile picture

Carova

#1
I started a discussion about adding stops to rotation scripts which helped me develop this piece of code
CODE:
Please log in to see this code.

with Eugene's help. I am now looking to see how to approach adding code to provide a replacement position for the one that was stopped out.

How do I approach this?

Vince
profile picture

Eugene

#2
Vince,

If there are stocks satisfying the strategy's entry criteria, shouldn't it reenter on the next bar following the exit anyway?
profile picture

Carova

#3
Hi Eugene!

I should have been much more clear in my description. When a position is stopped out it is not unusual that the "buy" condition is still in force which leads to a re-purchase of the very same position! :( One way most trading strategies handle this condition is with a timeout. I was looking for a framework that can handle various approaches to mitigating these sorts of problems.

Vince
profile picture

Eugene

#4
OK, topic title has been renamed accordingly.

I don't see what you describe as a problem. Your exit conflicts with the primary rule which still says "Buy". Such "framework" does not exist for rotational strategies because you're probably the first to have encountered such issue. Rotation systems do not account for stops and reentries.

For "regular" systems (i.e. which do not loop over the DataSetSymbols collection), the CooledOff method helps prevent re-entries by introducing a cooling period. Here it will most likely not work as intended, preventing entries in any symbols. The code is open source if you like to give it a go and modify it (without guarantees that it will work) for your strategy. Maybe some other solution exists, so I leave it up to you to let the forum know if you find it. ;)
profile picture

Carova

#5
Hi Eugene!

Would something like this work?

CODE:
Please log in to see this code.


Vince
profile picture

Eugene

#6
Hi Vince,

Your timeout logic makes sense. On the surface, it might work.
profile picture

Carova

#7
Hi Eugene!

You stay safe too!

OK, so I rewrote the code a bit, but there seems to some problems.
CODE:
Please log in to see this code.


First, it dos not seem to be installing the stop consistently.
Second, it is no giving me a cool off period.

What am I doing wrong? Thanks!

Vince
profile picture

Eugene

#8
Hi Vince,

I'd suggest you use PrintDebug statements to indicate the variable's state on each bar.

Although it can take some effort in setting up, debugging your strategies in Visual Studio is a more flexible and powerful method to debug your code.

Good luck!
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).