Understanding Current Price & Entry Price in Pine Script
So you're getting into Pine Script and wondering how to work with the current price? I totally get it - this was one of the first things that confused me when I started coding indicators for TradingView. Let me walk you through everything I wish someone had explained to me back then.
The Thing About "Current Price" in Pine Script
Here's something that threw me off initially: in Pine Script, when you want the current price, you use close
. I know, I know - the name is misleading! You'd think "close" means the final closing price of a finished candle, right?
Well, here's the kicker - close
actually gives you the real-time price as it's happening. So on historical candles, yes, it's the closing price. But on the current candle (the one that's still forming), it updates every time the price moves. Pretty neat, huh?
I remember spending way too much time looking for a variable called "current_price" or something like that. Turns out, close
was what I needed all along.
Your First Current Price Script
Let's start with something super simple. Here's how you can plot the current price:
//@version=5
indicator("My Current Price Plotter")
// Just plot the current price - that's it!
plot(close, "Current Price", color=color.blue)
When you add this to your chart, you'll see a blue line following the price. On old candles, it shows where they closed. On the current candle, it moves with the live price. It's actually pretty cool to watch!
Building Something Useful - A Moving Average
Now let's make something more practical. How about a simple moving average? This is where current price really starts to shine:
//@version=5
indicator("My Simple Moving Average")
// Let people choose how many periods they want
period = input(20, "How many periods?")
// Calculate the moving average using current prices
my_sma = ta.sma(close, period)
// Plot it on the chart
plot(my_sma, "SMA", color=color.blue)
What's happening here is that ta.sma()
takes the current price (close
) from each of the last 20 candles (or whatever period you choose) and averages them out. The beauty is that as the current candle's price changes, your moving average updates too.
Making Your Life Easier with Visual Tools

Website: Pineify
Check out what Pineify can do.Look, I'll be honest with you - coding everything from scratch can be a pain. I've been there, staring at blank screens trying to figure out how to combine different indicators with price data.
That's where tools like Pineify come in handy. Instead of wrestling with syntax, you can drag and drop conditions together visually. Want to check if the current price is above a moving average AND the RSI is oversold? Just click a few buttons instead of writing lines of code.
I still code plenty of stuff manually, but for complex conditions involving multiple indicators and price levels, having a visual editor saves me tons of time. Plus, you can see exactly what your conditions look like with charts and colors, which makes debugging so much easier.

Getting Price Data from Other Symbols
Sometimes you want to peek at another stock's price while looking at your current chart. Maybe you're trading SPY but want to see what Apple is doing. Here's how:
//@version=5
indicator("Apple Price Tracker")
// Get Apple's price even if we're looking at a different chart
apple_price = request.security("AAPL", "D", close)
// Show it on our chart
plot(apple_price, "Apple Price", color=color.red)
This grabs Apple's daily closing price and plots it on whatever chart you're viewing. Pretty handy for keeping an eye on key stocks or indices while analyzing something else.
Using Current Price in Trading Strategies
Here's where things get interesting. Let's say you want to buy when RSI gets oversold and sell when it gets overbought:
//@version=5
strategy("Simple RSI Strategy")
// Calculate RSI using current prices
rsi = ta.rsi(close, 14)
// Set up our buy and sell conditions
should_buy = ta.crossover(rsi, 30)
should_sell = ta.crossunder(rsi, 70)
// Execute the trades
if (should_buy)
strategy.entry("Buy", strategy.long)
if (should_sell)
strategy.entry("Sell", strategy.short)
The RSI calculation uses close
(our current price) to figure out if the stock is oversold or overbought. When RSI crosses above 30, we buy. When it drops below 70, we sell. Simple but effective!
Setting Up Price Alerts
Want to get notified when price does something specific? Here's a script that alerts you when the current price moves significantly from the day's opening:
//@version=5
indicator("Big Move Alert")
// Figure out yesterday's trading range
yesterday_high = ta.highest(high[1], 1)
yesterday_low = ta.lowest(low[1], 1)
yesterday_range = yesterday_high - yesterday_low
// We'll alert if price moves half of yesterday's range
big_move_threshold = yesterday_range * 0.5
// Check if we've had a big move up from today's open
big_move_up = close >= open + big_move_threshold
// Show a signal on the chart
plotshape(big_move_up, "Big Move!", shape.triangleup, location.belowbar, color.green)
This compares the current price to today's opening price and alerts you if it's moved up by half of yesterday's trading range. You can adjust the threshold to whatever makes sense for your trading style.
Common Gotchas I've Run Into
Here's something that tripped me up early on - trying to access future prices:
// This works - getting yesterday's close
yesterday_close = close[1]
// This doesn't work - you can't see the future!
tomorrow_close = close[-1] // Nope, not happening
Pine Script processes data bar by bar, from left to right on your chart. You can look back at historical data, but you can't peek into the future (wouldn't that be nice though?).
Also, remember that close[1]
means "the close of the previous bar," close[2]
means "two bars ago," and so on. It's not rocket science, but it can be confusing at first.
Wrapping It Up
Working with current price in Pine Script is really just about understanding that close
is your friend. It gives you the real-time price data you need for indicators, strategies, and alerts.
The key things to remember:
close
updates in real-time on the current candle- You can use it in calculations just like any other number
- You can grab price data from other symbols if needed
- You can look back in time, but not forward
Once you get comfortable with these basics, you'll find that most of your Pine Script projects will involve current price in some way. Whether you're building simple indicators or complex trading strategies, understanding how to work with price data is fundamental.
Happy coding, and don't be afraid to experiment! The best way to learn is by trying stuff out and seeing what happens.