New Members: Be sure to confirm your email address by clicking on the link that was sent to your email inbox. You will not be able to post messages until you click that link.
I would like to rank the results of a scan based on the average of two Bollinger Bands indicators:
BB Width(50, 2) / max(50, BB Width(50, 2))
BB Width(200, 2) / max(200, BB Width(200, 2))
I attempted this instruction, but it is not working. All results are showing a zero value:
rank by [[[BB Width(50, 2) / max(50, BB Width(50, 2))] + [BB Width(200, 2) / max(200, BB Width(200, 2))]] / 2] ascending
While the following instruction does provide some results, the values do not match the average of the two. I believe this discrepancy is due to them not being enclosed in brackets, resulting in an incorrect mathematical computation.
rank by [[BB Width(50, 2) / max(50, BB Width(50, 2)) + BB Width(200, 2) / max(200, BB Width(200, 2))] / 2] ascending
Is there any way to rank the results by the average of the two indicators above?
Thank you,
Alex
0
Comments
this works (passes syntax, gives results that look valid):
rank by [BB Width(50, 2)/[max(50, BB Width(50, 2))]] ascending
and this works:
rank by [BB Width(200, 2)/[max(200, BB Width(200, 2))]] ascending
but this (both statements combined with brackets and the addition operator -> [ ... + ... ] ) does not:
rank by [ [BB Width(50, 2)/[max(50, BB Width(50, 2))]]+[BB Width(200, 2)/[max(200, BB Width(200, 2))]] ] ascending
and the error message is :
" Invalid text after RANK BY : + "
apparently meaning brackets are correct but the addition operator can't be used with RANK BY. Adding spaces before and after "+" doesn't help.
So, it appears the rank by functions has some limitations.
p.s. if you weren't aware, you can get errors (a red "x" on the left margin) and autofill suggestions as you type (use the space key to accept the suggestion) if you check "Advanced Editor" in the upper right corner.
Actually, it seems the addition operator can be used! Here's an example that works fine (no error in the Advanced Editor):
rank by [BB Width(50, 2) + [BB Width(200, 2)]] ascending
It won't work if I add brackets to the first BB instruction, or I remove the brackets for the second one.
I tried to add the 'max' divisions and get the average of the two, but it stopped working. Anyhow, the scan engine does appear to accept plus signs.
Alex
It seems to like one or the other of your statements but not both together.
If it's important to have the average of the two, I'd export the results into a CSV using the max 50 statement rank by. Then export the results using the max 200 rank by. Combine the two CSV files together and then do the math on it. Sort that CSV by the result and save it with a numbering system in the Name column and import the CSV into a chartlist. Properly formatted CSV import will have Column A is the Symbol. Column B is the Name. Column C is the Comment. You only really need Column A for the import but you can import other information into the Name or Comment fields in StockCharts.
So You could have AAPL in column A. 1 - 0.25 Apple in column B. The 1 is to imply the 1st ranked in the list. the - seperates the calculated "complex" rank by value of 0.25.
Sounds 'hard' or tedious, but I use this type of import structure all the time on my brokerage portfolio lists. I save column C for the % return on the position at the time of import. I put the cost information AFTER the Symbol name in column B. This allows me to look at the cost info and the current close information in Summary View pretty easily. My ranking indication is in front of the name in Column B. So it would look like this in the CSV
Col A - Column B - Col C
AAPL - A001 Apple 99.99 - 92%
I use a Letter in the ranking so that I can do subsorting in Summary View without messing up the "permanent" sort order.
Still, I am wondering if we shouldn't report this to the StockCharts programming team because this looks like a SC bug to me.
The 'rank by' instruction is unique, it has no quick alternatives and it is an important feature of the scan engine, maybe even critical for certain scripts. It shows you the top stock selections using your own scan criteria (in this case, volatility contraction on multiple timeframes).
My point is that it must work well and without any major constraints! I doubt it will take too much programming time to have it fixed, and once this is done, it will save precious time for the website users.
What do you think?
I'd put a suggestion to Support and see what they say. It never hurts. I also suggest that you copy your request, before you submit it, then submit it and copy it to the Suggestions to StockCharts thread here on this forum so that others may make a similar suggestion or request if so inclined. That was the idea behind that thread. I make a suggestion then posted it on the forum a week or two ago. Like I said, it never hurts to let them know what you want. And, if you don't, they'll never know what you want.
https://scan.stockcharts.com/discussion/1721/suggestions-to-stockcharts#latest