ActiveTrader 2012-05 | Efficient Rotation strategy
Author: Eugene
Creation Date: 4/3/2012 6:21 AM
profile picture

Eugene

#1
Code for ActiveTrader 2012-05 | Efficient Rotation strategy strategy published.

We recommend downloading it directly using the convenient "Strategy Download" feature (found in Wealth-Lab's "Open Strategy" dialog).
profile picture

tedfeely

#2
I am a newbie to Wealth-Lab and am using ActiveTrader 2012-05 | Efficient Rotation strategy.

The results are not what I expected. For example, I am unable to set the position size so that all trades are included. (Actually over 10K trades are not included. See the page below for some examples of settings and results.

I suspect I've got some settings wrong, but am too much of a newbie to know what to do. Thank you for your assistance.


profile picture

Eugene

#3
Welcome to the forums.

Start by reading this FAQ: A Rotation strategy isn't working like it should.
profile picture

tedfeely

#4
The FAQ answered my question.

Thanks.
profile picture

Eugene

#5
wphill asked:

I would like to explore this strategy using etf's.
Eugene offers the following narrative:
QUOTE:
Efficient Rotation is a non-Intraday strategy that continuously holds n stocks of a DataSet that have the highest Kaufman's Efficiency Ratio value averaged over three time frames. Although the number n is determined by the n Symbols Strategy Parameter, you must adjust Portfolio Simulation Mode sizing appropriately for the number that you select. For example, with 3 symbols you might set 33.3% of Equity sizing.



I used an etf data set of 8 etfs, which generally have low inter-correlation. EPP EWJ GLD IEV ILF IWM SPY TLO. I set n=1, equity position to 90%, and margin factor as high as 5 to 1. Data range begins 5-15-2006. With this range all symbols have the same number of bars in order that performance results are always the same no matter which symbol is highlighted to initiate the program. Periods are the same as default except for p3 which is 90 and days held is 45.

My assumption, overly simplistic and incorrect,is that the program ranks the data set by a Kaufman metric and that every n-days, if n symbol is only one, it buys whatever ticker is the highest. I can tell that my assumption is wrong because when running the program there are as many as five symbols that are open at the most current date.

Another point of confusion is that no matter how I adjust the equity percentage or the margin factor, I am still dropping trades.

I see considerable value in the basic structure of this coded program. I am wondering if Eugene or someone could offer additional descriptive narrative for someone that does not understand code, which may require considerable forgiveness.

Within the code I see the following:
CODE:
Please log in to see this code.



By any chance, should the descriptor "lowest" be "highest?" And, if the n symbol was only one would the numeric "3" be written as "1?"

Well, this is a start. Thanks.
profile picture

Eugene

#6
QUOTE:
I can tell that my assumption is wrong because when running the program there are as many as five symbols that are open at the most current date.

To make the strategy always hold a single stock, please comment the following line:
CODE:
Please log in to see this code.

It was added to make the Strategy hold a stock for several days to minimize re-entries. Unfortunately, it seems that the strategy may not be doing it properly. After commenting out, it should work.

QUOTE:
Another point of confusion is that no matter how I adjust the equity percentage or the margin factor, I am still dropping trades.

With 95% equity and 1.05 margin, for me the number of dropped trades is negligible and becomes even less so with Position Options is applied with "Skipped trade solution" and "Max open pos. = 1 + Use what's left" options engaged
profile picture

wmrgrove

#7
Eugene, a quick follow-up question to your comment above, "Unfortunately, it seems that the strategy may not be doing it properly. After commenting out, it should work".

I have been doing a lot of work with Rotational Strategies, are there any issues with 3 to 10 position strategies using the "re-entry reduction" code?

Thanks, Bill
profile picture

Eugene

#8
Only two published strategies, "ActiveTrader 2012-05 | Efficient Rotation strategy" and "Weak-stock rotation", had the re-entry reduction logic and have been updated. For now, I've removed it.
profile picture

Lieuallen

#9
Although it still hasn't completely solved the issue, I think I've been able to improve the re-entry reduction logic. To me, the problem was that the original code prevented sales for a specified number of days, but didn't prevent new buys. So, I added:
CODE:
Please log in to see this code.

immediately below the "//Buy new positions" comment. This will not allow purchases if you already have the maximum number of positions.

However, on my test run, this revised code produced 440 trades and 52 skipped for insufficient capital (with 3 symbols to be held, 30% equity sizing and 1.2 margin ratio).
profile picture

Eugene

#10
kbellare asked in a duplicate thread:

I adapted the ActiveTrader 2012-05 Efficient Rotation strategy (code below), so that I could draw the Close and Indicator of each symbol. Running into 4 issues described below - please address each of these 4 ..

1) I modified the ERHolder list class to include an indicator DataSeries as shown in code below, so i can plot the indicator - however, it disallows using [bar] in the item1.ema in the code below and gives a syntax error. How do i fix this?
CODE:
Please log in to see this code.


2) While plotting the price and indicator on the same chart (code snippet below), how do i make it plot each symbol price/indicator in a different color?
CODE:
Please log in to see this code.



