How does WL handle multiple positions in live trading
Author: tomphm
Creation Date: 9/11/2020 7:17 AM
profile picture

tomphm

#1
In back test, WL handles generated positions from each symbol independently (from other symbols) over the completed range of simulated bars.

If a strategy is trading in real-time at 1 minute interval, and on a dataset that has multiple symbols, then at some point it will generates multiple positions from different symbols at different time.

How does WL handle the multiple positions generated from different symbols in real-time? Does it has a separate list of position for each symbol? or does it has a single list of all the positions but keep track each position based on the symbol associated with a position? How does it know which open position is the right one to close/exit when a symbol met an exit condition? Thanks.
profile picture

Cone

#2
See QuickRef > Position object. Positions have many properties associated with them, like Symbol, Bars object, EntryBar, etc. When you exit a Position, you specify (the script specifies) precisely the position to exit. There is no ambiguity.

Now, remember that the difference with "live trading" is that the script is operating in hypothetical mode - it doesn't have knowledge of live positions (unless somehow you give it that knowledge with some fancy programming). Read the first few pages of the Orders chapter for more information.
profile picture

superticker

#3
QUOTE:
Does it have a separate list of position for each symbol? or does it have a single list of all the positions but keep track each position based on the symbol associated with a position?
From your strategy's point of view, it's only looking at one stock at a time (Positions included) for each iteration of the Execute() block. But doing this won't provide the information needed for WL Performance Visualizers, which need to compare stocks with each other for their workup. So the Execute block caches up the resulting stats from all closed Positions (for all stocks) so that information can be accessed by the Performance Visualizers for their comparative analysis.

In summary, for strategy execution, only Positions for one particular stock are considered and available. For Performance Visualizers, which execute after all trading for all stocks (in a dataset) are complete, all stats for all closed Position profits/losses are available.
profile picture

tomphm

#4
Thanks @Cone and @superticker. Yes, during back-test WL only looking at positions generated from one stock or symbol at a time for a duration of the Execute() block and combine the performance results from all symbols afterward for post analysis. Please correct me if I am wrong, however during real-time (live) trading, WL faces a different environment where it could not look and process positions from a single symbol separate from other symbols within one iteration of the Execute() block.

For example, for an intraday strategy operates on a large dataset, and say, at time t1, t2, t3, it opens positions p1, p2, p3. Since the positions are generated at different times (bars), WL has to cache (store) it somehow to carry on with the execution - this is differed from back-test. At some later time, t4, an exit condition is met for position p2, so WL suppose to find and close p2.

In back-test, WL maintains a list of positions and active positions such as in multiple positions strategies, does it also do the same in live trading?

I use SetGlobalList to hold live performance data that could be shared with the strategy.

profile picture

Cone

#5
QUOTE:
does it also do the same in live trading?
There is no difference. Wealth-Lab always operates with hypothetical trading.

Example:
You're long 50 IBM in your live account because you bought it ad-hoc and now want to sell it with a Wealth-Lab strategy. For a strategy to exit a position in IBM you need to generate an Alert to Sell IBM. But an exit requires a hypothetical position. You can program your strategy buy on any bar in order to have a Position to work with.

It doesn't matter to Wealth-Lab when you buy that Position, and BuyAtMarket(1) works pretty well for this case. But, if you're comfortable with your Global data you could sync your script to it and make your strategy buy on the Date your actually entered the position. For the sell, it makes no difference.
profile picture

tomphm

#6
Thanks @Cone, it's good to know that WL operates the same in live and back-test. What I am after is; after the Execute() block is done, does WL still has any memory of the positions that are generated from that block, after done some experiments, it confirms that it does not as pointed out by @superticker on post #3. My assumption of how WL works in post #5 was incorrect.
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).