Re: Fun with ThinkScript May 28, 2015 11:42PM |
Registered: 8 years ago Posts: 2 |
Re: Fun with ThinkScript May 29, 2015 12:03AM |
Registered: 9 years ago Posts: 14 |
Re: Fun with ThinkScript May 29, 2015 07:00AM |
Registered: 10 years ago Posts: 615 |
Quote
SKumar
Thank you for the regression channel angle script. That's awesome. Is there a way to apply the angle on MACD to distinguish good crossovers from bad ones as I requested before?
declare lower; input fastLength = 12; input slowLength = 26; input MACDLength = 9; input averageType = AverageType.EXPONENTIAL; plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength); plot Avg = MovingAverage(averageType, Value, MACDLength); plot Diff = Value - Avg; plot ZeroLine = 0; Value.SetDefaultColor(GetColor(1)); Avg.SetDefaultColor(GetColor(8)); Diff.SetDefaultColor(GetColor(5)); Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Diff.SetLineWeight(3); Diff.DefineColor("Positive and Up", Color.GREEN); Diff.DefineColor("Positive and Down", Color.DARK_GREEN); Diff.DefineColor("Negative and Down", Color.RED); Diff.DefineColor("Negative and Up", Color.DARK_RED); Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.Color("Positive and Up" ) else Diff.Color("Positive and Down" ) else if Diff < Diff[1] then Diff.Color("Negative and Down" ) else Diff.Color("Negative and Up" )); ZeroLine.SetDefaultColor(GetColor(0)); # ----- apply linear regression slope to macd line ----- def LRlength = 3; def angle = ATan(LinearRegressionSlope(Value, LRlength)) * 180 / Double.Pi; AddLabel(yes, "macd slope angle: " + round(angle,1), Color.WHITE);
Quote
SKumar
A tip has been added in your tip jar
Re: Fun with ThinkScript May 29, 2015 07:40AM |
Registered: 8 years ago Posts: 6 |
Re: Fun with ThinkScript May 29, 2015 02:57PM |
Registered: 8 years ago Posts: 1 |
Re: Fun with ThinkScript May 29, 2015 05:37PM |
Registered: 8 years ago Posts: 8 |
Re: Fun with ThinkScript May 29, 2015 08:06PM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript May 30, 2015 08:16PM |
Registered: 9 years ago Posts: 67 |
# scan for downwardly sloping channels # manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = angle < 0 and absValue(angle) >= minAngle;The Scan criteria look like this:
Re: Fun with ThinkScript May 30, 2015 11:18PM |
Registered: 10 years ago Posts: 615 |
Quote
netarchitech
If time and circumstances permit, I look forward to your reply to this issue. Thanks again!
Re: Fun with ThinkScript May 31, 2015 05:07AM |
Registered: 10 years ago Posts: 615 |
Quote
RTAVERA
Hi Robert,
This is a great tool, but I would like to add labels next to the label date with the expected move (GetMarketMakerMove) before earnings and the actual % and $ change after earnings. Also the implied volatility drop after ER and finally the average price movement after X number of days after ER.
I know it's not easy, I'm in the process but I realized have a lot to learn with scrips.
If you can add those indicators I wuold be glad to buy the whole package.
Thank you.
Re: Fun with ThinkScript May 31, 2015 05:14AM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript May 31, 2015 06:11AM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript May 31, 2015 07:41PM |
Registered: 9 years ago Posts: 67 |
Quote
Robert
If the goal it to plot a 100 period linear regression channel, then LinearRegCH100 is not study to use. That study does a linear regression over the entire length of the chart. The 100 in that study doesn't refer to a channel with a length of 100 bars, but to setting the width of the channel to 100% of maximum.
Instead, use the LinearRegChVar study...
# scan for upwardly sloping channels # manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = angle >= minAngle;
# scan for downwardly sloping channels # manually change the input values as needed before pasting into the scan tool # length of linear regression channel input length = 100; # filter out all channels with an angle that is less than the minimum specified angle input minAngle = 20; # --- do not change anything below this line --- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; plot signal = angle < 0 and absValue(angle) >= minAngle;Is it possible to have the input "length" have a value interpreted as a percentage (default value = 100%) instead of a period (default value = 100 bars)?
Re: Fun with ThinkScript June 01, 2015 04:34AM |
Registered: 10 years ago Posts: 615 |
Quote
netarchitech
Is it possible to have the input "length" have a value interpreted as a percentage (default value = 100%) instead of a period (default value = 100 bars)?
script LR { input y = close; input n = 20; input x = 1; def l = 3 * n; plot a = (n * Sum(x * y, l) - Sum(x, l) * Sum(y, l) ) / ( n * Sum(Sqr(x), l) - Sqr(Sum(x, l))); plot b = (Sum(Sqr(x), l) * Sum(y, l) - Sum(x, l) * Sum(x * y, l) ) / ( n * Sum(Sqr(x), l) - Sqr(Sum(x, l))); plot lr = a * x + b; } input length = 100; # determine last bar, not counting extended area def LastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); # determine when the LR channel begins def LRbegin = if BarNumber() == (LastBar - length + 1) then BarNumber() else LRbegin[1]; def modY = if !LRbegin then 0 else close; def modX = if !LRbegin then 0 else BarNumber(); # calculate the linear regression values def lr = lr(modY, length, modX).lr; def a = lr(modY, length, modX).a; def b = lr(modY, length, modX).b; # plot the linear regression channel def transpose = BarNumber() - LastBar; plot linReg = if !modX then Double.NaN else modX * GetValue(a, transpose) + GetValue(b, transpose); linReg.SetDefaultColor(Color.WHITE); linReg.SetStyle(Curve.MEDIUM_DASH); def dist = HighestAll(AbsValue(modY - linReg)); plot LRupper = linReg + dist; LRupper.SetDefaultColor(Color.CYAN); plot LRlower = linReg - dist; LRlower.SetDefaultColor(Color.CYAN); # ----- find the slope angle ----- def angle = ATan(LinearRegressionSlope(length = length)) * 180 / Double.Pi; AddLabel(yes, "slope angle: " + Round(angle, 2), Color.WHITE);
Re: Fun with ThinkScript June 01, 2015 04:50AM |
Registered: 10 years ago Posts: 615 |
Quote
ht65
I am looking for a scan that will look for all stocks breaking out above the highest RSI
input length = 14; def rsi = rsi(length).rsi; plot signal = rsi == highestall(rsi);
Quote
I would like to be able to define the RSI as well with values of 69.10 and 30.90
input length = 14; input threshold = 69.10 def rsi = rsi(length).rsi; plot signal = rsi >= threshold;
Re: Fun with ThinkScript June 01, 2015 05:53AM |
Registered: 9 years ago Posts: 12 |
Re: Fun with ThinkScript June 01, 2015 06:05AM |
Registered: 10 years ago Posts: 615 |
Quote
ht65
am I to assume the first code you provided can be used as a scan and then set the period to week? TOS returns some inaccurate results.. for instance [screencast.com]
Quote
also how am i to use the second snippet of code with the 69.10? as an indicator or what?
Re: Fun with ThinkScript June 01, 2015 09:24AM |
Registered: 8 years ago Posts: 6 |
Re: Fun with ThinkScript June 01, 2015 09:53AM |
Registered: 10 years ago Posts: 615 |
Quote
bijinkei
Do you know if there's a way to turn a recursive variable into a non-recursive one? Or some way to get around using a recursive. I'm trying to set a study alert to notify me of when a new higher/lower fractal is formed and apparently recursive variables are disabled in study alerts.
def OpenRangeMinutes = 30; def MarketOpenTime = 0930; input ShowTodayOnly = yes; def Today = if GetDay() == GetLastDay() then 1 else 0; def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0; def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1]; def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1]; plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN; OpenRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeHigh.SetDefaultColor(Color.YELLOW); plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN; OpenRangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeLow.SetDefaultColor(Color.YELLOW);
input agg = AggregationPeriod.Thirty_MIN; input ShowTodayOnly = yes; def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay(); def lookback = SecondsFromTime(0930) / GetAggregationPeriod() * 1000; plot ORh = if !today then double.nan else GetValue(high(period = agg), lookback); ORh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); ORh.SetDefaultColor(Color.YELLOW); ORh.SetLineWeight(2); plot ORl = if !today then double.nan else GetValue(low(period = agg), lookback); ORl.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); ORl.SetDefaultColor(Color.YELLOW); ORl.SetLineWeight(2);
Re: Fun with ThinkScript June 01, 2015 10:43AM |
Registered: 8 years ago Posts: 6 |
input length = 34; input lookback = 2; input lookforward = 1; def HP = GetValue(high,0) > GetValue(high, 1, lookback); def HF = GetValue(high,0) > GetValue(high, -lookforward); def HPc = if HP then 1 else if GetValue(high,0) == GetValue(high, 1) and GetValue(HPc, 1) then GetValue(HPc,1) else 0; def peak = if HPc and HF then GetValue(high,0) else GetValue(peak, 1); def LP = GetValue(low,0) < GetValue(low, 1, lookback); def LF = GetValue(low,0) < GetValue(low, -lookforward); def LPc = if LP then 1 else if GetValue(low,0) == GetValue(low, 1) and GetValue(LPc, 1) then GetValue(LPC, 1) else 0; def trough = if LPc and LF then GetValue(low,0) else GetValue(trough, 1); plot upperband = Highest(GetValue(peak, 1), length); plot lowerband = Lowest(GetValue(trough, 1), length);
Re: Fun with ThinkScript June 01, 2015 10:51AM |
Registered: 10 years ago Posts: 615 |
Quote
bijinkei
I tried replacing a bunch of things with GetValue and while the plot works, the study alerts still give me that rec usage not allowed message. I think the issue is that I'm still using < and >?
Re: Fun with ThinkScript June 01, 2015 10:55AM |
Registered: 8 years ago Posts: 6 |
input length = 55; input lookback = 2; input lookforward = 1; def HP = high > Highest(high[1], lookback); def HF = high > Highest(high[-lookforward], lookforward); def HPc = if HP then 1 else if high == high[1] and HPc[1] then HPc[1] else 0; def peak = if HPc and HF then high else peak[1]; def LP = low < Lowest(low[1], lookback); def LF = low < Lowest(low[-lookforward], lookforward); def LPc = if LP then 1 else if low == low[1] and LPc[1] then LPc[1] else 0; def trough = if LPc and LF then low else trough[1]; plot upperband = Highest(peak[1], length); plot lowerband = Lowest(trough[1], length);
Re: Fun with ThinkScript June 01, 2015 02:19PM |
Registered: 10 years ago Posts: 615 |
input length = 55; input lookback = 2; input lookforward = 1; def HP = high > Highest(high[1], lookback); def HF = high > Highest(high[-lookforward], lookforward); def HPc = HP or (hp[1] and high == high[1]) or (hp[2] and high == high[1] and high[1] == high[2]); def peak = if HPc and HF then high else 0; def upperband = Highest(peak[1], length); plot alert = close crosses above upperband;
Re: Fun with ThinkScript June 02, 2015 08:08AM |
Registered: 9 years ago Posts: 67 |
Re: Fun with ThinkScript June 02, 2015 10:18AM |
Registered: 8 years ago Posts: 6 |
Re: Fun with ThinkScript June 03, 2015 09:37AM |
Registered: 10 years ago Posts: 615 |
Quote
netarchitech
Off topic...what screen capture utility are you are currently using? I'm guessing Techsmith's SnagIt. If so, would you recommend it?
Quote
netarchittech
As I review the continuing evolution of this issue, I've come to realize I've always been looking for:
1. linear regression (channel) "length" = 100% (just like LinearRegCh100)
# Scan for positive slopes # manually change minSlopeAngle before scanning input minSlopeAngle = 15; # ---- don't change anything below this line ---- def slope = LinearRegressionSlope(length = 252); def angle = ATan(slope) * 180 / Double.Pi; plot signal = angle > 0 and angle >= minSlopeAngle;
# Scan for positive slopes # manually change minSlopeAngle before scanning input minSlopeAngle = 15; # ---- don't change anything below this line ---- def slope = LinearRegressionSlope(length = 252); def angle = ATan(slope) * 180 / Double.Pi; plot signal = angle < 0 and AbsValue(angle) >= minSlopeAngle;
plot angle = round(atan(linearRegressionSlope(length = 252))*180/double.pi);
Re: Script Question June 03, 2015 12:48PM |
Registered: 8 years ago Posts: 59 |
Re: Script Question June 03, 2015 01:06PM |
Registered: 10 years ago Posts: 615 |
Quote
Ralph53
I plot this script as a line on a chart;
# 5 Cents Below Open #
def OpenNeg5 = (open("period" = AggregationPeriod.DAY) -.05);
plot condition = OpenNeg5;
Does anyone know of a way to re-script it so the line starts 10 candles behind the current candle? Thanks.
# 5 Cents Below Open # def OpenNeg5 = (open("period" = AggregationPeriod.DAY) - .05); def lastbar = HighestAll(if IsNaN(close) then 0 else BarNumber()); plot condition = if BarNumber() < lastbar - 10 then Double.NaN else GetValue(OpenNeg5, BarNumber() - lastbar);
Re: Fun with ThinkScript June 04, 2015 10:27PM |
Registered: 8 years ago Posts: 59 |
Re: Fun with ThinkScript June 04, 2015 10:53PM |
Registered: 9 years ago Posts: 67 |
Quote
Robert
Quote
netarchitech
Off topic...what screen capture utility are you are currently using? I'm guessing Techsmith's SnagIt. If so, would you recommend it?
You've a good eye for detail. That is exactly the program I am using. Hardly a day goes by that I don't use it. I also like to use ScreenSnapzProX.
Yes, I would recommend SnagIt. I like how easily annotations can be added to a screenshot. A wonderful bonus, for me, is that each annotation is created on a separate layer within the SnagIt editor so they can be edited / deleted later.