Plot Signals on TradingView Chart
Plot Signals on TradingView Chart
To plot custom signals (e.g., buy/sell arrows) on a TradingView chart, you can useĀ Pine Script, TradingView’s built-in scripting language. Below is a step-by-step example to plot signals based on a moving average crossover strategy:
Pine Script
The following Pine Script creates basic buy and sell signals based on a Simple Moving Average (SMA) Strategy:
// This Pine Script⢠code is subject to the terms of the Mozilla
Public License 2.0 at https://mozilla.org/MPL/2.0/
// Pine Script Tutorials
// Ā© www.TestingDocs.com
//@version=6
indicator("MA Crossover Signals", overlay=true)
// Define Moving Averages
fastMA = ta.sma(close, 50)
slowMA = ta.sma(close, 200)
// Plot MAs on the chart
plot(fastMA, "Fast MA", color=color.blue)
plot(slowMA, "Slow MA", color=color.red)
// Define Conditions
buySignal = ta.crossover(fastMA, slowMA) // Fast MA crosses above Slow MA
sellSignal = ta.crossunder(fastMA, slowMA) // Fast MA crosses below Slow MA
// Plot Signals on the Chart
plotshape(buySignal, title="Buy", style=shape.triangleup,
location=location.belowbar, color=color.green, size=size.small,text="BUY")
plotshape(sellSignal, title="Sell", style=shape.triangledown,
location=location.abovebar, color=color.red, size=size.small,text="SELL")
How It Works?
Explanation of the script:
- Moving Averages
- A 50-period (fast) and 200-period (slow) SMA are calculated.
- These are plotted as lines on the chart.
- Signal Conditions
- Buy Signal: When the fast MA crossesĀ aboveĀ the slow MA.
- Sell Signal: When the fast MA crossesĀ belowĀ the slow MA.
- Visualization
- Green ā² triangles appearĀ below barsĀ for buy signals.
- Red ā¼ triangles appearĀ above barsĀ for sell signals.
Disclaimer
This content is for informational and educational purposes only and should not be considered financial or investment advice. Trading stocks, cryptocurrencies, or any financial instruments involves risk, and past performance does not guarantee future results. Always conduct your own research and consult with a licensed financial advisor before making any trading or investment decisions. The author and publisher are not responsible for any financial losses incurred by the use of this information.