SPY with sdi_itsig study. |

While three segment trade signal is present the bars will darken when MACD is moving against the signal and brighten when it is moving with the signal.

Revision 1.2 Feb 28, 2012

- Previously SMP was used to select simple moving average in the moving average type input now it is SMA to conform with TOS standards.
- Previously MACD was always an EMA calculation. Now it conforms to the moving average type selection.

Here's the code:

#########################

# sdi_itsig: InvesTools SIGnals

#hint: Displays the Investools green arrow signals as a composite lower histogram study. Three red segments = three red arrows, three green segments = three green arrows. Phantom stocahstics arrows are accounted for. A color fade during a three arrow era represents the MACD fading back towards the zero line. A dot represents a MACD fade occuring during a stochastics over-bought/sold era. Rev:1.2 http://www.smalldoginvestor.com

# rev: 1.2 2/27/2012:

# -Previously SMP was used to select simple moving average in the moving

# average type input now it is SMA to conform with TOS standards.

# -Previously MACD was always an EMA calculation. Now it conforms to the

# moving average type selection.

#

# author: allen everhart 10/8/2009

#

# 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;

# stochastics inputs
input Sto_over_bought = 75;

#hint Sto_over_bought: % level that defines over-bought. Any Full-D value above over-bought is an investool green arrow. Full-D is the slower varying line in the stochastics study.

input Sto_over_sold = 25;

#hint Sto_over_sold: % level that defines over-sold. Any Full-D value below over-sold is an investool red arrow. Full-D is the slower varying line in the stochastics study.

input sto_KPeriod = 14;

#hint sto_KPeriod: bars used to average the stochastics calculation to produce Fast-K, an intermediate calculation to Full-K and Full-D.

input sto_DPeriod = 5;

#hint sto_DPeriod: bars used to average Full-K to produce Full-D. Full-D is the slower varying line displayed in stochastics studies. Full-D overbought or oversold produces an Investools green or red arrow, resp. In midrange, Full-D rising or falling produces an Investools phantom green or phantom red arrow, resp.

def sto_priceH = high;

def sto_priceL = low;

def sto_priceC = close;

input sto_slowing_period = 3;

#hint sto_slowing_period: bars used to average Fast-K to produce Full-K. Full-K is the more swiftly varying line displayed in stochastics studies.

#input sto_smoothingType = 1;

input MACDFastLength = 8;
#hint MACDfastLength: bars used to produce the more swiftly varying average in MACD studies. The MACD value is the difference between the fast and slow moving averages.

input MACDSlowLength = 17;

#hint MACDSlowLength: bars used to produce the less swiftly varying average in MACD studies. The MACD value is the difference between the fast and slow moving averages.

input MACDLength = 9;

#hint MACDLength: bars used to produce MACD signal line, the moving average of the MACD value. A MACD value greater or less than the signal line produces an Investools green or red arrow, resp.

input MvgAvgLength = 30 ;
#hint MvgAvgLength: bars used to produce the Investools moving average. Underlying price closes above or below this moving average produce and Investools green or red arrow, resp.

input MvgAvgType = { default SMA, EMA };

#hint MvgAvgType: Selects simple or exponential moving average calculations for all the composite studies.

def SimpleMvgAvgOnOrOff =

if mvgAvgType == mvgAvgType.SMA then

1

else

0

; # 0 = exponential

def sto_smoothingType = SimpleMvgAvgOnOrOff ;

def c1 = sto_priceC - Lowest(sto_priceL, sto_KPeriod);

def c2 = Highest(sto_priceH, sto_KPeriod) - Lowest(sto_priceL, sto_KPeriod);

def FastK = c1 / c2 * 100;

def FullK =
if sto_smoothingType == 1 then

Average(FastK, sto_slowing_period)

else

ExpAverage(FastK, sto_slowing_period);

def FullD =
if sto_smoothingType == 1 then

Average(FullK, sto_DPeriod)

else

ExpAverage(FullK, sto_DPeriod);

# moving average
def MAprice =

if simpleMvgAvgOnOrOff == 1 then

simpleMovingAvg( close, mvgAvgLength)

else

ExpAverage( close, mvgAvgLength);

if simpleMvgAvgOnOrOff == 1 then

MACD( MACDfastLength, MACDslowLength, MACDLength, "SMA").Diff

else

