Re: Fun with ThinkScript May 31, 2016 06:40PM |
Registered: 10 years ago Posts: 615 |
Quote
Palmer
Will buy you a round
# +--------------------------------------------------+ # | After hours volume | # | robert payne | # | [rrpayne.blogspot.com] | # +--------------------------------------------------+ input TimeMarketOpens = 0930; input TimeMarketCloses = 1600; def nMinutes = GetAggregationPeriod() / 60000; def eod = SecondsFromTime(TimeMarketCloses) >= 0 and SecondsFromTime(TimeMarketCloses) < nMinutes * 60; def mktopen = SecondsFromTime(TimeMarketOpens) >= 0 and SecondsTillTime(TimeMarketCloses) > 0; def cumulativeVolume = if eod then volume else if mktopen then cumulativeVolume[1] else cumulativeVolume[1] + volume; AddLabel(yes, cumulativeVolume, Color.YELLOW);
Re: Fun with ThinkScript May 31, 2016 07:24PM |
Registered: 9 years ago Posts: 53 |
Re: Fun with ThinkScript May 31, 2016 08:23PM |
Registered: 10 years ago Posts: 465 |
Re: Fun with ThinkScript June 01, 2016 02:47AM |
Registered: 10 years ago Posts: 615 |
# +--------------------------------------------------+ # | After hours volume | # | modified to ONLY count between certain hours | # | robert payne | # | [rrpayne.blogspot.com] | # +--------------------------------------------------+ input TimeToStartCounting = 1600; input TimeToStopCounting = 2000; def nMinutes = GetAggregationPeriod() / 60000; def startTime = SecondsFromTime(TimeToStartCounting) >= 0 and SecondsFromTime(TimeToStartCounting) < nMinutes * 60; def cumulativeVolume = if startTime then volume else if SecondsFromTime(TimeToStartCounting) > 0 and SecondsTillTime(TimeToStopCounting) > 0 then cumulativeVolume[1] + volume else cumulativeVolume[1]; AddLabel(yes, cumulativeVolume, Color.YELLOW);
Re: Fun with ThinkScript June 01, 2016 04:23AM |
Registered: 8 years ago Posts: 63 |
Quote
mntman
i would like to modify this where the previous peak only extends for me when todays close comes within 1/2% of that peak level... otherwise it would remain unextended.
# continue the previous peak as a dashed line def percent = 0.5; def today = getDay() == getLastDay(); def inRange = if !today then double.nan else close between (peak*(1-percent/100)) and (peak*(1+percent/100));
Re: Fun with ThinkScript June 01, 2016 01:36PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript June 01, 2016 05:14PM |
Registered: 10 years ago Posts: 615 |
Quote
mntman
I'm using roberts reversal areas as my swing targets after breakouts. I'm still fairly new to thinkscript, but my understanding is currently his script has a previous peak extend as a dashed line to the start of the next peak. i would like to modify this where the previous peak only extends for me when todays close comes within 1/2% of that peak level... otherwise it would remain unextended.
i referenced roberts other post about when a price is inRange of a set percentage. ive added definitions for inRange and percentage but can't seem to get it to work. would anyone have advice where I'm going wrong please?
# +--------------------------------------------------+ # | Example showing how to hide a plot when the | # | most recent close is not within a certain range. | # | robert payne | # | [rrpayne.blogspot.com] | # +--------------------------------------------------+ # | define a peak and plot it input magnitude = 5; def peak = high > Highest(high[1], magnitude) and high >= Highest(high[-magnitude], magnitude); def peakValue = if peak then high else peakValue[1]; plot peakLine = peakValue; peakLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); peakLine.SetDefaultColor(Color.CYAN); # | get the bar numbers for the most recent close # | and the most recent peak def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); def peakBar = if peak then BarNumber() else Double.NaN; # | find the values of the most recent peak and the one before it def lastPeakValue = GetValue(high, BarNumber() - HighestAll(peakBar)); def prevPeakValue = GetValue(peakValue[1], BarNumber() - HighestAll(peakBar)); # | find the value of the most recent close def mostRecentClose = HighestAll(if BarNumber() == lastBar then close else 0); # | define what is considered to be "in range" of the previous peak input percent = 0.5; def inRange = mostRecentClose > (prevPeakValue * (1 - percent / 100)) and mostRecentClose < (prevPeakValue * (1 + percent / 100)); # | extend the most recent peak plot lastPeakExtension = if BarNumber() >= HighestAll(peakBar) then lastPeakValue else Double.NaN; lastPeakExtension.SetDefaultColor(Color.CYAN); # | extend the previous peak only if the most recent close value is "in range" plot prevPeakExtension = if BarNumber() >= HighestAll(peakBar) - 1 then prevPeakValue else Double.NaN; prevPeakExtension.SetDefaultColor(Color.Dark_Orange); prevPeakExtension.SetHiding(!inRange);
Re: Fun with ThinkScript June 01, 2016 08:17PM |
Registered: 8 years ago Posts: 63 |
Re: Fun with ThinkScript June 02, 2016 10:41PM |
Registered: 7 years ago Posts: 3 |
Re: Fun with ThinkScript June 02, 2016 11:26PM |
Registered: 10 years ago Posts: 615 |
Quote
Anuramanus
I was wondering how to do the same with the outline on candles.
Quote
Alternately, I would like to just draw a line at the bottom of the chart and change the color of the points on that line ala John Carter's Porsche dots.
# +--------------------------------------------------+ # | changing colors based on moving avg relation | # | robert payne | # | [rrpayne.blogspot.com] | # +--------------------------------------------------+ plot MA1 = Average(close, 20); plot MA2 = Average(close, 50); plot Dots = (HighestAll(high) + LowestAll(low)) / 2; Dots.SetStyle(Curve.POINTS); Dots.SetLineWeight(5); Dots.AssignValueColor(if MA1 > MA2 then Color.LIME else Color.RED);
Re: Fun with ThinkScript June 03, 2016 08:49PM |
Registered: 8 years ago Posts: 10 |
Re: Fun with ThinkScript June 05, 2016 08:36AM |
Registered: 7 years ago Posts: 3 |
Re: Fun with ThinkScript June 05, 2016 12:00PM |
Registered: 7 years ago Posts: 3 |
Re: Fun with ThinkScript June 05, 2016 09:12PM |
Registered: 8 years ago Posts: 63 |
Quote
Anuramanus
Can anyone help with how to set a price level and then clear it?
input slowMA = 10; input fastMa = 20; plot MA1 = Average(close, slowMA); plot MA2 = Average(close, fastMA); # --- entry orders def show = yes; def hide = no; input orderLines = {default "Show", "Hide"}; input adjustEntryPrice = 0.25; input stopPercentage = 1.0; # crossover signals def crUp = ma1 crosses above ma2; def crDn = ma1 crosses below ma2; def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); def mostRecentClose = HighestAll(if BarNumber() == lastBar then close else 0); # order lines, bullish def hideUp = if mostRecentClose and ma1[0] < ma2[0] then 1 else 0; def crsUp = if barNumber() ==1 then double.nan else if !orderLines and crUp then close + adjustEntryPrice else crsUp[1]; plot entryUp = crsUp; entryUp.SetPaintingStrategy(PaintingStrategy.Horizontal); entryUp.AssignValueColor(createColor(0,153,204)); entryUp.SetLineWeight(1); entryUp.SetHiding(hideUp); def entUpExt = if barNumber() ==1 then double.nan else if !orderLines and !crUp then entryUp else entUpExt[1]; plot entryUpLine = entUpExt; entryUpLine.SetPaintingStrategy(PaintingStrategy.Horizontal); entryUpLine.SetDefaultColor(createColor(0,153,204)); entryUpLine.SetHiding(hideUp); def sUp = if !orderLines and !crUp then double.nan else low; def stUp = if barNumber() ==1 then double.nan else if !orderLines and crUp then (sUp*(1 - stopPercentage/100)) else stUp[1]; plot stopUp = stUp; stopUp.SetPaintingStrategy(PaintingStrategy.Dashes); stopUp.AssignValueColor(color.Pink); stopUp.SetLineWeight(1); stopUp.SetHiding(hideUp); def stpUpExt = if barNumber() ==1 then double.nan else if !orderLines and !crUp then stopUp else stpUpExt[1]; plot stopUpLine = stpUpExt; stopUpLine.SetPaintingStrategy(PaintingStrategy.Dashes); stopUpLine.SetDefaultColor(Color.Pink); stopUpLine.SetHiding(hideUp); # order lines, bearish def hideDn = if mostRecentClose and ma1[0] > ma2[0] then 1 else 0; def crsDn = if barNumber() ==1 then double.nan else if !orderLines and crDn then close - adjustEntryPrice else crsDn[1]; plot entryDn = crsDn; entryDn.SetPaintingStrategy(PaintingStrategy.Horizontal); entryDn.SetDefaultColor(createColor(0,153,204)); entryDn.SetLineWeight(1); entryDn.SetHiding(hideDn); def entDnExt = if barNumber() ==1 then double.nan else if !orderLines and !crDn then entryDn else entDnExt[1]; plot entryDnLine = entDnExt; entryDnLine.SetPaintingStrategy(PaintingStrategy.Horizontal); entryDnLine.SetDefaultColor(createColor(0,153,204)); entryDnLine.SetHiding(hideDn); def sDn = if !orderLines and !crDn then double.nan else high; def stDn = if barNumber() ==1 then double.nan else if !orderLines and crDn then (sDn*(1 + stopPercentage/100)) else stDn[1]; plot stopDn = stDn; stopDn.SetPaintingStrategy(PaintingStrategy.Dashes); stopDn.AssignValueColor(color.pink); stopDn.SetLineWeight(1); stopDn.SetHiding(hideDn); def stpDnExt = if barNumber() ==1 then double.nan else if !orderLines and !crDn then stopDn else stpDnExt[1]; plot stopDnLine = stpDnExt; stopDnLine.SetPaintingStrategy(PaintingStrategy.Dashes); stopDnLine.SetDefaultColor(Color.pink); stopDnLine.SetHiding(hideDn);
Re: Fun with ThinkScript June 06, 2016 08:22AM |
Registered: 10 years ago Posts: 615 |
# +--------------------------------------------------+ # | Example: setting & clearing a price level | # | robert payne | # | [rrpayne.blogspot.com] | # +--------------------------------------------------+ # Define two moving averages plot MA10 = Average(close, 10); plot MA20 = Average(close, 20); # Define entry as MA10 crossing above MA20 plot signalUp = MA10 crosses above MA20; signalUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); signalUp.SetDefaultColor(Color.YELLOW); signalUp.SetLineWeight(3); # Define the entry price as the closing price when the MA10 # crosses above the MA20. # Store that price using a recursive variable then # clear the price when the MA10 crosses back below the MA20 def entryPrice = if signalUp then close else if MA10 crosses below MA20 then Double.NaN else entryPrice[1]; # plot the entry line plot entryLine = entryPrice; entryLine.SetDefaultColor(Color.LIME); entryLine.SetLineWeight(2);
Re: Fun with ThinkScript June 06, 2016 06:39PM |
Registered: 8 years ago Posts: 63 |
Quote
Robert
You need to read about using recursive (self-referencing) variables to carry historical data forward.
def show = yes; def hide = no; input shortMA = 10; input longMA = 20; input CrossoverArrows = {default "Show", "Hide"}; input OrderLines = {default "Show", "Hide"}; input OrderLineLength = 5; input AdjustEntryPrice = 0.25; input StopPercentage = 1.0; # Plot the moving average lines plot MA1 = Average(close, shortMA); plot MA2 = Average(close, longMA); # Crossover signals def CrossUp = MA1 crosses above MA2; def CrossDn = MA1 crosses below MA2; # Alert arrows plot ArrowUp = if CrossUp and !crossoverArrows then low * 0.997 else Double.NaN; ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); ArrowUp.SetDefaultColor(Color.Light_Green); ArrowUp.SetLineWeight(2); ArrowUp.HideBubble(); plot ArrowDn = if CrossDn and !crossoverArrows then high * 1.003 else Double.NaN; ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); ArrowDn.SetDefaultColor(Color.Pink); ArrowDn.SetLineWeight(2); ArrowDn.HideBubble(); # Order lines def limitUp = crossUp[OrderLineLength]; def limitDn = crossDn[OrderLineLength]; def entryPriceUp = if !orderLines and crossUp then close + AdjustEntryPrice else if limitUp then double.nan else entryPriceUp[1]; def stopPriceUp = if !orderLines and crossUp then (close*(1 - stopPercentage/100)) else if limitUp then double.nan else stopPriceUp[1]; def entryPriceDn = if !orderLines and crossDn then close - AdjustEntryPrice else if limitDn then double.nan else entryPriceDn[1]; def stopPriceDn = if !orderLines and crossDn then (close*(1 + stopPercentage/100)) else if limitDn then double.nan else stopPriceDn[1]; plot entryLineUp = entryPriceUp; entryLineUp.SetPaintingStrategy(PaintingStrategy.Horizontal); entryLineUp.SetDefaultColor(createColor(0,153,204)); entryLineUp.SetLineWeight(1); plot stopLineUp = stopPriceUp; stopLineUp.SetPaintingStrategy(PaintingStrategy.Dashes); stopLineUp.SetDefaultColor(color.Pink); stopLineUp.SetLineWeight(1); plot entryLineDn = entryPriceDn; entryLineDn.SetPaintingStrategy(PaintingStrategy.Horizontal); entryLineDn.SetDefaultColor(createColor(0,153,204)); entryLineDn.SetLineWeight(1); plot stopLineDn = stopPriceDn; stopLineDn.SetPaintingStrategy(PaintingStrategy.Dashes); stopLineDn.SetDefaultColor(color.Pink); stopLineDn.SetLineWeight(1);
Fisher Transform alert TOS June 07, 2016 12:25PM |
Registered: 7 years ago Posts: 1 |
Re: Fun with ThinkScript June 08, 2016 11:42AM |
Registered: 7 years ago Posts: 1 |
Re: Fun with ThinkScript June 09, 2016 12:52AM |
Registered: 8 years ago Posts: 7 |
#Primary aggregation: 1 minute declare lower; plot PastDailyClose = close( period = "DAY" )[100];
Re: Fun with ThinkScript June 09, 2016 06:33AM |
Registered: 9 years ago Posts: 60 |
Re: Fun with ThinkScript June 09, 2016 05:43PM |
Registered: 8 years ago Posts: 63 |
Quote
Sara
How can I write a script that will give an UP arrow if the volume bar is green or DOWN arrow if the volume bar is red ?
def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); def Vol = volume; def upBar = if Vol > Vol[1] then 1 else 0; def dnBar = if Vol < Vol[1] then 1 else 0; plot upArrow = if BarNumber() == lastBar then upBar else double.nan; upArrow.SetPaintingStrategy(PaintingStrategy.Boolean_ARROW_UP); upArrow.AssignValueColor(Color.light_green); upArrow.SetLineWeight(2); plot dnArrow =if BarNumber() == lastBar then dnBar else double.nan; dnArrow.SetPaintingStrategy(PaintingStrategy.Boolean_ARROW_DOWN); dnArrow.AssignValueColor(Color.pink); dnArrow.SetLineWeight(2);
Re: Fun with ThinkScript June 09, 2016 06:10PM |
Registered: 8 years ago Posts: 63 |
Quote
KevinR
What is causing this weird bug?
Re: Fun with ThinkScript June 10, 2016 03:29AM |
Registered: 9 years ago Posts: 60 |
Re: Fun with ThinkScript June 10, 2016 10:13AM |
Registered: 8 years ago Posts: 10 |
Re: Fun with ThinkScript June 10, 2016 04:02PM |
Registered: 8 years ago Posts: 63 |
Quote
Sara
I'm using Average volume indicator.
# # TD Ameritrade IP Company, Inc. (c) 2007-2016 # declare lower; declare zerobase; input length = 50; plot Vol = volume; plot VolAvg = Average(volume, length); Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM); Vol.SetLineWeight(3); Vol.DefineColor("Up", Color.UPTICK); Vol.DefineColor("Down", Color.DOWNTICK); Vol.AssignValueColor(if close > close[1] then Vol.color("Up" ) else if close < close[1] then Vol.color("Down" ) else GetColor(1)); VolAvg.SetDefaultColor(GetColor(8));
input length = 20; def lastBar = HighestAll(if IsNaN(close) then 0 else BarNumber()); def VolAvg = Average(volume, length); def upBar = if VolAvg > VolAvg[1] then 1 else 0; def dnBar = if VolAvg < VolAvg[1] then 1 else 0; plot upArrow = if BarNumber() == lastBar then upBar else double.nan; upArrow.SetPaintingStrategy(PaintingStrategy.BooleAN_ARROW_UP); upArrow.AssignValueColor(Color.Uptick); upArrow.SetLineWeight(2); plot dnArrow =if BarNumber() == lastBar then dnBar else double.nan; dnArrow.SetPaintingStrategy(PaintingStrategy.BooleAN_ARROW_DOWN); dnArrow.AssignValueColor(Color.Downtick); dnArrow.SetLineWeight(2);
Re: Fun with ThinkScript June 11, 2016 01:18PM |
Registered: 10 years ago Posts: 615 |
Re: Fun with ThinkScript June 13, 2016 07:57PM |
Registered: 8 years ago Posts: 54 |
Re: Fun with ThinkScript June 13, 2016 08:34PM |
Registered: 10 years ago Posts: 35 |
Re: Fun with ThinkScript June 13, 2016 08:40PM |
Registered: 8 years ago Posts: 54 |
Re: Fun with ThinkScript June 15, 2016 10:44PM |
Registered: 8 years ago Posts: 10 |
def crossedDown = if close < percentLinedown15 then 1 else 0; def crosseddownstate = if today and crossedDown == 1 then 1 else crossedDownstate[1]; def crossedDownstate2 = crossedDownstate; def SEStop = If crossedDownstate2 ==1 then orl else orh;