Creating a Bollinger Bands rotation strategy
Author: SimhaD04
Creation Date: 7/9/2013 3:16 PM
profile picture

SimhaD04

#1
Using your sample code, Weak-Stock Rotation, I tried to write a code for the following strategy:

QUOTE:
Read in a database of stock symbols. For each symbol determine its position within Bollinger channel bands.

Assign a weight, w_i, from 0 to 1 depending on its position between the bands: 0 at or below the lower band and 1 at or above the top band.

Determine the average weight, w_av, of a symbol, w_av = w_i / N, where N is the total number of symbols and compute (w_i - w_av) for each symbol.

Select 2K symbols, 2K<N, K symbols with the largest positive weights and K symbols with the largest (in absolute value) negative weights. Print out the selected symbols and their signed normalized weights: (wi - wav) / (2K).


In Fortran, the computational portion takes just a few lines of code, so I include it here:
CODE:
Please log in to see this code.


Your code with my modifications (and errors) compiled fine up until I started making changed below line 50. I stopped at line 55 and the rest is your old code.

CODE:
Please log in to see this code.


I would appreciate if you help me to get it going either by suggesting changes or a sample code along the lines of the algorithm I am trying to implement.

Thanks.
profile picture

Eugene

#2
CODE:
Please log in to see this code.


1. holder.bb - I guess you meant to say holder.rsi instead. It's a double value whereas you're assigning entire DataSeries to it, so it's not going to compile. Additionally, "BBUp - bar" makes no sense to me: I don't think you really wanted to subtract the current bar number from the Upper BB.
2. av_weight - getting closer now that you're trying to access a value of a DataSeries. For the proper syntax, check out how the Weak Rotation strategy does it, or the WealthScript Programming Guide > DataSeries > Accessing a Single Value from a DataSeries.

In short, that piece should read something like this (I suppose):

CODE:
Please log in to see this code.


profile picture

SimhaD04

#3
you are right, I wanted to subtract current price from BBUp, not bar number. How can I do that? thanks
profile picture

Eugene

#4
Current price is Close, for example. Follow my pointer to the WS Programming Guide, and you'll find out how.
profile picture

changhengyiu

#5
Hi Eugene
I am trying to rebuild this model.Compiling is ok but it comes error after runing the strategy.Could you help to take a look?

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

Eugene

#6
Hi,

Which error? Am I supposed to guess? I know, you probably wanted to save yourself some typing since copying it to clipboard is impossible. But next time please don't hesitate to type in its precise text. ;)

At first glance, you forgot to initialize this strategy parameter in the constructor before accessing it in the rest of the code:
CODE:
Please log in to see this code.


There are 4 StrategyParameters defined, and only 3 are in the constructor.
profile picture

changhengyiu

#7
Sorry it is my bad not expressing clearly.
haha...you guess wrong...that's because it is not showing Enghish on error part in my computer and dont know how to inperpret.
Anyway, thanks to Eugene agin and have a nice day.