Re: Fun with ThinkScript March 27, 2017 08:13PM |
Registered: 11 years ago Posts: 106 |
Horizontal line from a given average at specified time March 29, 2017 03:38PM |
Registered: 7 years ago Posts: 2 |
Re: Horizontal line from a given average at specified time April 01, 2017 09:16AM |
Registered: 7 years ago Posts: 63 |
Quote
brushyourteeth
Is it possible to draw a horizontal line from the simple moving average (or any other indicator), at a specific time after the open, (say 10:00am), and have the line hold that value and draw out the remainder of the day?
# Plot longer moving average support lines def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0); def mostRecentClose = HighestAll(if BarNumber() == lastBar then close else 0); def barNumber = BarNumber(); def barCount = HighestAll(If(IsNaN(close), 0, barNumber)); input shtAvg = 50; input medAvg = 100; input lngAvg = 200; input avgType = {default "simple", "exponential"}; def avg1; def avg2; def avg3; switch (avgType) { case "simple": avg1 = Average(close, shtAvg); avg2 = Average(close, medAvg); avg3 = Average(close, lngAvg); case "exponential": avg1 = ExpAverage(close, shtAvg); avg2 = ExpAverage(close, medAvg); avg3 = ExpAverage(close, lngAvg); } input proximity = 10; #ref 0.5 = 1/2% def value1 = GetValue(avg1, BarNumber() - HighestAll(lastBar)); def value2 = GetValue(avg2, BarNumber() - HighestAll(lastBar)); def value3 = GetValue(avg3, BarNumber() - HighestAll(lastBar)); def inRange1 = mostRecentClose > (value1 * (1 - proximity / 100)) and mostRecentClose < (value1 * (1 + proximity / 100)); def inRange2 = mostRecentClose > (value2 * (1 - proximity / 100)) and mostRecentClose < (value2 * (1 + proximity / 100)); def inRange3 = mostRecentClose > (value3 * (1 - proximity / 100)) and mostRecentClose < (value3 * (1 + proximity / 100)); def avg1Line = if barNumber == 1 then Double.NaN else if barNumber == barCount then avg1 else if barNumber == barCount then Double.NaN else avg1Line[1]; def avg2Line = if barNumber == 1 then Double.NaN else if barNumber == barCount then avg2 else if barNumber == barCount then Double.NaN else avg2Line[1]; def avg3Line = if barNumber == 1 then Double.NaN else if barNumber == barCount then avg3 else if barNumber == barCount then Double.NaN else avg3Line[1]; plot sandline1 = avg1Line; sandline1.AssignValueColor(globalColor("sand" )); sandline1.SetLineWeight(1); sandline1.SetHiding(!inRange1); AddChartBubble(yes, if inRange1 and BarNumber() == HighestAll(Lastbar+3) then sandline1 else double.nan, shtAvg + (if avgType == avgType.simple then "sma" else "ema" ), globalColor("sand" ), 0); plot sandline2 = avg2Line; sandline2.AssignValueColor(globalColor("sand" )); sandline2.SetLineWeight(1); sandline2.SetHiding(!inRange2); AddChartBubble(yes, if inRange2 and BarNumber() == HighestAll(Lastbar+3) then sandline2 else double.nan, medAvg + (if avgType == avgType.simple then "sma" else "ema" ), globalColor("sand" ), 0); plot sandline3 = avg3Line; sandline3.AssignValueColor(globalColor("sand" )); sandline3.SetLineWeight(1); sandline3.SetHiding(!inRange3); AddChartBubble(yes, if inRange3 and BarNumber() == HighestAll(Lastbar+3) then sandline3 else double.nan, lngAvg + (if avgType == avgType.simple then "sma" else "ema" ), globalColor("sand" ), 0); AddLabel(yes, "proximity: " + proximity + "%", color.white); AddLabel(yes, shtAvg + (if avgType == avgType.simple then "sma: " else "ema: " ) + round(avg1,2), globalColor("sand" )); #for reference only AddLabel(yes, medAvg + (if avgType == avgType.simple then "sma: " else "ema: " ) + round(avg2,2), globalColor("sand" )); #for reference only AddLabel(yes, lngAvg + (if avgType == avgType.simple then "sma: " else "ema: " ) + round(avg3,2), globalColor("sand" )); #for reference only DefineGlobalColor("sand", CreateColor(255,204,102)); #sand
Re: Fun with ThinkScript April 01, 2017 09:55AM |
Registered: 7 years ago Posts: 2 |
Re: Fun with ThinkScript April 03, 2017 02:34AM |
Registered: 7 years ago Posts: 126 |
Re: Fun with ThinkScript April 03, 2017 04:33AM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript April 04, 2017 04:08AM |
Registered: 7 years ago Posts: 63 |
# define what is considered to be "in range" of the peak
input proximity = 1.0;
def inRangeUp = mostRecentClose > (PeakValue * (1 - proximity / 100)) and mostRecentClose < (PeakValue * (1 + proximity / 100));
plot peakline = peakvalue;
peakline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peakline.DefineColor("Passive", Color.Dark_Green);
peakline.DefineColor("Active", Color.Light_Green);
peakline.AssignValueColor(if inRangeUp then peakline.Color("Active" ) else peakline.Color("Passive" ));
# extend the current peak line to the right edge of the chart
def countp = if IsNaN(peak) and !IsNaN(peak[1]) then 1 else countp[1] + 1;
plot peakext = if IsNaN(peak) then GetValue(peakline, countp) else Double.NaN;
peakext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
peakext.DefineColor("Passive", Color.Dark_Green);
peakext.DefineColor("Active", Color.Light_Green);
peakext.AssignValueColor(if inRangeUp then peakext.Color("Active" ) else peakext.Color("Passive" )); # <-- the one not working
# continue the previous peak as a dashed line
input proximity2 = 0.5;
def prevInRangeUp = mostRecentClose > (prevPeakValue * (1 - proximity2 / 100)) and mostRecentClose < (prevPeakValue * (1 + proximity2 / 100));
plot prevPeakExt = if BarNumber() >= HighestAll(peakBar) - 1 then prevPeakValue else Double.NaN;
prevPeakExt.SetPaintingStrategy(PaintingStrategy.DASHES);
prevPeakExt.DefineColor("Passive", Color.Dark_Green);
prevPeakExt.DefineColor("Active", Color.Light_Green);
prevPeakExt.AssignValueColor(if prevInRangeUp then prevPeakExt.Color("Active" ) else prevPeakExt.Color("Passive" ));
Re: Fun with ThinkScript April 04, 2017 08:01PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript April 07, 2017 12:41AM |
Registered: 7 years ago Posts: 1 |
AssignValueColorcolor on ToS MOBILE.
declare lower; declare zerobase; def diff = close - close[1]; plot Vol = volume; Vol.AssignValueColor(if diff > 0 then Color.UPTICK else Color.DOWNTICK); Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Re: Fun with ThinkScript April 07, 2017 10:03AM |
Registered: 8 years ago Posts: 54 |
Re: Fun with ThinkScript April 09, 2017 11:58AM |
Registered: 10 years ago Posts: 464 |
Re: Fun with ThinkScript April 10, 2017 07:55AM |
Registered: 10 years ago Posts: 464 |
Re: Fun with ThinkScript April 16, 2017 12:05PM |
Registered: 9 years ago Posts: 53 |
A Bar that Close at the Top 25% of Its Range April 18, 2017 09:55AM |
Registered: 7 years ago Posts: 2 |
Re: Fun with ThinkScript April 20, 2017 01:01PM |
Registered: 7 years ago Posts: 3 |
Re: Fun with ThinkScript April 22, 2017 04:11AM |
Registered: 9 years ago Posts: 60 |
Re: Fun with ThinkScript April 22, 2017 01:14PM |
Registered: 7 years ago Posts: 59 |
Re: Fun with ThinkScript April 24, 2017 01:00PM |
Registered: 9 years ago Posts: 38 |
Re: Fun with ThinkScript April 24, 2017 01:38PM |
Registered: 8 years ago Posts: 34 |
Re: Fun with ThinkScript April 30, 2017 09:31AM |
Registered: 9 years ago Posts: 53 |
Re: Fun with ThinkScript May 05, 2017 02:36PM |
Registered: 6 years ago Posts: 3 |
Re: Fun with ThinkScript May 08, 2017 09:12PM |
Registered: 8 years ago Posts: 34 |
Re: Fun with ThinkScript May 10, 2017 09:39AM |
Registered: 6 years ago Posts: 6 |
Re: Fun with ThinkScript May 10, 2017 11:50AM |
Registered: 6 years ago Posts: 3 |
Re: Fun with ThinkScript May 10, 2017 06:27PM |
Registered: 6 years ago Posts: 6 |
Re: Fun with ThinkScript May 10, 2017 07:29PM |
Registered: 6 years ago Posts: 3 |
Re: Fun with ThinkScript May 11, 2017 12:20PM |
Registered: 6 years ago Posts: 1 |
Re: Fun with ThinkScript May 11, 2017 01:30PM |
Registered: 6 years ago Posts: 6 |
Re: Fun with ThinkScript May 11, 2017 02:43PM |
Registered: 6 years ago Posts: 6 |
Re: Fun with ThinkScript May 14, 2017 04:03PM |
Registered: 7 years ago Posts: 5 |