【发布时间】:2022-08-10 17:35:56
【问题描述】:
我正在尝试使用以下函数签名在 Pine Script-v5 中创建一个新库:
**导出 TrendMeterBarsColors(float vclose, float vohlc4, float vhlc3, float vOpen) => **
但我不断收到以下错误:\" 未使用 \'vohlc4\' 参数。应使用所有参数。\", 即使我在函数体中使用了参数\'vohlc4\'。有没有人遇到过类似的问题?
完整代码: \'\'\'
// @function returns the colors of Trend Bars (from Trend Meter)
// @param none
// @returns color.red,color.green
export TrendMeterBarsColors(float vclose, float vohlc4, float vhlc3, float vOpen) =>
ShowTrendBar = true
WTSetups = true
TMSetups = true
MSBar1 = \"Trend Filter\"
MSBar2 = \"Trend Filter\"
TrendBar1 = \"MACD Crossover - Fast - 8, 21, 5\"
TrendBar2 = \"RSI 13: > or < 50\"
TrendBar3 = \"RSI 5: > or < 50\"
TrendBar4 = \"MA Crossover\"
TrendBar5 = \"MA Crossover\"
////////////////Signals - Wave Trend/////////////////////////////////////////////////////////////////////////////////////////////////
// Wave Trend - RSI
RSIMC = ta.rsi(vclose, 14)
// Wave Trend
n1 = 9 //input(9, \"Wave Trend - WT Channel Length\")
n2 = 12 // input(12, \"Wave Trend - WT Average Length\")
esa = ta.ema(vhlc3, n1)
de = ta.ema(math.abs(vhlc3 - esa), n1)
ci = (vhlc3 - esa) / (0.015 * de)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 3)
// Wave Trend - Overbought & Oversold lines
obLevel2 = 60 // input( 60, \"Wave Trend - WT Very Overbought\")
obLevel = 50 // input( 50, \"Wave Trend - WT Overbought\")
osLevel = -50 // input(-50, \"Wave Trend - WT Oversold\")
osLevel2 = -60 // input(-60, \"Wave Trend - WT Very Oversold\")
// Wave Trend - Conditions
WTCross = ta.cross(wt1, wt2)
WTCrossUp = wt2 - wt1 <= 0
WTCrossDown = wt2 - wt1 >= 0
WTOverSold = wt2 <= osLevel2
WTOverBought = wt2 >= obLevel2
// MA Inputs
MA1_Length = 5
MA1_Type = \"EMA\"
MA2_Length = 11
MA2_Type = \"EMA\"
MA3_Length = 13
MA3_Type = \"EMA\"
MA4_Length = 36
MA4_Type = \"SMA\"
// MA Calculations
MA1 = if MA1_Type == \"SMA\"
ta.sma(vclose, MA1_Length)
else
ta.ema(vclose, MA1_Length)
MA2 = if MA2_Type == \"SMA\"
ta.sma(vclose, MA2_Length)
else
ta.ema(vclose, MA2_Length)
MA3 = if MA3_Type == \"SMA\"
ta.sma(vclose, MA3_Length)
else
ta.ema(vclose, MA3_Length)
MA4 = if MA4_Type == \"SMA\"
ta.sma(vclose, MA4_Length)
else
ta.ema(vclose, MA4_Length)
// MA Crossover Condition
MACrossover1 = MA1 > MA2 ? 1 : 0
MACrossover2 = MA3 > MA4 ? 1 : 0
// MA Direction Condition
MA1Direction = MA1 > MA1[1] ? 1 : 0
MA2Direction = MA2 > MA2[1] ? 1 : 0
MA3Direction = MA3 > MA3[1] ? 1 : 0
MA4Direction = MA4 > MA4[1] ? 1 : 0
// MA Direction Change Condition
MA1PositiveDirectionChange = MA1Direction and not MA1Direction[1] ? 1 : 0
MA2PositiveDirectionChange = MA2Direction and not MA2Direction[1] ? 1 : 0
MA3PositiveDirectionChange = MA3Direction and not MA3Direction[1] ? 1 : 0
MA4PositiveDirectionChange = MA4Direction and not MA4Direction[1] ? 1 : 0
MA1NegativeDirectionChange = not MA1Direction and MA1Direction[1] ? 1 : 0
MA2NegativeDirectionChange = not MA2Direction and MA2Direction[1] ? 1 : 0
MA3NegativeDirectionChange = not MA3Direction and MA3Direction[1] ? 1 : 0
MA4NegativeDirectionChange = not MA4Direction and MA4Direction[1] ? 1 : 0
// MACD and MOM & DAD - Top Dog Trading
// Standard MACD Calculations
MACDfastMA = 12
MACDslowMA = 26
MACDsignalSmooth = 9
MACDLine = ta.ema(vclose, MACDfastMA) - ta.ema(vclose, MACDslowMA)
SignalLine = ta.ema(MACDLine, MACDsignalSmooth)
MACDHistogram = MACDLine - SignalLine
// MACD- Background Color Change Condition
MACDHistogramCross = MACDHistogram > 0 ? 1 : 0
MACDLineOverZero = MACDLine > 0 ? 1 : 0
MACDLineOverZeroandHistogramCross = MACDHistogramCross and MACDLineOverZero ? 1 : 0
MACDLineUnderZeroandHistogramCross = not MACDHistogramCross and not MACDLineOverZero ? 1 : 0
// Fast MACD Calculations
FastMACDfastMA = 8
FastMACDslowMA = 21
FastMACDsignalSmooth = 5
FastMACDLine = ta.ema(vclose, FastMACDfastMA) - ta.ema(vclose, FastMACDslowMA)
FastSignalLine = ta.ema(FastMACDLine, FastMACDsignalSmooth)
FastMACDHistogram = FastMACDLine - FastSignalLine
// Fast MACD- Background Color Change Condition
FastMACDHistogramCross = FastMACDHistogram > 0 ? 1 : 0
FastMACDLineOverZero = FastMACDLine > 0 ? 1 : 0
FastMACDLineOverZeroandHistogramCross = FastMACDHistogramCross and FastMACDLineOverZero ? 1 : 0
FastMACDLineUnderZeroandHistogramCross = not FastMACDHistogramCross and not FastMACDLineOverZero ? 1 : 0
// Top Dog Trading - Mom Dad Calculations
TopDog_Fast_MA = 5
TopDog_Slow_MA = 20
TopDog_Sig = 30
TopDogMom = ta.ema(vclose, TopDog_Fast_MA) - ta.ema(vclose, TopDog_Slow_MA)
TopDogDad = ta.ema(TopDogMom, TopDog_Sig)
// Top Dog Dad - Background Color Change Condition
TopDogDadDirection = TopDogDad > TopDogDad[1] ? 1 : 0
TopDogMomOverDad = TopDogMom > TopDogDad ? 1 : 0
TopDogMomOverZero = TopDogMom > 0 ? 1 : 0
TopDogDadDirectandMomOverZero = TopDogDadDirection and TopDogMomOverZero ? 1 : 0
TopDogDadDirectandMomUnderZero = not TopDogDadDirection and not TopDogMomOverZero ? 1 : 0
////// Trend Barmeter Calculations //////
// UCS_Trend / Trend Candles Trend Barmeter Calculations
//UCS_Trend by ucsgears copy Trend Candles
//Interpretation of TTM Trend bars. It is really _close to the actual.
haopen = 0.0
haopen := na(haopen[1]) ? (vOpen + vclose) / 2 : (haopen[1] + vohlc4[1]) / 2
//hahigh = math.max(high, math.max(haopen, vohlc4))
//halow = math.min(low, math.min(haopen, vohlc4))
ccolor = vohlc4 - haopen > 0 ? 1 : 0
inside6 = haopen <= math.max(haopen[6], vohlc4[6]) and haopen >= math.min(haopen[6], vohlc4[6]) and
vohlc4 <= math.max(haopen[6], vohlc4[6]) and vohlc4 >= math.min(haopen[6], vohlc4[6]) ?
1 : 0
inside5 = haopen <= math.max(haopen[5], vohlc4[5]) and haopen >= math.min(haopen[5], vohlc4[5]) and
vohlc4 <= math.max(haopen[5], vohlc4[5]) and vohlc4 >= math.min(haopen[5], vohlc4[5]) ?
1 : 0
inside4 = haopen <= math.max(haopen[4], vohlc4[4]) and haopen >= math.min(haopen[4], vohlc4[4]) and
vohlc4 <= math.max(haopen[4], vohlc4[4]) and vohlc4 >= math.min(haopen[4], vohlc4[4]) ?
1 : 0
inside3 = haopen <= math.max(haopen[3], vohlc4[3]) and haopen >= math.min(haopen[3], vohlc4[3]) and
vohlc4 <= math.max(haopen[3], vohlc4[3]) and vohlc4 >= math.min(haopen[3], vohlc4[3]) ?
1 : 0
inside2 = haopen <= math.max(haopen[2], vohlc4[2]) and haopen >= math.min(haopen[2], vohlc4[2]) and
vohlc4 <= math.max(haopen[2], vohlc4[2]) and vohlc4 >= math.min(haopen[2], vohlc4[2]) ?
1 : 0
inside1 = haopen <= math.max(haopen[1], vohlc4[1]) and haopen >= math.min(haopen[1], vohlc4[1]) and
vohlc4 <= math.max(haopen[1], vohlc4[1]) and vohlc4 >= math.min(haopen[1], vohlc4[1]) ?
1 : 0
colorvalue = inside6 ? ccolor[6] : inside5 ? ccolor[5] : inside4 ? ccolor[4] :
inside3 ? ccolor[3] : inside2 ? ccolor[2] : inside1 ? ccolor[1] : ccolor
TrendBarTrend_Candle_Color = colorvalue ? #288a75 : color.red
TrendBarTrend_Candle = colorvalue ? 1 : 0
// barcolor(Trend_Candle_Color , title = \"Trend Candles\")
// barcolor(ShowTrendCandles? Trend_Candle_Color : na, title = \"Trend Candles\")
// RSI 5 Trend Barmeter Calculations
RSI5 = ta.rsi(vclose, 5)
RSI5Above50 = RSI5 > 50 ? 1 : 0
RSI5Color = RSI5Above50 ? #288a75 : color.red
TrendBarRSI5Color = RSI5Above50 ? #288a75 : color.red
// RSI 5 Trend Barmeter Calculations
RSI13 = ta.rsi(vclose, 13)
// Linear Regression Calculation For RSI Signal Line
SignalLineLength1 = 21
x = bar_index
y = RSI13
x_ = ta.sma(x, SignalLineLength1)
y_ = ta.sma(y, SignalLineLength1)
mx = ta.stdev(x, SignalLineLength1)
my = ta.stdev(y, SignalLineLength1)
c = ta.correlation(x, y, SignalLineLength1)
slope = c * (my / mx)
inter = y_ - slope * x_
LinReg1 = x * slope + inter
RSISigDirection = LinReg1 > LinReg1[1] ? 1 : 0
RSISigCross = RSI13 > LinReg1 ? 1 : 0
RSI13Above50 = RSI13 > 50 ? 1 : 0
// Trend Barmeter Color Calculation
RSI13Color = RSI13Above50 ? #288a75 : color.red
TrendBarRSI13Color = RSI13Above50 ? #288a75 : color.red
TrendBarRSISigCrossColor = RSISigCross ? #288a75 : color.red
TrendBarMACDColor = MACDHistogramCross ? #288a75 : color.red
TrendBarFastMACDColor = FastMACDHistogramCross ? #288a75 : color.red
TrendBarMACrossColor = MACrossover1 ? #288a75 : color.red
TrendBarMomOverDadColor = TopDogMomOverDad ? #288a75 : color.red
TrendBarDadDirectionColor = TopDogDadDirection ? #288a75 : color.red
TrendBar1Result = TrendBar1 == \"MA Crossover\" ? MACrossover1 :
TrendBar1 == \"MACD Crossover - 12, 26, 9\" ? MACDHistogramCross :
TrendBar1 == \"MACD Crossover - Fast - 8, 21, 5\" ? FastMACDHistogramCross :
TrendBar1 == \"Mom Dad Cross (Top Dog Trading)\" ? TopDogMomOverDad :
TrendBar1 == \"DAD Direction (Top Dog Trading)\" ? TopDogDadDirection :
TrendBar1 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? RSISigCross :
TrendBar1 == \"RSI 5: > or < 50\" ? RSI5Above50 :
TrendBar1 == \"RSI 13: > or < 50\" ? RSI13Above50 :
TrendBar1 == \"Trend Candles\" ? TrendBarTrend_Candle : na
TrendBar2Result = TrendBar2 == \"MA Crossover\" ? MACrossover1 :
TrendBar2 == \"MACD Crossover - 12, 26, 9\" ? MACDHistogramCross :
TrendBar2 == \"MACD Crossover - Fast - 8, 21, 5\" ? FastMACDHistogramCross :
TrendBar2 == \"Mom Dad Cross (Top Dog Trading)\" ? TopDogMomOverDad :
TrendBar2 == \"DAD Direction (Top Dog Trading)\" ? TopDogDadDirection :
TrendBar2 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? RSISigCross :
TrendBar2 == \"RSI 5: > or < 50\" ? RSI5Above50 :
TrendBar2 == \"RSI 13: > or < 50\" ? RSI13Above50 :
TrendBar2 == \"Trend Candles\" ? TrendBarTrend_Candle : na
TrendBar3Result = TrendBar3 == \"MA Crossover\" ? MACrossover1 :
TrendBar3 == \"MACD Crossover - 12, 26, 9\" ? MACDHistogramCross :
TrendBar3 == \"MACD Crossover - Fast - 8, 21, 5\" ? FastMACDHistogramCross :
TrendBar3 == \"Mom Dad Cross (Top Dog Trading)\" ? TopDogMomOverDad :
TrendBar3 == \"DAD Direction (Top Dog Trading)\" ? TopDogDadDirection :
TrendBar3 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? RSISigCross :
TrendBar3 == \"RSI 5: > or < 50\" ? RSI5Above50 :
TrendBar3 == \"RSI 13: > or < 50\" ? RSI13Above50 :
TrendBar3 == \"Trend Candles\" ? TrendBarTrend_Candle : na
TrendBars2Positive = TrendBar1Result and TrendBar2Result or TrendBar1Result and TrendBar3Result or
TrendBar2Result and TrendBar3Result ? 1 : 0
TrendBars2Negative = not TrendBar1Result and not TrendBar2Result or
not TrendBar1Result and not TrendBar3Result or
not TrendBar2Result and not TrendBar3Result ? 1 : 0
TrendBars3Positive = TrendBar1Result and TrendBar2Result and TrendBar3Result ? 1 : 0
TrendBars3Negative = not TrendBar1Result and not TrendBar2Result and not TrendBar3Result ? 1 : 0
FilterXUp = FastMACDHistogramCross and ta.ema(vclose, 15) > ta.ema(vclose, 15)[1]
FilterXDown = not FastMACDHistogramCross and ta.ema(vclose, 15) < ta.ema(vclose, 15)[1]
TrendFilterPlus = ta.ema(vclose, 15) > ta.ema(vclose, 20) and ta.ema(vclose, 20) > ta.ema(vclose, 30) and
ta.ema(vclose, 30) > ta.ema(vclose, 40) and ta.ema(vclose, 40) > ta.ema(vclose, 50) ? 1 : 0
TrendFilterMinus = ta.ema(vclose, 15) < ta.ema(vclose, 20) and ta.ema(vclose, 20) < ta.ema(vclose, 30) and
ta.ema(vclose, 30) < ta.ema(vclose, 40) and ta.ema(vclose, 40) < ta.ema(vclose, 50) ? 1 : 0
// // Wave Trend - Conditions
// WTCross = cross(wt1, wt2)
// WTCrossUp = wt2 - wt1 <= 0
// WTCrossDown = wt2 - wt1 >= 0
// WTOverSold = wt2 <= osLevel2
// WTOverBought = wt2 >= obLevel2
MSBar1PositiveWaveTrendSignal = MSBar1 == \"Filter X\" ? FilterXUp and WTCross and WTCrossUp :
MSBar1 == \"Trend Filter\" ? TrendFilterPlus and WTCross and WTCrossUp :
MSBar1 == \"Filter X + Trend Filter\" ?
FilterXUp and TrendFilterPlus and WTCross and WTCrossUp : WTCross and WTCrossUp
MSBar1NegativeWaveTrendSignal = MSBar1 == \"Filter X\" ? FilterXDown and WTCross and WTCrossDown :
MSBar1 == \"Trend Filter\" ? TrendFilterMinus and WTCross and WTCrossDown :
MSBar1 == \"Filter X + Trend Filter\" ?
FilterXDown and TrendFilterMinus and WTCross and WTCrossDown :
WTCross and WTCrossDown
MSBar2PositiveWaveTrendSignal = MSBar2 == \"Filter X\" ? FilterXUp and WTCross and WTCrossUp :
MSBar2 == \"Trend Filter\" ? TrendFilterPlus and WTCross and WTCrossUp :
MSBar2 == \"Filter X + Trend Filter\" ?
FilterXUp and TrendFilterPlus and WTCross and WTCrossUp : WTCross and WTCrossUp
MSBar2NegativeWaveTrendSignal = MSBar2 == \"Filter X\" ? FilterXDown and WTCross and WTCrossDown :
MSBar2 == \"Trend Filter\" ? TrendFilterMinus and WTCross and WTCrossDown :
MSBar2 == \"Filter X + Trend Filter\" ?
FilterXDown and TrendFilterMinus and WTCross and WTCrossDown :
WTCross and WTCrossDown
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
BackgroundColorChangePositive = TrendBars3Positive and not TrendBars3Positive[1]
BackgroundColorChangeNegative = TrendBars3Negative and not TrendBars3Negative[1]
// Signals Color Calculations
MSBar1Color = MSBar1PositiveWaveTrendSignal ? #288a75 :
MSBar1NegativeWaveTrendSignal ? color.red : na
MSBar2Color = BackgroundColorChangePositive ? #288a75 :
BackgroundColorChangeNegative ? color.red : na
// Trend Barmeter Color Assignments
TrendBar1Color = TrendBar1 == \"N/A\" ? na :
TrendBar1 == \"MACD Crossover - 12, 26, 9\" ? TrendBarMACDColor :
TrendBar1 == \"MACD Crossover - Fast - 8, 21, 5\" ? TrendBarFastMACDColor :
TrendBar1 == \"Mom Dad Cross (Top Dog Trading)\" ? TrendBarMomOverDadColor :
TrendBar1 == \"DAD Direction (Top Dog Trading)\" ? TrendBarDadDirectionColor :
TrendBar1 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? TrendBarRSISigCrossColor :
TrendBar1 == \"RSI 5: > or < 50\" ? TrendBarRSI5Color :
TrendBar1 == \"RSI 13: > or < 50\" ? TrendBarRSI13Color :
TrendBar1 == \"Trend Candles\" ? TrendBarTrend_Candle_Color :
TrendBar1 == \"MA Crossover\" ? TrendBarMACrossColor : na
TrendBar2Color = TrendBar2 == \"N/A\" ? na :
TrendBar2 == \"MACD Crossover - 12, 26, 9\" ? TrendBarMACDColor :
TrendBar2 == \"MACD Crossover - Fast - 8, 21, 5\" ? TrendBarFastMACDColor :
TrendBar2 == \"Mom Dad Cross (Top Dog Trading)\" ? TrendBarMomOverDadColor :
TrendBar2 == \"DAD Direction (Top Dog Trading)\" ? TrendBarDadDirectionColor :
TrendBar2 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? TrendBarRSISigCrossColor :
TrendBar2 == \"RSI 5: > or < 50\" ? TrendBarRSI5Color :
TrendBar2 == \"RSI 13: > or < 50\" ? TrendBarRSI13Color :
TrendBar2 == \"Trend Candles\" ? TrendBarTrend_Candle_Color :
TrendBar2 == \"MA Crossover\" ? TrendBarMACrossColor : na
TrendBar3Color = TrendBar3 == \"N/A\" ? na :
TrendBar3 == \"MACD Crossover - 12, 26, 9\" ? TrendBarMACDColor :
TrendBar3 == \"MACD Crossover - Fast - 8, 21, 5\" ? TrendBarFastMACDColor :
TrendBar3 == \"Mom Dad Cross (Top Dog Trading)\" ? TrendBarMomOverDadColor :
TrendBar3 == \"DAD Direction (Top Dog Trading)\" ? TrendBarDadDirectionColor :
TrendBar3 == \"RSI Signal Line Cross - RSI 13, Sig 21\" ? TrendBarRSISigCrossColor :
TrendBar3 == \"RSI 5: > or < 50\" ? TrendBarRSI5Color :
TrendBar3 == \"RSI 13: > or < 50\" ? TrendBarRSI13Color :
TrendBar3 == \"Trend Candles\" ? TrendBarTrend_Candle_Color :
TrendBar3 == \"MA Crossover\" ? TrendBarMACrossColor : na
CrossoverType2 = TrendBar4 == \"DAD Direction (Top Dog Trading)\" ? TopDogDadDirection :
TrendBar4 == \"MACD Crossover\" ? MACDHistogramCross :
TrendBar4 == \"MA Direction - Fast MA - TB1\" ? MA1Direction :
TrendBar4 == \"MA Direction - Slow MA - TB1\" ? MA2Direction : MACrossover1
color_1 = color.green
color_2 = color.red
TrendBar4Color1 = TrendBar4 == \"N/A\" ? na : CrossoverType2 ? color_1 : color_2
// TrendBar4Color2 = TrendBar4==\"N/A\" ? na : TrendBar4==\"DAD Direction (Top Dog Trading)\" and TopDogDadDirectandMomOverZero ? color(green, 70) : TrendBar4==\"DAD Direction (Top Dog Trading)\" and TopDogDadDirectandMomUnderZero ? color(red, 70) : TrendBar4==\"MACD Crossover - 12, 26, 9\" and MACDLineOverZeroandHistogramCross ? color(green, 70) : TrendBar4==\"MACD Crossover - 12, 26, 9\" and MACDLineUnderZeroandHistogramCross ? color(red, 70) : TrendBar4==\"MA Crossover\" and CrossoverType2 ? color(green, 40) : TrendBar4==\"MA Crossover\" and not CrossoverType2 ? color(red, 40) : TrendBar4==\"MA Direction - Fast MA\" and CrossoverType2 ? color(green, 40) : TrendBar4==\"MA Direction - Fast MA\" and not CrossoverType2 ? color(red, 40) : na
CrossoverType3 = TrendBar5 == \"DAD Direction (Top Dog Trading)\" ? TopDogDadDirection :
TrendBar5 == \"MACD Crossover\" ? MACDHistogramCross :
TrendBar5 == \"MA Direction - Fast MA - TB2\" ? MA3Direction :
TrendBar5 == \"MA Direction - Slow MA - TB2\" ? MA4Direction : MACrossover2
color_3 = color.green
color_4 = color.red
TrendBar5Color1 = TrendBar5 == \"N/A\" ? na : CrossoverType3 ? color_3 : color_4
trenbar1color = ShowTrendBar and not(TrendBar5 == \"N/A\") ? TrendBar4Color1 : na
trenbar2color = ShowTrendBar and not(TrendBar4 == \"N/A\") ? TrendBar5Color1 : na
[trenbar1color, trenbar2color]
\'\'\'
标签: tradingview-api pinescript-v5