Home Forums Trading view How can I show the entry price, stop-loss, and target on the chart in Pine Script?

How can I show the entry price, stop-loss, and target on the chart in Pine Script?

  • Author
    Posts
    • I’m creating a trading strategy in Pine Script and I want to display the entry price, stop-loss, and target levels directly on the chart.

      What is the best way to plot these levels so that I can easily see my entry, SL, and target for each trade?

      A simple example would be really helpful.

    • Yes, you can display the entry price, stop-loss, and target directly on the chart using plot().

      For example, you can calculate the levels based on the strategy’s entry price:

      //@version=6
      strategy("Entry SL Target", overlay = true)
      
      longCondition = ta.crossover(ta.ema(close, 9), ta.ema(close, 21))
      
      if longCondition
          strategy.entry("Long", strategy.long)
      
      entryPrice = strategy.position_avg_price
      stopLoss = entryPrice - 100
      target = entryPrice + 200
      
      plot(strategy.position_size > 0 ? entryPrice : na, "Entry", color = color.blue, linewidth = 2)
      plot(strategy.position_size > 0 ? stopLoss : na, "Stop Loss", color = color.red, linewidth = 2)
      plot(strategy.position_size > 0 ? target : na, "Target", color = color.green, linewidth = 2)
      

      Here:

      • strategy.position_avg_price gives the average entry price.
      • stopLoss calculates the stop-loss level.
      • target calculates the target level.
      • plot() displays all three levels on the chart.

      You can replace the fixed 100 and 200 values with your own SL and target calculation, such as a percentage, ATR-based distance, or risk-reward ratio.

      This makes it much easier to visually track your entry, stop-loss, and target while the trade is active.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top