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

Asked by Radhesh Joshi · SOLVED
1 reply 418 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

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.

Posted Aug 10
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    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.

    Verified Solution
      Markdown supported · ```json for code blocks · paste or drop screenshots

      Be specific and kind. Never share API keys, passwords or personal account details.

      Welcome to the community

      Log in or create your account in under a minute.

      1. 1Mobile
      2. 2E-mail
      3. 3Password
      +91

      Have a password?

      By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.