Stop and reverse in live streaming mode
Author: avishn
Creation Date: 10/15/2009 3:55 PM
profile picture

avishn

#1
I apologize in advance if this question has been asked before, I couldn't find anything on the forum...

I'm trying to implement stop and reverse logic. The current implementation works fine in backtesting mode...
CODE:
Please log in to see this code.

... but it fails to execute BuyAtMarket in live streaming mode. This kind of makes sense, since the "next" bar is not available yet in live mode, so CoverAtStop always returns false.

What's the prescribed way to deal with that type of scenario? I feel I'm missing something basic here.

profile picture

Cone

#2
Well, the snippet above is an example of "peeking". The logic says, "if I sell at my stopPrice on the next bar, buy that bar on the open". That's not possible to do in real life, and likely inflated your backtest results.

There are 3 ways I can think of to do the stop and reverse, depending on what you're really trying to achieve.

1. Use a BuyAtStop order if you really want to execute "at market" when the stopPrice trigger is touched. The code -

CODE:
Please log in to see this code.


2. Another way is to operate on a closing value and use market order for both -

CODE:
Please log in to see this code.


3. Finally, you could execute the touch stop, but enter at market on the following bar if the Close exceeds the stop price. The logic for this would have to be more integrated with the script.

The problem with the first two methods is that I'm not sure if the Fidelity backend will allow simultaneous Cover and Buy orders. I think stop and reverse is supported, but maybe their telephone trading support can answer this question.
profile picture

avishn

#3
I really appreciate a lightning fast response, as usual. Thank you!

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).