Trying to write a list of data to global memory and retrieve from another strategy
Author: angel57
Creation Date: 5/24/2009 6:13 PM
profile picture

angel57

#1
I'm trying to write a list of data to global memory and then retrieve from another strategy. I can't get the attached code to compile due to my C# skills and being a little confused on what kind of data can be written to global memory. I'm sure it's something obvious, but I can't see what I need to do differently.

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

Cone

#2
You almost had it in the commented code, but were missing the parentheses -
CODE:
Please log in to see this code.
profile picture

angel57

#3
Thanks. The code compiles and works and runs in the same strategy. Now when I put similar code (see code snippet below) in a second strategy so I can pull the data from global memory, it compiles ok, but I get the following runtime error.

[A]Systems.Collections.Generic.List'1[WealthLab.Strategies.HighPoints] cannot be cast to [B]Systems.Collections.Generic.List'1[WealthLab.Strategies.HighPoints]. Type A originates from mscorlib, at WealthLab.Strategies.

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

Cone

#4
The definition of your generic list is loaded twice from two different places. You probably have to create a single class library using Visual Studio (or equivalent) that you can reference in all your scripts.
profile picture

angel57

#5
Thanks Cone. Always appreciate your quick responses. Can you point to some examples, or just google my way from here?
profile picture

Eugene

#6
profile picture

angel57

#7
Thanks. Works great. For future reference for others, after compiling the dll in release mode and creating the class library (call it wl_tools.dll), then you need to copy wl_tools.dll to the WealthLab directory with other dll's (in my case it is C:\Program Files\Fidelity Investments\Wealth-Lab Pro 5), and put a directive at the top of your strategy file "using wl_tools;", then compile strategy in Wealth-Lab.
profile picture

Cone

#8
That's one way. Another way is to use the References button in the Editor toolbar (Version 5.3 and up) to locate the component so that you don't have to copy it to the WL install folder.
profile picture

psimmons

#9
I am using SetGlobal and GetGlobal to signal status, including position count, profit/loss and to stop trading. The strategy is intraday.

The functions work successfully in the real world for live trading, but seems to work only partially when Multi Symbol Backtesting.

Is there a need to synchronize the global object pool in some way? If the mechanics of a backtest implemented by testing each symbol sequentially and then the positions are calculated as a post process, then I presume I must need to do something for my strategy backtest to work correctly, but I do not see any synchronization in the examples on the forum or knowledge base (such as Interacting Dynamically with Portfolio Level Equity).

profile picture

Eugene

#10
When it seems to work partially, how you're using Set/GetGlobal in the code and how did you exactly determine that it works "partially"?
profile picture

psimmons

#11
The code does a SetGlobal during the entry and exit routines. It then does a verification of the value after the entry and exit routines. This code is shown below.

The global object for each symbol in the Dataset is called Bars.Symbol+"positions". This is read, converted to a double and if it does not match the local variable positions count, then the global object is corrected. The same is done for profit.

Then the global object is accumulated for all symbols and if this exceeds a maximum position count (plus hysteresis) and if this symbol has a position, then that position is sold (each symbol can hold multiple positions).

The profit example then looks for if profit has exceed a certain level and then had a pullback, and will then exit positions and stop trading for the day.

CODE:
Please log in to see this code.


When I say partial, when I look at the trades executed after the backtest, some symbols in the dataset have exited and stopped trading for the day, but others keep trading. Short time period backtests ( a few months of 1 min intraday) appear ok (I have not proved if it is fully correct), but 10 years of backtest does not work correctly.
profile picture

Cone

#12
Why are you using global memory? After reading the first couple lines of code, my choice would have been to use a Dictionary<string, List<Positions>>, which would make accessing and updating a symbol's Positions much more direct/easy.

Given the code above, the problem could be that you use LastPosition logic in an incongruent way after the "(all_symbols_profit > 1000 )..." test. In other words, if your strategy exceeded the 1000 profit but had already sold the LastPosition because of the previous maxpositions test, then it wouldn't pass the "if (IsLastPositionActive)" test to sell more positions; which to me looks like you'd continue to hold positions that you didn't intend to hold.

Anyway, that's just a guess... it's hard enough to troubleshoot someone else code when you have all of it, let alone just a snippet.
profile picture

psimmons

#13
Thanks for the guidance. I will try this.