Plot Candle

FXC911 – Forex & Crypto News & Insights

Goals

This script will correctly plot candlesticks on the TradingView chart, coloring the bodies of the candles green if the close is higher than the open and red otherwise. The wicks will be orange, and the borders of the candles will be white.

Pine Script Code

//@version=5
indicator("Plot Candle")

candleColor = if (close > open)
	color.green
else
	color.red
	
plotcandle(open, high, low, close, title = "CANDLE", color = candleColor, wickcolor = color.orange, bordercolor = color.white)

Code Output

Explanation

1. Version Declaration:

//@version=5
  • This line specifies that the script is written in Pine Script version 5.

2. Indicator Declaration:

indicator("Plot Candle")
  • This line defines a new indicator named "Plot Candle". When this script is applied to a chart, this name will be shown in the list of applied indicators.

3. Determining Candle Color:

candleColor = if (close > open)
	color.green
else
	color.red
  • candleColor: This variable determines the color of the candle to be plotted based on the condition (close > open).

  • if (close > open): This is a conditional statement that checks if the closing price (close) is greater than the opening price (open).

  • color.green and color.red: These are predefined colors in Pine Script. If the condition (close > open) is true, candleColor is set to green; otherwise, it's set to red.

4. Plotting the Candle:

plotcandle(open, high, low, close, title = "CANDLE", color = candleColor, wickcolor = color.orange, bordercolor = color.white)
  • plotcandle(open, high, low, close, title = "CANDLE", color = candleColor, wickcolor = color.orange, bordercolor = color.white)

    • The plotcandle function is used to plot candlesticks on the chart.

    • It uses the open, high, low, and close prices to draw the candlesticks.

    • The title parameter sets the name of the plotted candles to "CANDLE".

    • The color parameter sets the color of the candle body to the value determined by candleColor (either green or red).

    • The wickcolor parameter sets the color of the wicks (shadows) to orange (color.orange). Note that there is a typo in the script where it says color.orage instead of color.orange.

    • The bordercolor parameter sets the color of the candle borders to white (color.white).

Keywords

pine script, trading view, script editor, indicators, strategies, backtesting, alerts, custom scripts, stock analysis, charting tools, technical analysis, built-in functions, pine script syntax, trading bots, automated trading, scripting language, market data, trading signals, financial markets, programming trading strategies

Visit me on:

Last updated