state maintenance during strategy calls
Author: jalalfeghhi1
Creation Date: 1/17/2011 8:05 PM
profile picture

jalalfeghhi1

#1
Eugene,
Hi, I just ran into an issue and do appreciate your thoughts on this matter. My system works on DataSets and for each symbol in the DataSet it calculates a set of parameters to be used later to decide which symbol(s) in the DataSet should be traded. What I noticed is that WLP makes calls to my strategy one symbol at a time, which is the correct behavior. The problem is that when WLP calls the next symbol, I have already lost my calculated data from the previous execution of the routine. I need to keep this data until my strategy runs on all the symbols.

I think what I should do is to iterate through all the symbols in the DataSet from within my system, this way I can keep all my calculated data. With this approach, WLP must no longer run my strhategy for each symbol: I should click on the DataSet and WLP runs on my strategy once for each incoming bar.

Am I on the right track here? Can I instruct WLP not to run my strategy on each symbol? Do appreciate all your support.

-Regards J
profile picture

Eugene

#2
J,

Depending on your strategy design, you may like to:

* loop over DataSetSymbols and be on the right track but lose the ability to execute the system in Multi-Symbol mode (code looping over DataSetSymbols e.g. rotational strategies, shouldn't be used this way to avoid getting into the mess of duplicate trades and incorrect performance metrics),

* leaving the code as is but adding some logic that uses Wealth-Lab's global memory to store the intermediate processing results on the previous symbols (and clear them on the next bar). QuickRef (F11) for SetGlobal, GetGlobal, and ClearGlobal,

* off the top of my head: storing the calculated data in class level variables may also help, acting in a manner similar to global variables, but please don't quote me on that.
profile picture

jalalfeghhi1

#3
Eugene,
Thanks for your reply, your third idea sounds exciting and I will explore that. Meanwhile, I am still confused. If I define a Dataset and run my strategy on the Dataset in a live INTRADAY (1 minute) mode, it seems to me that the Strategy Monitor should execute my strategy only ONCE every minute for the entire Dataset, allowing my logic to examine all the symbols in the Dataset and make calculations. I have tried this with a Dataset consisting of two symbols and it looks like the Strategy Monitor runs my strategy TWO times every minute, once for each symbol of Dataset. Is that the right behavior? I don't understand that, so if I have 100 symbols in my Dataset, Strategy Monitor will run my strategy 100 times every minute?

Also when I look at the RSI symbol rotation strategy, this strategy loops over all the symbols in the Dataset. If Strategy Monitor calls RSI symbol rotation once for every symbol in the dataset, then I cannot understand how the RSI symbol rotation strategy works.

Thanks for your support, it still feel I am missing some concepts here :-(

-J
profile picture

Eugene

#4
How was RSI Rotation added to the SM: on a single symbol or as a portfolio/multi-symbol mode backtest?
profile picture

jalalfeghhi1

#5
Eugene,
I did not run the RSI Rotation, only examined the code, but let's view this code fragment from RSI Rotation;

foreach(string symbol in DataSetSymbols)
{
SetContext(symbol, true);
if (Bars.FirstActualBar < bar)
{
RSIHolder holder = new RSIHolder();
holder.symbol = symbol;
holder.rsi = RSI.Series(Bars.Close, Period)[bar];
list.Add(holder);
}
RestoreContext();
}

The foreach(string symbol in DataSetSymbols) appears three times in the entire code and it indicates that RSI Rotaion expects to run on a Dataset.

That is where I am confused: If RSI Rotation uses this foreach(...) statement, SM must no longer call the RSI Rotation Strategy for each symbol, but as far as I understand (and verified by single stepping through my code) SM always calls a (any)strategy every time for each symbol of Dataset for a new bar is formed. It seems to me one of these loops is unnecessary. Actually, IDEALLY I would like to in my code take over of the looping (foreach statement), this way I will keep the results of all my previous iterations and won't need to use globals, etc.

If my observations are true, is there any way to instruct SM not to run the strategy for every symbol of the Dataset and let the strategy take care of the looping process? I do appreciate your insights in this issue.

-Regards, J
profile picture

Eugene

#6
Here's my question rephrased, this is what matter most and and this is still unclear:

<<How was your strategy added to the SM: on a single symbol or as a portfolio/multi-symbol mode backtest?>>

Since you didn't give me an answer, currently I can only suggest to check out if this FAQ applies to your case:

A Rotation strategy isn't working like it should.
profile picture

jalalfeghhi1

#7
Eugene,
I click on SM, Click on Add Strategy, choose my strategy, then WLP brings up the Strategy Setting Activation dialog box. For the Data Source (Select a Dataset or a Symbol), I choose my dataset. That is all I do, and I do not see any reference to portfolio/multi-symbol mode backtes, perhaps by that you mean the same thing as Dataset. I also choose 1 minute data scale to have live intrday trading system.

Hope that answers you question :-)

-J
profile picture

Eugene

#8
That's what I wanted to hear. If you choose a DataSet, that's incorrect way of doing things. You should select an individual symbol - just like the FAQ says.
profile picture

jalalfeghhi1

#9
Eugene,
I think I understand now. If I choose only symbol from my Dataset, they SM runs my strategy only once (no matter how many other symbols there are in DS), then my logic foreach loop will handle all the symbols. It seems to me I should proceed this way. Just one thing you said concerns me: "...loop over DataSetSymbols and be on the right track but lose the ability to execute the system in Multi-Symbol mode.." What do you mean by lose the ability to execute the system in Multi-symbol mode? What capabilities do I lose exactly with my approach? What does WLP in Multi-symbol mode offers me that I cannot duplicate with my foreach loop?

-Best, J
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).