MACD( MACDfastLength, MACDslowLength, MACDLength, "EMA").Diff

;

#plot md = macddiff;

# macd stuff

rec MACDarrow =

if MACDdiff == 0 then MACDarrow[1]

else if MACDdiff > 0 then 1

else -1 ;

#plot MCDdiag = MACDarrow ;

# red/green arrow stuff

rec MAarrow =

if close == MAprice then MAarrow[1]

else if close > MAprice then 1

else -1 ;

#plot MAdiag = MAarrow ;

rec StochsArrow =
if FULLD > sto_over_bought then 1

else if FULLD >= sto_over_sold and FULLD > FULLD[1] then 1

else if FULLD >= sto_over_sold and FULLD == FULLD[1] then

StochsArrow[1]

else -1 ;

#plot StochsDiag = StochsArrow ;

def arrowCount = MACDarrow + StochsArrow + MAarrow ;
def macdStoCount = MACDarrow + STOCHSArrow;

#plot mcdsto = macdStoCount;

plot up =

if arrowCount == 3 then 3

else if arrowCount == 1 then 2

else if arrowCount == -1 then 1

else double.NaN

;

up.SetPaintingStrategy(paintingStrategy.HISTOGRAM);

up.SetDefaultColor(color.GREEN);

up.SetLineWeight(4);

up.AssignValueColor(

if arrowCount == 3 && MACDdiff >= MACDdiff[1] then color.GREEN

else color.DARK_GREEN

);

plot dn =
if arrowCount == -3 then -3

else if arrowCount == -1 then -2

else if arrowCount == 1 then -1

else double.NaN

;

dn.SetPaintingStrategy(paintingStrategy.HISTOGRAM);

dn.SetDefaultColor(color.RED);

dn.SetLineWeight(4);

dn.AssignValueColor(

if arrowCount == -3 && MACDdiff <= MACDdiff[1] then coLor.RED

else color.DARK_RED

);

plot macd_rv =

if MACDdiff[2] < MACDdiff[1] && MACDdiff[1] > MACDdiff && MACDdiff[1] > 0 && FULLD[1] > sto_over_bought then

up+0.5

else if MACDdiff[2] > MACDdiff[1] && MACDdiff[1] < MACDdiff && MACDdiff[1] < 0 && FULLD[1] < sto_over_sold then

dn-0.5

else

double.NaN

;

macd_rv.hideBubble();

macd_rv.setpaintingStrategy( paintingStrategy.POINTS ) ;

macd_rv.setDefaultColor( COLor.DARK_GRAY) ;

macd_rv.setLineWeight(5) ;

macd_rv.AssignValueColor(

if isNaN( macd_rv ) then color.DARK_GRAY

else if MACDdiff[1] > 0 then color.RED

else if MACDdiff[1] < 0 then color.GREEN

else color.DARK_GRAY

);

plot z = 0 ;

z.SetDefaultColor( color.DARK_GRAY );

z.setLineWeight(3);

plot p3 = 3 ;
p3.setDefaultColor( color.DARK_GRAY);

plot p2 = 2 ;

p2.SetDefaultColor( color.DARK_GRAY);

plot p1 = 1 ;

p1.SetDefaultColor( color.DARK_GRAY);

plot m3 = -3 ;
m3.setdefaultColor( color.DARK_GRAY);

plot m2 = -2 ;

m2.SetDefaultColor( color.DARK_GRAY);

plot m1 = -1 ;

m1.SetDefaultColor( color.DARK_GRAY);

Thank for the script on 3 Green & 3 Red Arrows. It works great.but how can I chenge it to work on the scan tab? (in Thinkorswim)

ReplyDeleteThanks

Ron

Great question! TOS does not allow one to use sdi_itsig directly in a custom scan query - apparently its too complex. It is necessary to break out the internals of itsig to do this and I will show how to do this in a new blog entry by this weekend.

ReplyDeleteHi Allen is there a way you can post a version of this indicator only with the TTM WAVE instead of using the macd ?The dots would identify where the TTM WAVE value has rolled over (i.e. started decreasing)(fail to make new high on histogram) ?thanks I don't know if this would take a lot of time or not to just replace the macd code with the TTM WAVE. I have notice good reversal points on TTM WAVE histogram .

ReplyDeleteI'd be happy to provide a quote for this customization. Contact me at support@smallDogInvestor.com

Delete