3) How do i ensure it plots the Buy and Sell markers for trades of each symbol (Close is plotted as a SolidLine, not as candle to de-clutter). If not possible with SolidLine style, how do i plot Candles of multiple symbols?

4) Finally, can i show relative growth of all symbols (instead of absolute prices) over a chart timeframe? What chartpane do i use and how to hide the PricePane? Attached is a screenshot of what i'm trying to achieve.



CODE:
Please log in to see this code.

profile picture

Eugene

#11
#1 - This code modification is incorrect and should be discarded. There's no need to touch "public int Compare". Loop through the List<ERHolder> list in a foreach loop and plot each ERHolder's "ema" property. Here's one example of plotting multiple DataSeries:

Indicators | How to Plot ROC of multiple symbols on same chart

#2 - For example, randomize it. See answer #4 below.

#3 - It's a good habit for both newbies and seasoned users like you to check with the FAQ: Is there a way to see the trades on secondary symbols?

#4 - Again, see Knowledge Base: WealthScript Techniques | Relative Performance Chart

Additionally, code from this KB article answers your question #2 i.e. plotting indicator in a different color.

#5 - And again, please take a look in the same FAQ: I want to chart an indicator, but without the stock price. Can I hide the PricePane?
profile picture

kbellare

#12
Thanks Eugene,

This was helpful - I'm running into 1 issue plotting the Buy/Sell signals of Secondary Symbols - I used AnnotateBar and the Buy/Sell signals are being plotted on the Primary Bars, even though I set SetContext and RestoreContext before/after the AnnotateBar.
- See screenshot attached and code snippets below. How do i fix this?

CODE:
Please log in to see this code.


CODE:
Please log in to see this code.


profile picture

Eugene

#13
QUOTE:
I used AnnotateBar and the Buy/Sell signals are being plotted on the Primary Bars, even though I set SetContext and RestoreContext before/after the AnnotateBar.

SetContext has no effect on AnnotateBar. In this case, use AnnotateChart as exemplified by this downloadable Strategy:

ActiveTrader 2011-05 | Inverse ETF switching system

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

kbellare

#14
I'm applying this strategy to intra-day futures that have different Start and End times (i.e. trading hours) - the charts are showing different hourly bars (e.g. 3pm of @BO and 10pm of @QG) on the same vertical line, which also distorts the backtested performance results.
- My Portfolio simulation settings are last 2000 bars, 7% of equity for each symbol, max 2 positions.

How do i synchronize these symbols in this code, so that the strategy evaluates indicator and price values across symbols from the same time (i.e. the 3pm price and indicator values of all symbols line up)?

thanks
Kiran
profile picture

Carova

#15
How could I approach using a secondary filter with this type of script, i.e. selecting the "top 10" stocks and then selecting the "best 5" from the "top 10" using a secondary metric (e.g. RSI)? Thanks!

