CodyDegraaf

Candlestick Math

833 4 78
This is an updated version of my previous post, with the option to specify which symbol you want it to show up on.

This is a script I made to do what is called candlestick math (if you're not sure, Google             it). It will take the first open, the last close, and the highest high and lowest low from a range of candlesticks, and plot it on top of the chart.

Unfortunately, there is no way to make it so you can move it with your mouse, and the bar numbering is not the same as the regular drawing tools, so to figure out what the line number is, create a new script with the text:
study("Plot N")
plot(n)

This will create another chart that will show you the bar numbers that correspond to the script's bar numbers. From there, figure out where you want to start the candlestick math, and enter that number in the "Start" field in the inputs for this script.
Remove from Favorite Scripts Add to Favorite Scripts
study("Candlestick Math","CndlMth",overlay=true)
inStart = input(2610,"Start",integer,minval=0)
inLen = input(3,"Length",integer,minval=2)
inSym = input("*","Symbol",symbol)

len = inLen-1
start = inStart
end = inStart + len
isIn = (n >= start) and (n <= end) and (inSym == tickerid)

o = isIn ? (na(o[1]) ? fixnan(open[0]) : o[1]) : na
c = isIn ? (na(c[1]) ? fixnan(close[round(-len)]) : c[1]) : na
h = isIn ? (na(h[1]) ? highest(fixnan(high[round(-len)]),len+1) : h[1]) : na
l = isIn ? (na(l[1]) ? lowest(fixnan(low[round(-len)]),len+1) : l[1]) : na

fill(plot(h,title="High"),plot(l,title="Low"),color=gray,transp=50)
plot(o,title="Open",color=iff(o > c,red,green),linewidth=4)
plot(c,title="Close",color=iff(o > c,red,green),linewidth=4)
Phynx PRO
3 months ago
Hi there, sorry I don't know anything about pine script but when running this script it says "index is a negative". I really would like this script if I could get it working. I have already have the plot script to enter this value but just have trouble with this negative index. Any help appreciated.
Reply
Liza_84 Phynx
2 months ago
copy the script and delete "-" in lines 12, 13, 14
it shoud be:
"12 c = isIn ? (na(c) ? fixnan(close) : c) : na
13 h = isIn ? (na(h) ? highest(fixnan(high),len+1) : h) : na
14 l = isIn ? (na(l) ? lowest(fixnan(low),len+1) : l) : na
Reply
Liza_84 Liza_84
2 months ago
sorry (don't know how to correct the sent message), the right lines are:
12 c = isIn ? (na(c) ? fixnan(close) : c) : na
13 h = isIn ? (na(h) ? highest(fixnan(high),len+1) : h) : na
14 l = isIn ? (na(l) ? lowest(fixnan(low),len+1) : l) : na
Reply
Liza_84 Liza_84
2 months ago
again wrong post! delete "-" before word "len".
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out