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
Size:
Color:
Vince,
If there are stocks satisfying the strategy's entry criteria, shouldn't it reenter on the next bar following the exit anyway?
Size:
Color:
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
Size:
Color:
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. ;)
Size:
Color:
Hi Eugene!
Would something like this work?
CODE:
Please log in to see this code.
Vince
Size:
Color:
Hi Vince,
Your timeout logic makes sense. On the surface, it might work.
Size:
Color:
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
Size:
Color:
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!
Size:
Color: