Position Management Between Sessions
Author: KEVINP
Creation Date: 9/19/2015 7:20 PM
profile picture

KEVINP

#1
The following question is transferred from this post:
http://www.wealth-lab.com/Forum/Posts/Plot-AD-Line-as-Cumulative-Position-Management-between-sessions-37891

My question:
QUOTE:
2. Does Position Management objects persist from day to day or session to different session? How is this situation handled?


Here is Eugene's response:
QUOTE:
2 - What is a "session" and what is to "persist"? Please elaborate by starting a new thread.



Let me re-phrase the question. How does the code i.e. Position Management Objects know that there is an open position from yesterday (for example) and since the position being opened, WLPro and PC were shut down until the next day.

I think I may have answered my own question: I just saw a post in the Wiki or somewhere that said something to this effect: First, a question was asked... why is there a trading loop in the code if you are only going to use the strategy for live trading? Part of the answer was that the loop recreates the memory of all the trades....

This made me realize that there should be checks in the code to not open a new position if the position is already opened for the same symbol. On the next day, since the trading loop recreates the memory, a record of the open position should exist in the ActivePositions object.

The reason why I was asking this question is because I was using the Strategy Builder (SB). The SB does not have code that does proper checking of open positions in order to prevent opening another position on the same symbol. This was something I was confused about: Why is WLPro opening another position on an already opened position of the same symbol in paper trading? Thus, I think the solution would be to perform adequate open position checking in the code as opposed to maybe using a database to store this information. Same goes for prevention of selling a position that has not been opened.

Is this correct?

Thank you for the help.
profile picture

Eugene

#2
Yes, it is correct.

QUOTE:
The SB does not have code that does proper checking of open positions in order to prevent opening another position on the same symbol

The SB does have that code by default, but you can disable that by checking "Multiple open positions allowed". And the loop is there in rule-based strategies, too. It's like the usual hand-written code.

Most likely, your confusion (and those database considerations) comes from 1) either omitting the trading loop, 2) making a "peeking" kind of error in the code, 3) loading not enough data for an "unstable" indicator (WS Guide > Indicators), or probably --> 4) not loading enough data from the date when system has started trading. For example, you set "Most recent 50 bars", the code opened a position 5 bars later, then after 15 bars of paper trading the starting point is shifted so that the condition is no longer valid, then system creates a new position etc.

P.S. Should you require further assistance with this, please provide the following information:

1. Strategy code used
2. Where is the strategy being paper traded: Strategy Window or Strategy Monitor
3. Single symbol or Multi-symbol mode, Position Sizing, and Data Loading settings, Symbol(s) and Data provider
profile picture

KEVINP

#3
I do not understand the following statement:

From Eugene:
QUOTE:
For example, you set "Most recent 50 bars", the code opened a position 5 bars later, then after 15 bars of paper trading the starting point is shifted so that the condition is no longer valid, then system creates a new position etc.


I know what it means to set the "Most recent 50 bars". I am following when you say: "the code opened a position 5 bars later", but what does this mean:
QUOTE:
...then after 15 bars of paper trading the starting point is shifted so that the condition is no longer valid...


P.S. I see that I need to work on this. Thank you for the suggestions and information. Will do.
profile picture

Eugene

#4
This means that when doing real or paper trading, as opposed to backtesting, it's better to start the trading loop at the date when trading started and leave it fixed. Follow Cone's example here:

Opening Capital in new Portfolio
profile picture

KEVINP

#5
Oh. I don't recall seeing examples with a startBar starting on a specific date, or discussion of this point. However, I did realize that the code should reflect a difference between backtesting and live trading. Okay, I think I am getting the idea.