零点课堂 | How To Create TA Indicators on TradingView（4）
Many traders prefer candlestick charts as they give us more information than a simple plot like the one we just did. Let’s add them next.
//@version=4 study("My Script", overlay=true) plotcandle(open, high, low, close)
It’s a good start, but the lack of colors makes it a bit bland. Ideally, we should have red candles when the open is greater than the close for the given timeframe, and green ones if the close exceeds the open. We’ll add a line above the plotcandle() function:
//@version=4 study("My Script", overlay=true) colors = open >= close ? color.red : color.green plotcandle(open, high, low, close)
This looks at every candlestick and checks whether the open is greater or equal to the close. If it is, it means prices have dropped over the period, so it will color the candlestick red. Otherwise, it will color it green. Modify the plotcandle() function to pass this color scheme in:
//@version=4 study("My Script", overlay=true) colors = open >= close ? color.red : color.green plotcandle(open, high, low, close, color=colors)
Remove the current indicators if you haven’t already, and add this one to the chart. Now we should have something resembling a regular candlestick chart.
Plotting moving averages (MA)
We’ve got some of the basics down. Let’s move on to our first custom indicator – the exponential moving average, or EMA. This is a valuable tool as it allows us to filter out any market noise and smooth out price action.
EMA differs slightly from the simple moving average (SMA), in that it puts more weight in the most recent data. It tends to be more reactive to sudden movements and is often used for short-term plays (in day trading, for example).