# Jan 2022 my mucking about with code from mashume
# https://usethinkscript.com/threads/dr-wishs-black-green-dot-indicator-for-thinkorswim.8110/
# to include stuff from
# https://wishingwealthblog.com/2018/03/green-dot-strategy-defined/
# https://aaiidcmetro.com/slides/(2019-07-13)wish.pdf
# https://wishingwealthblog.com/glossary/
# Dr Wish's Black & Green Dot Indicator For ThinkOrSwim
# @Joshua 9/2021
# with green dots by mashume
# from TC2000 code found here: https://wishingwealthblog.com/2021/06/follow-on-to-traderlion-conference-this-wednesdays-long-island-talk-examples-of-black-dot-signals-gmi6-of-6/
def black =
Sum(StochasticFull(10,1) <= 25, 3) >= Yes
and close > close[1]
and (close > Average(close,30)
or
close > expAverage(close,21)
)
;
# Added the Stoch suggested cross over up to occur at oversold values less than 50.
def green = if stochasticFull(10, 4)[1] < Average(StochasticFull(10, 4)[1], 4)
and stochasticFull(10, 4) < 50
AND StochasticFull(10, 4) > Average(StochasticFull(10, 4), 4) then low else double.nan;
plot bDot = if black then low else double.nan;
bDot.SetPaintingStrategy(paintingStrategy.triangles);
bDot.setLineWeight(3);
bDot.setDefaultColor(color.magenta); # instead of black to show on black chart background
plot gDot = green;
gDot.SetPaintingStrategy(paintingStrategy.POINTS);
gDot.setLineWeight(3);
gDot.setDefaultColor(color.lime); #green
# --- Finding lowest 5 day value for possible support level and entry stop out if trade fails.
# --- ToS only compares two values at a time.
def A = Min(low, low[1]);
def B = Min(low[2], low[3]);
def C = Min(A, B);
def D = Min(C, low[4]);
# -- to show only current few (5) days worth of level stop bubbles, reduce clutter
def plotThis = if getday() >= (getlastday() - 5) and GetLastYear() == GetYear() then 1 else 0;
# -- extra dots for lookback stop value
plot bDotLB = if black then D else double.nan;
bDotLB.SetPaintingStrategy(paintingStrategy.Horizontal); #triangle in case they overlap green dot
bDotLB.setLineWeight(2);
bDotLB.setDefaultColor(color.magenta); # instead of black to show on black chart background
plot gDotLB = if green then D else Double.NaN;
gDotLB.SetPaintingStrategy(paintingStrategy.Horizontal);
gDotLB.setLineWeight(2);
gDotLB.setDefaultColor(color.lime); #green
input ShowBubbles = yes;
AddChartBubble(ShowBubbles and plotThis == 1 and green, D, "Support / \n Stop: " +D+ "", Color.lime, no);
AddChartBubble(ShowBubbles and plotThis == 1 and black, D, "Support / \n Stop: " +D+ "", Color.magenta, no);
# -- 30 week avg for Dr Wish, one of the conditions for determining trend. Stock should be above.
def agg = AggregationPeriod.WEEK;
def ThirtyWeek = close(period = agg);
plot wk30sma = Average(ThirtyWeek, 30);
wk30sma.setDefaultColor(color.light_green);
AddLabel(close > wk30sma, " Above 30wk sma ", color.green);
AddLabel(close < wk30sma, " Below 30wk sma ", color.pink);
# -- moving avgs for black dot confirmation
input ShowBlkDotMA = yes;
plot BlkDtsma = if ShowBlkDotMA then Average(close, 30) else Double.nan;
plot BlkDtexp = if ShowBlkDotMA then ExpAverage(close, 21) else Double.nan;
# -- Green Line BreakOut -- Monthly timeframe, all time high not surpassed for 3 months
def aggM = AggregationPeriod.Month;
plot GLBO = High(period = aggM);
GLBO.SetPaintingStrategy(paintingStrategy.Horizontal);
GLBO.setLineWeight(2);
GLBO.setDefaultColor(color.green);
# --- Find yearly low of stock, want price to double from it's lowest price over the past year
def YearLow = Lowest(Low, 261); # 52weeks x 2day weekend = 104, 365-104 = roughly 261 trading days in a year
AddLabel(yes, " Yearly Low: " +round(YearLow, 2)+ ", x2 = " +round(YearLow, 2)* 2+ ", Current: " +round(close, 2)+ "", color.light_gray);
#-- Percentage from YearlyLow
def data = close;
def avg = YearLow;
def pct = (data/avg) - 1;
AddLabel(yes, "% change from YearLow of " +round(YearLow, 2)+ " is " + AsPercent(pct)+ "" , if pct > 1 then Color.GREEN else Color.PINK);