Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Stock Splits #466753
06/30/17 16:31
06/30/17 16:31
Joined: Aug 2016
Posts: 95
Wien
T
trenki2 Offline OP
Junior Member
trenki2  Offline OP
Junior Member
T

Joined: Aug 2016
Posts: 95
Wien
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?

Last edited by trenki2; 06/30/17 16:35.
Re: Stock Splits [Re: trenki2] #466755
06/30/17 16:53
06/30/17 16:53
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.

Re: Stock Splits [Re: jcl] #476876
04/18/19 06:08
04/18/19 06:08
Joined: Apr 2019
Posts: 20
K
kankan Offline
Newbie
kankan  Offline
Newbie
K

Joined: Apr 2019
Posts: 20
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?

Re: Stock Splits [Re: kankan] #476877
04/18/19 07:10
04/18/19 07:10
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.


Re: Stock Splits [Re: jcl] #476902
04/21/19 13:35
04/21/19 13:35
Joined: Apr 2019
Posts: 20
K
kankan Offline
Newbie
kankan  Offline
Newbie
K

Joined: Apr 2019
Posts: 20
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!

Last edited by kankan; 04/21/19 13:37.
Re: Stock Splits [Re: kankan] #476903
04/21/19 14:05
04/21/19 14:05
Joined: Sep 2003
Posts: 929
Spirit Offline

Moderator
Spirit  Offline

Moderator

Joined: Sep 2003
Posts: 929
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.

Re: Stock Splits [Re: Spirit] #476920
04/23/19 11:10
04/23/19 11:10
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
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?

Re: Stock Splits [Re: AndrewAMD] #476921
04/23/19 11:30
04/23/19 11:30
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.

Re: Stock Splits [Re: jcl] #476924
04/23/19 14:23
04/23/19 14:23
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
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).

Re: Stock Splits [Re: AndrewAMD] #476933
04/24/19 06:37
04/24/19 06:37
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
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.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1