Stock Splits

Posted By: trenki2

Stock Splits - 06/30/17 16:31

How does Zorro handle stock splits?

For instance when do enterLong() with 100 shares and then the stock split happens 2:1 and later I exit the trade with exitLong().

Does Zorro exit the 200 shares? How does it know that the stock split happened? I don't see a function in the broker plugin API for that.

What happens to the stop-loss and take-profit levels in such a case?
Posted By: jcl

Re: Stock Splits - 06/30/17 16:53

It depends on how the script trades. For Z8, stock splits are no problem since it trades position based and thus always knows the right number of shares to sell. But normal scripts do not care of stock splits. Non-NFA brokers will close the whole position with exitLong(), NFA brokers will close only half the position. So the script itself must take care of stock splits and adjust the position and exit limits accordingly.
Posted By: kankan

Re: Stock Splits - 04/18/19 06:08

To keep the topic together, I decided to add my question to this as well, regarding historical data handling.

1 - How are series handled when a split occurred overnight?
2 - Is it better to store the historical data as adjusted or unadjusted? And if we adjust it after a split, we basically need to retrain everything, correct?
3 - Some brokers will cancel any open stop/profit orders after a split occurs (e.g. IB). I imagine we have to manually detect that and re-issue those orders?
Posted By: jcl

Re: Stock Splits - 04/18/19 07:10

Which variables and series must be adjusted and which not depends on your script. You must know what you're doing. How to handle open trades depends on how your broker is handling them. You don't reissue orders, but you usually must adjust volume, prices, and limits when a split is detected.

You don't retrain after a split. You normally train with adjusted historical data.

Posted By: kankan

Re: Stock Splits - 04/21/19 13:35

In case of IB, the broker will cancel all open orders when the split or a special dividend happens. This means that if you have an already open trade, all of its stop losses and profit targets are cancelled and you have an unprotected trade. In Zorro, how would I re-issue these exit orders then?

Regarding adjusting historical data...
So when a split happens, would this approach work?
1 - detect an upcoming split
2 - when the market is closed, close Zorro (keep Open trades and keep trading)
3 - adjust historical data
4 - restart Zorro, reloading the session
5 - Zorro re-runs the Lookback period on the adjusted data, thereby adjusting the series <== Would this actually happen???

Thanks!
Posted By: Spirit

Re: Stock Splits - 04/21/19 14:05

IB cancels nothing because Zorro normally has no open orders. Your script must adjust the prices and stop losses internally. Closing Zorro helps not, I dont think that IB will adjust his price history, so when you restart the session the prices are still wrong. The correction must be done in the script. Or it must stop trading until the stock split is past the lookback period.
Posted By: AndrewAMD

Re: Stock Splits - 04/23/19 11:10

Now suppose I have an NFA broker like IB, and...
* I have an trade with 100 shares long, market price is $80.
* The stock splits 2:1, so now market price is $40, and I am holding 200 shares long.
* My script detects the stock split, by reading large differences between open and close bars.

Can I just alter all trade structs for that asset? Say...
* TradeLots *= 2;
* g->tr->fEntryPrice /= 2;
... etc.

And then suppose this trade is closed, the correct size order will be issued to the broker?

Or is it perhaps more complicated than that because I need to manage phantom trades and pool trades?
Posted By: jcl

Re: Stock Splits - 04/23/19 11:30

Yes, you can do it this way. Better don't detect stock splits by comparing bars, but check the PriceJump variable. Then run a loop over all open trades of that asset, regardless if they are phantom or pool trades. Multiply also TradeUnits with the PJ factor.

If you want to handle stock splits in your script, I suggest to do it either completely or not at all. Handling them completely involves adjusting all trades and all affected variables. Not at all means that the script just issues a warning, cancels all trades of that assets, and suspends trading with it. You must then close the positions manually and wait as least for the length of the lookback period before new trades can be opened.
Posted By: AndrewAMD

Re: Stock Splits - 04/23/19 14:23

Thanks.

It appears PriceJump help determine stock split ratios, but what about reverse stock splits?

I'm guessing I would need to manually calculate a reverse stock split ratio.

The LookBack shutdown method is looking more appealing now, but I would like to at least flatten my position automatically, in case I'm not reading my emails. So I can either alter the trade structs and close the trades, or I can send a special BrokerCommand (depending on the plugin).
Posted By: jcl

Re: Stock Splits - 04/24/19 06:37

As to my knowledge, a reverse split leads to a temporary different ticker symbol. If so, it cannot be detected by checking the price. You need to poll a ticker list or event list.
© 2024 lite-C Forums