Vince
profile picture

Eugene

#16
Hi Vince,

Combined rotation/ranking question

Unfortunately, that discussion's got hijacked with a ton of unrelated posts so you might want to read it up to my reply #16 and pretty much disregard the rest.
profile picture

Carova

#17
Hi Again Eugene!

Thanks!

Did a search but found no data. How does one add a stop-loss with a replacement stock to these rotation scripts? I assume the stop might be something like this:
CODE:
Please log in to see this code.

Is this correct? Then how do I get a "replacement" stock from the list?

VinceI
profile picture

Eugene

#18
Vince,

Stops are not popular in rotational strategies but I've found one example:

Snapping Tortoise Rotation

The "level" can be assigned to Position's .Tag property after its creation, for example. Don't forget about boxing and unboxing.
profile picture

Carova

#19
I will take a look at it. Thanks Eugene!


I realize that my knowledge of C# is way too primitive. :( The script provided by ss161 has errors when I run it and I do not even know where to begin. The rotation scripts that you have written make infinitely more logical sense! Can we continue the discussion of stops using your design for rotation scripts?

Vince
profile picture

Carova

#20
This is my latest attempt to incorporate stops into a rotation strategy
CODE:
Please log in to see this code.


What am I doing wrong? Thanks!

Vince
profile picture

Eugene

#21
Proposed fix:

CODE:
Please log in to see this code.


Note 1: The "p.Bars" makes the whole difference.

Note 2: no need in SetContext/RestoreContext and in the foreach loop.
profile picture

Carova

#22
Thanks Eugene!
profile picture

surfthru

#23
I went to ActiveTrader Mag to purchase "The efficient rotation strategy by Volker Knapp"

But it appears the site is down? I subscribed to the mag some years ago.

Does anyone know where to obtain the article?

http://store.activetradermag.com/theefficientrotationstrategy.aspx
profile picture

Eugene

#24
Indeed, the website and their cart at 02e7912.netsolstores.com seems to be misconfigured or down. I know that Currency Trader was closed last November but Active Trader Mag wasn't mentioned. Please create a support ticket and we'll try to help you out.
profile picture

Carova

#25
Hi Eugene!

I am looking to use my custom indicator in this Rotation Strategy and I am looking for a pointer to adding that "module" into the strategy. For this C# novice how do I add a subroutine to do this calculation outside of the Main module so that my code calls it correctly? I searched both the Forum and the Programming Guide looking for guidance about adding a custom indicator but had no luck. Thanks!

Vince
profile picture

Eugene

#26
Vince,

An example placement of such "module" can be found in the WealthScript Programming Guide > Indicators > Custom Indicators > How to: Create a "semi-formal" Custom Indicator.
profile picture

Carova

#27
Thanks Eugene! Just what I needed.

Vince
profile picture

ashridharani

#28
Hello,

I cannot get a buy alert but only sell alerts issued for the next trading day when using Rotation strategy.

I downloaded the "Activetrader 2012-05 [Efficient Rotation Strategy] Rev B" from Wealthlab "Symbol Rotation" folder. Without modifying it or optimizing it I ran it against the following sample dataset : AGQ DGP DRN ERX FAS MATL MIDU SOXL TECL TNA TQQQ .

Using "TNA" symbol to run the strategy there were 4 trades done on 05/15/15. Two "Sells" : DRN and DGP and two "Buys": ERX and FAS.

So to test out the problem I re-ran the strategy using date range from 01/01/2008 - 05/14/15. The idea being to see what alerts would I have got on May 14th for the next day. I only got the two sell alerts. No Buy alerts. Now if I move the date range forward by one day to May 15th. I see all 4 trades being executed. As a matter of fact for any of the trades in the backtest where there is a buy and sell (all trades) on the same day, just randomly testing, I only get the sell alerts.

Assuming that I should be getting Buy alerts, and since I am using the strategy as is, I was hoping you can help me figure out if there is some hidden configuration file that I need to tweak to get "Buy" alerts or sort out the cause of this issue.

Regards,
Anish
profile picture

Eugene

#29
Hello Anish,

Thanks for the heads-up. This should fix it:

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

ashridharani

#30
Thanks Eugene. That did it. Revised code snippet below for other beginners like me.


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

Eugene

#31
Another challenge is that the latest fix introduces a new problem: the system now may open much more positions than allowed by its "n Symbols" setting. The problem lies within another tweak called "Minimum holding time":

CODE:
Please log in to see this code.


To fix the new issue, I suggest disabling that tweak completely:

CODE:
Please log in to see this code.


Optionally you could get rid of the now inactive parameter:

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

ashridharani

#32
Hi Eugene,

Is there another way to modify the code to incorporate "Minimum holding period" in the strategy without triggering the bug?

Regards,
Anish
profile picture

LenMoz

#33
Anish,

QUOTE:
Is there another way to modify the code to incorporate "Minimum holding period" in the strategy without triggering the bug?

Here's one way...

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

ashridharani

#34
Hi Len,

Thank you very much. This will help greatly.

Regards,
Anish
profile picture

Eugene

#35
In a duplicate thread, lukeallen63 wrote:

Hello All,

I am working on trying to test a sector rotation strategy, and have noticed the Efficient Rotation Strategy Rev C is kind of what I'm looking for except instead of using the Kaufman Efficiency Ratio, I would like to change it to use trailing 3,6, and 12 month returns. The strategy is a monthly system, only using monthly bars, but I need the ranking feature and using the average of 3 periods like this does. I have tried and failed, mostly because I lack substantially the programming skills to implement it. The dataset would include the Fidelity Sector ETF's (11 in all), get the average of 3,6,12 month trailing return (including dividends if possible) and then rank them, buy and hold the top three and repeat this at the end of every calendar month.

I would also like to put a filter saying is SPY is above 12 month SMA, keep investing in the top 3 sectors, but if below, no trades to be taken and go flat. But if that can't be done, still would be interested in the trailing return ranking system.

I couldn't find anything similar in the forums, but if someone knows where I could get some help on this please advise.

Thanks in advance,

Luke
profile picture

Eugene

#36
QUOTE:
except instead of using the Kaufman Efficiency Ratio, I would like to change it to use trailing 3,6, and 12 month returns


If not using Kaufman's ER, that would be a very much different strategy, wouldn't it? This Wiki FAQ should come in handy in your implementation of the rule:

FAQ | Strategies and WealthScript > Rotation strategies > "I need other rotation rule other than the built-in RSI."

QUOTE:
The strategy is a monthly system, only using monthly bars


Switch to the Monthly data. It's going to be much easier than coding with SetScaleMonthly() etc.

QUOTE:
get the average of 3,6,12 month trailing return

That simply is a 3-, 6-, and 12-period ROC, isn't it?

QUOTE:
I would also like to put a filter saying is SPY is above 12 month SMA,


Check this out:

Rotation Strategy based on Highest ROC that on weekly data and external symbol

On a related note, you may also find this helpful:

* GetExternalSymbol and SetContext/RestoreContext in the QuickRef,
* DataSeries > Accessing Secondary Symbols in the WealthScript Programming Guide,

Hope this helps in your venture.
profile picture

Carova

#37
If I wanted to add a "filter" to Len's revision, i.e. "Buy" when the 50d ROC is positive and "Sell" when it is negative, Where and how do I add that type of logic? Also, what happens when there are not enough candidates to fill all of the "top slots"? Currently the script buys even when the "holder.er" is negative.

Thanks!
Vince


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

Carova

#38
I have solved the "BUY" portion of the problem (the solution really is just an effective hack) but I am really stuck on the "SELL" portion of the filter (sell the position when the filter is "false").

Can someone help with a suggestion?

Vince


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

Carova

#39
Is this proposed "SELL" code correct? I do not think so since it does not generate any "SELL" signals! :(

All help appreciated!

Vince

CODE:
Please log in to see this code.
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).