Join useThinkScript to post your question to a community of 21,000+ developers and traders.
sopen = security(ticker, res1, open[1], barmerge.gaps_off, barmerge.lookahead_on)
shigh = security(ticker, res1, high[1], barmerge.gaps_off, barmerge.lookahead_on)
slow = security(ticker, res1, low[1], barmerge.gaps_off, barmerge.lookahead_on)
sclose = security(ticker, res1, close[1], barmerge.gaps_off, barmerge.lookahead_on)
sPrice = security(ticker, res2, close)
r = shigh-slow
//Calculate pivots
pivot = (shigh + slow + sclose) / 3
pivotBottom = (shigh + slow ) / 2
pivotTop = (pivot - pivotBottom) + pivot
h3=sclose + r*(1.1/4)
h4=sclose + r*(1.1/2)
h5=(shigh/slow)*sclose
l3=sclose - r*(1.1/4)
l4=sclose - r*(1.1/2)
l5=sclose - (h5-sclose)
The Camarilla Pivot Points study in Thinkorswim does not plot lines, nor does it show the labels (S1...S2...etc.) Can someone modify the study so I can
- choose the painting strategy (line, dots, triangles)
- choose whether or not to show the labels and price
Ruby:# # TD Ameritrade IP Company, Inc. (c) 2013-2021 # input aggregationPeriod = {default "DAY", "WEEK", "MONTH"}; input length = 25; input hide_s1_r1 = yes; input lines = {default dashes, points, triangles, horizontal, squares}; input showbubbles_description = yes; input showpricebubble = yes; Assert(length > 0, "'length' should be positive: " + length); def yyyymmdd = GetYYYYMMDD(); def month = GetYear() * 12 + GetMonth(); def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd)); def period; switch (aggregationPeriod) { case DAY: period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1; case WEEK: period = Floor(day_number / 7); case MONTH: period = Floor(month - First(month)); } def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % length else count[1], 0); def start = CompoundValue(1, count < count[1] + period - period[1], yes); def highValue = if start then Highest(high(period = aggregationPeriod), length)[1] else if highValue[1] != 0 then highValue[1] else Double.NaN; def lowValue = if start then Lowest(low(period = aggregationPeriod), length)[1] else if lowValue[1] != 0 then lowValue[1] else Double.NaN; def closeValue = if start then close(period = aggregationPeriod)[1] else closeValue[1]; def range = highValue - lowValue; plot R5 = (highValue / lowValue) * closeValue; plot R4 = closeValue + range * (1.1) / 2; plot R3 = closeValue + range * (1.1) / 4; plot R2 = closeValue + range * (1.1) / 6; plot R1 = closeValue + range * (1.1) / 12; plot S1 = closeValue - range * (1.1) / 12; plot S2 = closeValue - range * (1.1) / 6; plot S3 = closeValue - range * (1.1) / 4; plot S4 = closeValue - range * (1.1) / 2; plot S5 = (closeValue - (R5 - closeValue)); R1.SetHiding(hide_s1_r1); S1.SetHiding(hide_s1_r1); R5.SetDefaultColor(GetColor(5)); R4.SetDefaultColor(GetColor(5)); R3.SetDefaultColor(GetColor(5)); R2.SetDefaultColor(GetColor(5)); R1.SetDefaultColor(GetColor(5)); S1.SetDefaultColor(GetColor(6)); S2.SetDefaultColor(GetColor(6)); S3.SetDefaultColor(GetColor(6)); S4.SetDefaultColor(GetColor(6)); S5.SetDefaultColor(GetColor(6)); def paintingStrategy = if lines == lines.points then PaintingStrategy.POINTS else if lines == lines.triangles then PaintingStrategy.TRIANGLES else if lines == lines.dashes then PaintingStrategy.DASHES else if lines == lines.horizontal then PaintingStrategy.HORIZONTAL else PaintingStrategy.SQUARES; R5.SetPaintingStrategy(paintingStrategy); R4.SetPaintingStrategy(paintingStrategy); R3.SetPaintingStrategy(paintingStrategy); R2.SetPaintingStrategy(paintingStrategy); R1.SetPaintingStrategy(paintingStrategy); S1.SetPaintingStrategy(paintingStrategy); S2.SetPaintingStrategy(paintingStrategy); S3.SetPaintingStrategy(paintingStrategy); S4.SetPaintingStrategy(paintingStrategy); S5.SetPaintingStrategy(paintingStrategy); #Bubbles to describe Pivot Levels input bubblemover = 8; def n = bubblemover; def n1 = n + 1; def StartPlot = if showbubbles_description == yes then (IsNaN(close[n]) and !IsNaN(close[n1])) else Double.NaN; AddChartBubble(StartPlot, R5[n1], "R5 " + (if showpricebubble then AsText(R5[n1]) else ""), Color.RED, if close[n1] > R5[n1] then no else yes); AddChartBubble(StartPlot, R4[n1], "R4 " + (if showpricebubble then AsText(R4[n1]) else ""), Color.RED, if close[n1] > R4[n1] then no else yes); AddChartBubble(StartPlot, R3[n1], "R3 " + (if showpricebubble then AsText(R3[n1]) else ""), Color.RED, if close[n1] > R3[n1] then no else yes); AddChartBubble(StartPlot, R2[n1], "R2 " + (if showpricebubble then AsText(R2[n1]) else ""), Color.RED, if close[n1] > R2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, R1[n1], "R1 " + (if showpricebubble then AsText(R1[n1]) else ""), Color.RED, if close[n1] > R1[n1] then no else yes); AddChartBubble(StartPlot, S5[n1], "S5 " + (if showpricebubble then AsText(S5[n1]) else ""), Color.GREEN, if close[n1] > S5[n1] then no else yes); AddChartBubble(StartPlot, S4[n1], "S4 " + (if showpricebubble then AsText(S4[n1]) else ""), Color.GREEN, if close[n1] > S4[n1] then no else yes); AddChartBubble(StartPlot, S3[n1], "S3 " + (if showpricebubble then AsText(S3[n1]) else ""), Color.GREEN, if close[n1] > S3[n1] then no else yes); AddChartBubble(StartPlot, S2[n1], "S2 " + (if showpricebubble then AsText(S2[n1]) else ""), Color.GREEN, if close[n1] > S2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, S1[n1], "S1 " + (if showpricebubble then AsText(S1[n1]) else ""), Color.GREEN, if close[n1] > S1[n1] then no else yes); R1.HideBubble(); R2.HideBubble(); R3.HideBubble(); R4.HideBubble(); R5.HideBubble(); S1.HideBubble(); S2.HideBubble(); S3.HideBubble(); S4.HideBubble(); S5.HideBubble();
Thanks bro.The following has inputs to choose the painting strategy, hide_s1_r1 plots , show bubbles and within the bubbles whether to show the price.
It shows bubbles (labels at the lines). If you are wanting labels at the top of the chart, it is now an option in the code below.Thanks bro.
I tried using this. It still does not show the labels
Ruby:# # TD Ameritrade IP Company, Inc. (c) 2013-2021 # input aggregationPeriod = {default "DAY", "WEEK", "MONTH"}; input length = 25; input hide_s1_r1 = yes; input lines = {default dashes, points, triangles, horizontal, squares}; input showbubbles_description = yes; input showpricebubble = yes; input showlabels = yes; Assert(length > 0, "'length' should be positive: " + length); def yyyymmdd = GetYYYYMMDD(); def month = GetYear() * 12 + GetMonth(); def day_number = DaysFromDate(First(yyyymmdd)) + GetDayOfWeek(First(yyyymmdd)); def period; switch (aggregationPeriod) { case DAY: period = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd) - 1; case WEEK: period = Floor(day_number / 7); case MONTH: period = Floor(month - First(month)); } def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % length else count[1], 0); def start = CompoundValue(1, count < count[1] + period - period[1], yes); def highValue = if start then Highest(high(period = aggregationPeriod), length)[1] else if highValue[1] != 0 then highValue[1] else Double.NaN; def lowValue = if start then Lowest(low(period = aggregationPeriod), length)[1] else if lowValue[1] != 0 then lowValue[1] else Double.NaN; def closeValue = if start then close(period = aggregationPeriod)[1] else closeValue[1]; def range = highValue - lowValue; plot R5 = (highValue / lowValue) * closeValue; plot R4 = closeValue + range * (1.1) / 2; plot R3 = closeValue + range * (1.1) / 4; plot R2 = closeValue + range * (1.1) / 6; plot R1 = closeValue + range * (1.1) / 12; plot S1 = closeValue - range * (1.1) / 12; plot S2 = closeValue - range * (1.1) / 6; plot S3 = closeValue - range * (1.1) / 4; plot S4 = closeValue - range * (1.1) / 2; plot S5 = (closeValue - (R5 - closeValue)); R1.SetHiding(hide_s1_r1); S1.SetHiding(hide_s1_r1); R5.SetDefaultColor(GetColor(5)); R4.SetDefaultColor(GetColor(5)); R3.SetDefaultColor(GetColor(5)); R2.SetDefaultColor(GetColor(5)); R1.SetDefaultColor(GetColor(5)); S1.SetDefaultColor(GetColor(6)); S2.SetDefaultColor(GetColor(6)); S3.SetDefaultColor(GetColor(6)); S4.SetDefaultColor(GetColor(6)); S5.SetDefaultColor(GetColor(6)); def paintingStrategy = if lines == lines.points then PaintingStrategy.POINTS else if lines == lines.triangles then PaintingStrategy.TRIANGLES else if lines == lines.dashes then PaintingStrategy.DASHES else if lines == lines.horizontal then PaintingStrategy.HORIZONTAL else PaintingStrategy.SQUARES; R5.SetPaintingStrategy(paintingStrategy); R4.SetPaintingStrategy(paintingStrategy); R3.SetPaintingStrategy(paintingStrategy); R2.SetPaintingStrategy(paintingStrategy); R1.SetPaintingStrategy(paintingStrategy); S1.SetPaintingStrategy(paintingStrategy); S2.SetPaintingStrategy(paintingStrategy); S3.SetPaintingStrategy(paintingStrategy); S4.SetPaintingStrategy(paintingStrategy); S5.SetPaintingStrategy(paintingStrategy); #Labels Addlabel(showlabels, "R5 " + AsText(R5), Color.RED); Addlabel(showlabels, "R4 " + AsText(R4), Color.RED); Addlabel(showlabels, "R3 " + AsText(R3), Color.RED); Addlabel(showlabels, "R2 " + AsText(R2), Color.RED); Addlabel(showlabels, "R1 " + AsText(R1), Color.RED); Addlabel(showlabels, "S5 " + AsText(S5), Color.GREEN); Addlabel(showlabels, "S4 " + AsText(S4), Color.GREEN); Addlabel(showlabels, "S3 " + AsText(S3), Color.GREEN); Addlabel(showlabels, "S2 " + AsText(S2), Color.GREEN); Addlabel(showlabels, "S1 " + AsText(S1), Color.GREEN); #Bubbles to describe Pivot Levels input bubblemover = 8; def n = bubblemover; def n1 = n + 1; def StartPlot = if showbubbles_description == yes then (IsNaN(close[n]) and !IsNaN(close[n1])) else Double.NaN; AddChartBubble(StartPlot, R5[n1], "R5 " + (if showpricebubble then AsText(R5[n1]) else ""), Color.RED, if close[n1] > R5[n1] then no else yes); AddChartBubble(StartPlot, R4[n1], "R4 " + (if showpricebubble then AsText(R4[n1]) else ""), Color.RED, if close[n1] > R4[n1] then no else yes); AddChartBubble(StartPlot, R3[n1], "R3 " + (if showpricebubble then AsText(R3[n1]) else ""), Color.RED, if close[n1] > R3[n1] then no else yes); AddChartBubble(StartPlot, R2[n1], "R2 " + (if showpricebubble then AsText(R2[n1]) else ""), Color.RED, if close[n1] > R2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, R1[n1], "R1 " + (if showpricebubble then AsText(R1[n1]) else ""), Color.RED, if close[n1] > R1[n1] then no else yes); AddChartBubble(StartPlot, S5[n1], "S5 " + (if showpricebubble then AsText(S5[n1]) else ""), Color.GREEN, if close[n1] > S5[n1] then no else yes); AddChartBubble(StartPlot, S4[n1], "S4 " + (if showpricebubble then AsText(S4[n1]) else ""), Color.GREEN, if close[n1] > S4[n1] then no else yes); AddChartBubble(StartPlot, S3[n1], "S3 " + (if showpricebubble then AsText(S3[n1]) else ""), Color.GREEN, if close[n1] > S3[n1] then no else yes); AddChartBubble(StartPlot, S2[n1], "S2 " + (if showpricebubble then AsText(S2[n1]) else ""), Color.GREEN, if close[n1] > S2[n1] then no else yes); AddChartBubble(StartPlot and hide_s1_r1 == no, S1[n1], "S1 " + (if showpricebubble then AsText(S1[n1]) else ""), Color.GREEN, if close[n1] > S1[n1] then no else yes); R1.HideBubble(); R2.HideBubble(); R3.HideBubble(); R4.HideBubble(); R5.HideBubble(); S1.HideBubble(); S2.HideBubble(); S3.HideBubble(); S4.HideBubble(); S5.HideBubble();
It is working. I had to increase "number of bars to the right" setting to 10It works for me. Make sure you the right expansion is set enough to display the bubble/label. You can also move the bubbles right/left at the bubblemover input.
here is a 15m chart of GME with the bubbles showing.
Hello there! I know you are a brilliant coder! I am trying to create a condition for Cam study and I am having a hard time doing it. Condition: if price OPENs at 9:30am EST between S3 and S4 (open of the first candle of the day) then a candle which crosses above S3 gets a "buy" bubble (it can happen anytime between 9:30am and 4pm). I want to display a "buy" bubble only ONCE if that condition is met meaning if a candle gets a bubble then no other candles after will get a bubble again even if their CLOSE crosses above S3 again so it will not overcrowd the chart with bubbles.It works for me. Make sure your right expansion is set wide enough to display the bubble/label. You can also move the bubbles right/left at the bubblemover input.
here is a 15m chart of GME with the bubbles showing.
Hello there! I know you are a brilliant coder! I am trying to create a condition for Cam study and I am having a hard time doing it. Condition: if price OPENs at 9:30am EST between S3 and S4 (open of the first candle of the day) then a candle which crosses above S3 gets a "buy" bubble (it can happen anytime between 9:30am and 4pm). I want to display a "buy" bubble only ONCE if that condition is met meaning if a candle gets a bubble then no other candles after will get a bubble again even if their CLOSE crosses above S3 again so it will not overcrowd the chart with bubbles.
#first part would be your cam study
#then I added time condition 9:30am -16:00 (I don't want to display any bubbles during pre-market or after hours)
def sessionopen= 930;
def sessionclose=1600;
def secondsFromOpen = SecondsFromTime(sessionOpen);
def secondsUntilClose = SecondsTillTime(sessionClose);
def MarketOpen = if SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0;
#now I was trying to create a condition: a. "open" of the day between S3 and S4
# b. 9:30am-4pm (time between this study is valid)
# c. candle crosses above S3
def buy = S3 > open(period = aggregationPeriod.DAY)> S4 and MarketOpen and (close crosses above S3);
addchartbubble(buy,low,"Buy",color.green, no);
what did I do wrong? or it should be if....then condition?! or maybe my market "open" condition is not correct ?
I would appreciate your help!
Example could be CRWD from today on 3D 5min chart
Ruby:#S3 Buy Bubble ----------------------------------------------------------- def sessionopen= 930; def sessionclose=1600; def secondsFromOpen = SecondsFromTime(sessionOpen); def secondsUntilClose = SecondsTillTime(sessionClose); def MarketOpen = if getday() == getlastday() and SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0 then 1 else 0; def cond1 = Between(open(period = aggregationPeriod), S4, S3) and marketopen; def cond2 = if isnan(cond2[1]) and cond1 and close crosses above S3 then 1 else cond2[1] + 1; AddChartBubble(cond2 == 1, low, "Buy", Color.LIGHT_RED, no);
You are AWESOMEEEEEEE! It works! I really appreciate it! I was losing my mind trying to figure it out.Try adding this to the code
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.