Sunday, September 14, 2014

thinkscript included: sdi_consbar - display consecutive up and down count

a while back when i was playing with altucher's strategy i wrote a little study called consbar, or consecutive bar, to help me validate the signals from altucher's strategy. recently, people have been writing to me to develop a scan that finds ttm_scalper_alert signals. this ttm_scalper_alert looks for 3 consecutively higher/lower closes to throw an indicator on the chart. the problem is that ttm_scalper_alert backdates the indication signal to the start of the run, which makes it confusing to scan for (hint: use the clause 'within 3 bars') because the indication never appears on the currently forming bar. now, maybe you want to investigate how the market behaves after other consecutive runs as well, say 4 or 5. it is in this spirit that maybe you will find my consbar to be useful. so here's the image followed by the code:
sdi_consbar showing runs of consecutively higher or lower closes on spy
################################
# sdi_consbar: display consecutive bar count
#hint: displays the count of consecutively up days and consecutively down days.  rev: 1.00 http://www.smallDogInvestor.com 
# author: allen everhart
# date: 14sep2014
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale. 
# Help me get the word out about my blog by keeping this header
# in place. 
declare lower;
def bars_up = if close > close[1] then bars_up[1] + 1 else 0;
def bars_down = if close < close[1] then bars_down[1] + 1 else 0;

plot up = bars_up;
plot dn = bars_down ;

up.setDefaultColor( COlor.DARK_GREEN );
dn.setDefaultColor( Color.RED ) ;
up.hideBubble();
dn.hideBubble();