Any Open Position (in Other Symbols) in Portfolio Mode
Author: Gamba
Creation Date: 9/1/2013 8:59 AM
profile picture

Gamba

#1
Is it possible to check if there are any open positions (short or long) from my dataset in portfolio simulation mode?

For example I want to know when strategy runs on Symbol ABV if there
are any open positions in other symbols, in ABX, for example?

I tried to program it by myself, but with no luck so far.
profile picture

Eugene

#2
Well, you can do it by switching to single-symbol mode and looping through DataSetSymbols as shown in this KB article:

WealthScript Techniques | Portfolio-wide conditions

It works but you might lose some MSB-only performance visualizers (like By Symbol and Contribution):

CODE:
Please log in to see this code.
profile picture

Gamba

#3
Eugene, that was my first approach but it doesn't seem to work.

I have coded a simple sample strategy to check the code and I don't understand why I cannot get the
open positions in my portfolio. You only need two symbols ABV and AMX in the dataset.
There should only be one trade but actually there are two:


CODE:
Please log in to see this code.
profile picture

Eugene

#4
Sorry if I wasn't clear enough. The idea is to rewrite your strategy for looping through DataSetSymbols in single-symbol mode - of course with entries and exits. Without taking trades using SetContext/RestoreContext, your code will not work. That's why I warned that you're going to lose some MSB-only performance visualizers after the rewrite.

P.S. Be careful with class-level variables (i.e. shortsOpen, longsOpen) - unless you declared them as "global" intentionally.
profile picture

Gamba

#5
Ok, I misunderstood your solution. So I have to move Entries to the symbol-context.
Hm ... that would be a big change in my strategies ... I will think about it.

Is or will there be another, maybe smarter solution in portfolio simulation mode?