thinkScript last price function "Pricetype.LAST"


In ThinkorSwim, how do you select last price/current price is greater/less than study? I only see high low open close.

# beginning of code -------------------------------
# puts a label with close/last price on the chart

input price = close;
plot CloseLabel = price;
AddChartLabel(yes, concat(CloseLabel, " : Close Price"), CloseLabel.TakeValueColor());

# end of code ---------------------------------

Another example that I found

close("period" = AggregationPeriod.DAY, "priceType" = PriceType.LAST) from 3 bars ago is less than or equal to SimpleMovingAvg()."SMA" from 3 bars ago


New member
Hi guys. I am trying to code a custom column. I have two columns on a scan result. One is the Last price of an option and the other is the Open price. I am trying to code a new custom column to highlight the column green when the last price is 10% greater than the Open price.

Here is my code. I'm not sure why TOS wont accept the syntax. Any suggestions:

def O =OPEN;
def l =Last();
plot scan = (O*1.10);
assignBackgroundColor(if scan>l then color.dark_green else;


Well-known member
@godfreym Off the top of me head I think this should work... Note that I use self-documenting code rather than cryptic variable names... Also note that you cannot use Last as a priceType... Close works as Last while a candle/bar is painting...

def percenttChange = 0.10;
def lastPrice = close;
def tradePrice = if !IsNan(EntryPrice()) then EntryPrice() else lastPrice;
def diff = lastPrice - tradePrice;
def pct = if tradePrice != 0 then diff / tradePrice else 0;
plot data = pct * 100;
AssignBackgroundColor(if diff / tradePrice >= percenttChange then Color.DARK_GREEN else Color.BLACK);

I don't have any open positions to test this against at the moment...
Last edited:


New member
Thanks for taking a look. This may work and will give it a shot. I will let you know. Thanks again.

Shoot. Didn't work. Is there another priceType to use to replace Last? That's weird that you cannot calculate off it when its an actual column


Well-known member
@godfreym No, the code above is not working... I did get it working and then messed it back up again... I've been having a terrible time coding today due to stress so I think I'm done for the night... I'll get it working tomorrow morning... I've slept like crap for days, if you can even call it sleep...

Edited to add: I managed to fix the code above... Note that it doesn't account for a negative price change percentage but it could be added...
Last edited:


New member
Man thats awesome. Thank you so much. I will test is first thing after the markets open. I dont think the negative percentage matters so long as it turns green if its greater than 10%.

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.