StockFetcher Forums · Filter Exchange · 'Band' scripting in SF<< >>Post Follow-up
glgene
534 posts
msg #97646
Ignore glgene
11/28/2010 1:12:48 AM

Read an article in the Dec. 2010 issue of 'Technical Analysis of Stocks & Commodities.' Article is titled, "Less Stress With the JM Internal Band." JM is simply the initials of a person the band was named after.

Talks about creating a 15-day SMA of a stock, offset by 2% upward and 2% downward bands from the 15-day MA. You go long when the close breaks above the upper band, and go short when it breaks below the lower band. You can then use a break above (below) the 15-day SMA as a sell (buy) stop..... or use any other exit strategy you normally employ.

Looked up the subject of 'Bands' in the SF Manual, but none exist (other than Bollinger). Is there a more complete, updated SF Manual available?

Question: Can anybody here show me the script to build 2% upper and 2% lower bands on the 15-day MA of a stock, say, SPY?

Much appreciated!

Gene



glgene
534 posts
msg #97648
Ignore glgene
11/28/2010 8:06:54 AM

Let's try this for my initial attempt, using the 2% 'Band' rule mentioned above. That would be GO LONG when the Close goes above its MA(15) at 102.00% (far right-hand column), and GO SHORT when Close goes below MA(15) at 98.00%.

No stop loss here (yet). ???

Question: How do I modify the script so the Upper and Lower 2% bands are drawn overlapping the Price and MA(15) charts ???

Fetcher [
symlist(spy,qqqq,iwm,vti)
set {m, ma(15)}
set{u,m*1.02}
set{l,m*.98}
add column separator
add column u{Up2%Band}
add column ma(15){ma(15)}
add column l{dn2%Band}
add column separator
set{d,close/m}
set{d1,d*100}
add column d1{Close-vs.-ma15[%]}
draw ma(15)
draw u
draw m
draw l
draw d1
]

Kevin_in_GA
4,536 posts
msg #97649
Ignore Kevin_in_GA
11/28/2010 8:37:25 AM

Fetcher[

set{upperband, MA(15) * 1.02}
set{lowerband, MA(15) * 0.98}
set{go_long, count(close above upperband, 1)}
set{go_short, count(close below lowerband, 1)}
set{null, 0}

add column go_long {go long}
add column go_short {go short}

draw MA(15)
draw upperband on plot price
draw lowerband on plot price

draw go_short on plot null
draw go_long on plot null
market is S&P500
]



Kevin_in_GA
4,536 posts
msg #97650
Ignore Kevin_in_GA
11/28/2010 8:41:53 AM

The above filter is based on momentum, rather than mean reversion. Just make sure that you are careful, and recognize that statistically over short time frames (like 15 days) mean reversion is quite common.

I would probably use Bollinger Bands instead of this system, and play mean reversion when the price is greater than 2 SD from the MA.

glgene
534 posts
msg #97651
Ignore glgene
11/28/2010 10:01:49 AM

Thanks, Kevin, for BOTH replies, and so quickly. Yes, I agree, that using an MA(15) could cause a lot of trades.

I will add your remarks to my "What I learned" memory bank. My bank needs a lot of filling!

Your most recent comment....."play mean reversion when the price is greater than 2 SD from the MA." I'll have to work on that one. But first, I've got to study page 98 in the SF Manual on Standard Deviation. There are no examples there that reference the number of standard deviations.

Your comment (without scripting) tells me to look at somethng like the following:

Close > than 2 standard deviations above ma(15)

Is that acceptable SF scripting language?

Gene

Kevin_in_GA
4,536 posts
msg #97657
Ignore Kevin_in_GA
modified
11/28/2010 11:33:28 AM

Not really. Because of the way Bollinger Bands are calculated, you only need to say

Fetcher[

set{go_short, count(close above upper Bollinger Band(15,2), 1)}
set{go_long, count(close below lower Bollinger Band(15,2), 1)}
set{null, 0}

set{trigger, go_long + go_short}

draw go_short on plot null
draw go_long on plot null
draw MA(15)
Draw Bollinger Bands(15,2)

add column go_long {go long}
add column go_short {go short}

market is S&P500
trigger above 0.5

]



Here I have also added a line creating a user variable called trigger - since the majority of stocks usually stay inside their BB, the trigger variable being greater than 0.5 (meaning that the stock is either ABOVE the upper BB or BELOW the lower BB) filters these down to only those that are tradable for today.

I also use the S&P500 as the market since these are all highly liquid stocks that are unlikely to crash and burn. Only 9 hits for today.

You can remove that line and get a larger set if desired. If so, I would put some additional constraints on price (above $1) and volume traded (average volume(50) above 250000, for example).

Fetcher[

set{go_short, count(close above upper Bollinger Band(15,2), 1)}
set{go_long, count(close below lower Bollinger Band(15,2), 1)}
set{null, 0}

set{trigger, go_long + go_short}

draw go_short on plot null
draw go_long on plot null
draw MA(15)
Draw Bollinger Bands(15,2)

add column go_long {go long}
add column go_short {go short}

close above 1
average volume(50) above 250000
trigger above 0.5

]



This gives you 97 matches.

Remember that these values (15, 2) are arbitrary ... you really need to back-test or optimize against a large set of variables to find a set that is consistently profitable and robust.

glgene
534 posts
msg #97661
Ignore glgene
11/28/2010 4:40:33 PM

Kevin,

Your generosity of time and talent here are much appreciated. I will go over your scripts in detail to fully understand them. If (if?)I have any questions, I'll come back.

Thanks!

Gene

StockFetcher Forums · Filter Exchange · 'Band' scripting in SF<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2016 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus