fill()函數的以下新加載可以創建垂直漸變:
fill(plot1, plot2, top_value, bottom_value, top_color, bottom_color) fill(hline1, hline2, top_value, bottom_value, top_color, bottom_color)
新加載中的所有參數都接受系列參數。它們在`top_value`和`bottom_value`之間的空間中創建`top_color`和`bottom_color`之間的垂直漸變。在前兩個參數中使用了ID的繪圖或線充當了漸變的掩碼,確定漸變的哪個部分是可見的。
看看我們如何用兩個垂直漸變為舊的MACD賦予新外觀,一個填充兩個移動平均線之間的空間,另一個用於通常表示為直方圖的內容:
//@version=5 indicator("MACD") [macd, signal, hist] = ta.macd(close, 12, 26, 9) // Histogram float maxHist = ta.highest(hist, 100) float minHist = ta.lowest(hist, 100) bool histBull = hist > 0 color topHistColor = histBull ? color.new(color.green, 90) : color.red color botHistColor = histBull ? color.green : color.new(color.red, 90) float topHistValue = histBull ? maxHist : 0 float botHistValue = histBull ? 0 : minHist histPlot = plot(hist, "Histogram", color(na)) centerPlot = plot(0, "Middle", color(na)) fill(histPlot, centerPlot, topHistValue, botHistValue, topHistColor, botHistColor) // Averages float maxLine = ta.highest(math.max(macd, signal), 100) float minLine = ta.lowest(math.min(macd, signal), 100) bool lineBull = macd > signal color topLineColor = lineBull ? color.new(color.lime, 90) : color.fuchsia color botLineColor = lineBull ? color.lime : color.new(color.fuchsia, 90) float topLineValue = lineBull ? maxLine : maxLine float botLineValue = lineBull ? minLine : minLine macdPlot = plot(macd, "MACD", color.gray, 1) signalPlot = plot(signal, "Signal", color.silver, 1) fill(macdPlot, signalPlot, topLineValue, botLineValue, topLineColor, botLineColor)
在我們的下一個範例中,我們使用一個漸變作為背景,使用另一個漸變作為基於RSI的線創建一個Pine線圖:
//@version=5 indicator("Gradient Fill: Night in the Pine forest") // Sky skyTopColor = input.color(color.rgb(144, 191, 249, 1)) skyBotColor = input.color(color.rgb(251, 192, 45, 1)) skyPlot = plot(100, color = skyTopColor) groundPlot = plot(0, color = color.black) fill(skyPlot, groundPlot, 100, 0, skyTopColor, skyBotColor) // Trees crownsVal = ta.rsi(close, 20) treesPlot = plot(crownsVal, color = color.rgb(6, 126, 116)) fill(treesPlot, groundPlot, crownsVal, 0, color.rgb(6, 126, 116), color.black)
以下是我們的一些PineCoders在社群腳本中發佈的更多範例:
要隨時了解新的Pine Script™功能,請留意用戶手冊的發行說明。PineCoders帳戶還透過Telegram上的Squawk Box、Twitter帳戶和TradingView上的Pine Script™ Q&A公共聊天室中更新。
我們希望您可以發現這個功能很實用。請繼續向我們發送您的反饋和改進建議。我們為您建構TradingView,我們總是渴望收到您的來信。