How to add a Status Box in Tradingview Chart

Tradingview Status Box

Tradingview’s proprietary Pine script has clearly its limitation, but in script version 4 Tradingview has added a couple of useful features.

One of them is the option to add labels to the chart, which can used to render a status box, which might show important position parameters. The code below shows a simple example for how to add a status box to the last bar, which shows current position (long, short, flat), the current profit and the current price. It renders the box in green if profit is positive, red if negative and blue if neutral.

The status box can also be seen in action here on Tradingview.

posColor =, 75)
negColor =, 75)
dftColor =, 75)
posProfit= (strategy.position_size != 0) ? (close * 100 / strategy.position_avg_price - 100) : 0.0
posDir   = (strategy.position_size  > 0) ? "long" : strategy.position_size < 0 ? "short" : "flat"
posCol   = (posProfit > 0) ? posColor : (posProfit < 0) ? negColor : dftColor

var label lb = na
lb :=, max(high, highest(5)[1]),
   text="Pos: "+ posDir +
      "\nPnL: "+tostring(posProfit, "#.##")+"%" +
      "\nClose: "+tostring(close, "#.##"))
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *