使用了 'series bool' 类型的参数,但需要 'simple float'
An argument of 'series bool' type was used but a 'simple float' is expected
我希望在 SMA 3 越过 SMA 7 时触发多头入场警报条件,并且这应该发生在高斯通道的下频带下方。错误消息如下:'' 使用了 'series bool' 类型的参数,但需要 'simple float' ''。我试图将系列布尔值转换为简单的浮点数,但没有成功。如果有人可以帮我解决这个问题,我将不胜感激。
谢谢
//@version=5
indicator('Gauss and SMA', shorttitle='Gauss and SMA', overlay=true)
///
/// Gaussian Channel
///
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//indicator(title='Gaussian Channel [DW]', shorttitle='GC [DW]', overlay=true)
// This study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity.
// Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times.
// First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this script is 9.
// Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode".
// Then the alpha and source values are used to calculate the filter and filtered true range of the dataset.
// Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel.
// Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode".
//Custom bar colors are included.
//Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is.
// Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag.
// For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower truncates the equation.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Updates:
// Huge shoutout to @e2e4mfck for taking the time to improve the calculation method!
// -> migrated to v4
// -> pi is now calculated using trig identities rather than being explicitly defined.
// -> The filter calculations are now organized into functions rather than being individually defined.
// -> Revamped color scheme.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions - courtesy of @e2e4mfck
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter function
f_filt9x(_a, _s, _i) =>
int _m2 = 0
int _m3 = 0
int _m4 = 0
int _m5 = 0
int _m6 = 0
int _m7 = 0
int _m8 = 0
int _m9 = 0
float _f = .0
_x = 1 - _a
// Weights.
// Initial weight _m1 is a pole number and equal to _i
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
// filter
_f := math.pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ? _m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ? _m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * math.pow(_x, 9) * nz(_f[9]) : 0)
_f
//9 var declaration fun
f_pole(_a, _s, _i) =>
_f1 = f_filt9x(_a, _s, 1)
_f2 = _i >= 2 ? f_filt9x(_a, _s, 2) : 0
_f3 = _i >= 3 ? f_filt9x(_a, _s, 3) : 0
_f4 = _i >= 4 ? f_filt9x(_a, _s, 4) : 0
_f5 = _i >= 5 ? f_filt9x(_a, _s, 5) : 0
_f6 = _i >= 6 ? f_filt9x(_a, _s, 6) : 0
_f7 = _i >= 2 ? f_filt9x(_a, _s, 7) : 0
_f8 = _i >= 8 ? f_filt9x(_a, _s, 8) : 0
_f9 = _i == 9 ? f_filt9x(_a, _s, 9) : 0
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source
src = input(defval=hlc3, title='Source')
//Poles
int N = input.int(defval=4, title='Poles', minval=1, maxval=9)
//Period
int per = input.int(defval=144, title='Sampling Period', minval=2)
//True Range Multiplier
float mult = input.float(defval=1.414, title='Filtered True Range Multiplier', minval=0)
//Lag Reduction
bool modeLag = input(defval=false, title='Reduced Lag Mode')
bool modeFast = input(defval=false, title='Fast Response Mode')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Beta and Alpha Components
beta = (1 - math.cos(4 * math.asin(1) / per)) / (math.pow(1.414, 2 / N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
//Lag
lag = (per - 1) / (2 * N)
//Data
srcdata = modeLag ? src + src - src[lag] : src
trdata = modeLag ? ta.tr(true) + ta.tr(true) - ta.tr(true)[lag] : ta.tr(true)
//Filtered Values
[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)
//Lag Reduction
filt = modeFast ? (filtn + filt1) / 2 : filtn
filttr = modeFast ? (filtntr + filt1tr) / 2 : filtntr
//Bands
hband = filt + filttr * mult
lband = filt - filttr * mult
// Colors
color1 = #0aff68
color2 = #00752d
color3 = #ff0a5a
color4 = #990032
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
//barcolor = src > src[1] and src > filt and src < hband ? #0aff68 : src > src[1] and src >= hband ? #0aff1b : src <= src[1] and src > filt ? #00752d : src < src[1] and src < filt and src > lband ? #ff0a5a : src < src[1] and src <= lband ? #ff0a11 : src >= src[1] and src < filt ? #990032 : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter Plot
filtplot = plot(filt, title='Filter', color=fcolor, linewidth=3)
//Band Plots
hbandplot = plot(hband, title='Filtered True Range High Band', color=fcolor)
lbandplot = plot(lband, title='Filtered True Range Low Band', color=fcolor)
//Channel Fill
fill(hbandplot, lbandplot, title='Channel Fill', color=color.new(fcolor, 80))
//Bar Color
//barcolor(barcolor)
///
/// SMA
///
//indicator('SMA 11-21-50-200', shorttitle='SMA 11-21-50-200', overlay=true)
len0 = input.int(3, minval=1, title='Length Tip 1', group="SMA")
src0 = input(close, title='Source Tip 1', group="SMA")
smma0 = 0.0
sma_0 = ta.sma(src0, len0)
smma0 := na(smma0[1]) ? sma_0 : (smma0[1] * (len0 - 1) + src0) / len0
plot(smma0, title="SMA Type 1", color=color.new(color.green, 0), linewidth=2)
len1 = input.int(7, minval=1, title='Length Tip 2', group="SMA")
src1 = input(close, title='Source Tip 2', group="SMA")
smma1 = 0.0
sma_1 = ta.sma(src1, len1)
smma1 := na(smma1[1]) ? sma_1 : (smma1[1] * (len1 - 1) + src1) / len1
plot(smma1, title="SMA Type 2", color=color.new(color.navy, 0), linewidth=2)
len2 = input.int(50, minval=1, title='Length Tip 3', group="SMA")
src2 = input(close, title='Source Tip 3', group="SMA")
smma2 = 0.0
sma_2 = ta.sma(src2, len2)
smma2 := na(smma2[1]) ? sma_2 : (smma2[1] * (len2 - 1) + src2) / len2
plot(smma2, title="SMA Type 3", color=color.new(color.purple, 0), linewidth=2)
len3 = input.int(200, minval=1, title='Length Tip 4', group="SMA")
src3 = input(close, title='Source Tip 4', group="SMA")
smma3 = 0.0
sma_3 = ta.sma(src3, len3)
smma3 := na(smma3[1]) ? sma_3 : (smma3[1] * (len3 - 1) + src3) / len3
plot(smma3, title="SMA Type 4", color=color.new(color.yellow, 0), linewidth=2)
/////////////////////////////////////////
///// QUESTION = I would like to have an alertcondition for Long Entry that will be triggered when SMA 3 crosses under SMA 7, and this should happen below the lower band of the Gaussian Channel.
///// How is it possible to integrate this to the script? Thank you
/////////////////////////////////////////
// SMA 3 crosses over SMA 7
SMAcrossover = ta.crossover(sma_0, sma_1)
plotshape(SMAcrossover ? low : na, title='SMA3-7 crossover', text='SMA3-7\nCrossover\n', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
// SMA 3 crosses over sMA 7, and this happens below the lower Gaussian channel
LongEntry = SMAcrossover < lband
// Alert Condition
alertcondition(LongEntry, title="SMA3-7 crossover below the lower channel", message=" SMA3-7 crossover below the lower channel")
SMAcrossover
是 bool
类型,lband
是 float
。您不能将 bool
与 float
进行比较。
您实际上是将 sma 值或价格与 lband
进行比较。
下面的代码检查交叉是否发生,以及此时 sma3
是否低于 lband
。
// SMA 3 crosses over sMA 7, and this happens below the lower Gaussian channel
LongEntry = SMAcrossover and (sma_0 < lband)
我希望在 SMA 3 越过 SMA 7 时触发多头入场警报条件,并且这应该发生在高斯通道的下频带下方。错误消息如下:'' 使用了 'series bool' 类型的参数,但需要 'simple float' ''。我试图将系列布尔值转换为简单的浮点数,但没有成功。如果有人可以帮我解决这个问题,我将不胜感激。 谢谢
//@version=5
indicator('Gauss and SMA', shorttitle='Gauss and SMA', overlay=true)
///
/// Gaussian Channel
///
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//indicator(title='Gaussian Channel [DW]', shorttitle='GC [DW]', overlay=true)
// This study is an experiment utilizing the Ehlers Gaussian Filter technique combined with lag reduction techniques and true range to analyze trend activity.
// Gaussian filters, as Ehlers explains it, are simply exponential moving averages applied multiple times.
// First, beta and alpha are calculated based on the sampling period and number of poles specified. The maximum number of poles available in this script is 9.
// Next, the data being analyzed is given a truncation option for reduced lag, which can be enabled with "Reduced Lag Mode".
// Then the alpha and source values are used to calculate the filter and filtered true range of the dataset.
// Filtered true range with a specified multiplier is then added to and subtracted from the filter, generating a channel.
// Lastly, a one pole filter with a N pole alpha is averaged with the filter to generate a faster filter, which can be enabled with "Fast Response Mode".
//Custom bar colors are included.
//Note: Both the sampling period and number of poles directly affect how much lag the indicator has, and how smooth the output is.
// Larger inputs will result in smoother outputs with increased lag, and smaller inputs will have noisier outputs with reduced lag.
// For the best results, I recommend not setting the sampling period any lower than the number of poles + 1. Going lower truncates the equation.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Updates:
// Huge shoutout to @e2e4mfck for taking the time to improve the calculation method!
// -> migrated to v4
// -> pi is now calculated using trig identities rather than being explicitly defined.
// -> The filter calculations are now organized into functions rather than being individually defined.
// -> Revamped color scheme.
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Functions - courtesy of @e2e4mfck
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter function
f_filt9x(_a, _s, _i) =>
int _m2 = 0
int _m3 = 0
int _m4 = 0
int _m5 = 0
int _m6 = 0
int _m7 = 0
int _m8 = 0
int _m9 = 0
float _f = .0
_x = 1 - _a
// Weights.
// Initial weight _m1 is a pole number and equal to _i
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
// filter
_f := math.pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ? _m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ? _m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * math.pow(_x, 9) * nz(_f[9]) : 0)
_f
//9 var declaration fun
f_pole(_a, _s, _i) =>
_f1 = f_filt9x(_a, _s, 1)
_f2 = _i >= 2 ? f_filt9x(_a, _s, 2) : 0
_f3 = _i >= 3 ? f_filt9x(_a, _s, 3) : 0
_f4 = _i >= 4 ? f_filt9x(_a, _s, 4) : 0
_f5 = _i >= 5 ? f_filt9x(_a, _s, 5) : 0
_f6 = _i >= 6 ? f_filt9x(_a, _s, 6) : 0
_f7 = _i >= 2 ? f_filt9x(_a, _s, 7) : 0
_f8 = _i >= 8 ? f_filt9x(_a, _s, 8) : 0
_f9 = _i == 9 ? f_filt9x(_a, _s, 9) : 0
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Inputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Source
src = input(defval=hlc3, title='Source')
//Poles
int N = input.int(defval=4, title='Poles', minval=1, maxval=9)
//Period
int per = input.int(defval=144, title='Sampling Period', minval=2)
//True Range Multiplier
float mult = input.float(defval=1.414, title='Filtered True Range Multiplier', minval=0)
//Lag Reduction
bool modeLag = input(defval=false, title='Reduced Lag Mode')
bool modeFast = input(defval=false, title='Fast Response Mode')
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Definitions
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Beta and Alpha Components
beta = (1 - math.cos(4 * math.asin(1) / per)) / (math.pow(1.414, 2 / N) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
//Lag
lag = (per - 1) / (2 * N)
//Data
srcdata = modeLag ? src + src - src[lag] : src
trdata = modeLag ? ta.tr(true) + ta.tr(true) - ta.tr(true)[lag] : ta.tr(true)
//Filtered Values
[filtn, filt1] = f_pole(alpha, srcdata, N)
[filtntr, filt1tr] = f_pole(alpha, trdata, N)
//Lag Reduction
filt = modeFast ? (filtn + filt1) / 2 : filtn
filttr = modeFast ? (filtntr + filt1tr) / 2 : filtntr
//Bands
hband = filt + filttr * mult
lband = filt - filttr * mult
// Colors
color1 = #0aff68
color2 = #00752d
color3 = #ff0a5a
color4 = #990032
fcolor = filt > filt[1] ? #0aff68 : filt < filt[1] ? #ff0a5a : #cccccc
//barcolor = src > src[1] and src > filt and src < hband ? #0aff68 : src > src[1] and src >= hband ? #0aff1b : src <= src[1] and src > filt ? #00752d : src < src[1] and src < filt and src > lband ? #ff0a5a : src < src[1] and src <= lband ? #ff0a11 : src >= src[1] and src < filt ? #990032 : #cccccc
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Outputs
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
//Filter Plot
filtplot = plot(filt, title='Filter', color=fcolor, linewidth=3)
//Band Plots
hbandplot = plot(hband, title='Filtered True Range High Band', color=fcolor)
lbandplot = plot(lband, title='Filtered True Range Low Band', color=fcolor)
//Channel Fill
fill(hbandplot, lbandplot, title='Channel Fill', color=color.new(fcolor, 80))
//Bar Color
//barcolor(barcolor)
///
/// SMA
///
//indicator('SMA 11-21-50-200', shorttitle='SMA 11-21-50-200', overlay=true)
len0 = input.int(3, minval=1, title='Length Tip 1', group="SMA")
src0 = input(close, title='Source Tip 1', group="SMA")
smma0 = 0.0
sma_0 = ta.sma(src0, len0)
smma0 := na(smma0[1]) ? sma_0 : (smma0[1] * (len0 - 1) + src0) / len0
plot(smma0, title="SMA Type 1", color=color.new(color.green, 0), linewidth=2)
len1 = input.int(7, minval=1, title='Length Tip 2', group="SMA")
src1 = input(close, title='Source Tip 2', group="SMA")
smma1 = 0.0
sma_1 = ta.sma(src1, len1)
smma1 := na(smma1[1]) ? sma_1 : (smma1[1] * (len1 - 1) + src1) / len1
plot(smma1, title="SMA Type 2", color=color.new(color.navy, 0), linewidth=2)
len2 = input.int(50, minval=1, title='Length Tip 3', group="SMA")
src2 = input(close, title='Source Tip 3', group="SMA")
smma2 = 0.0
sma_2 = ta.sma(src2, len2)
smma2 := na(smma2[1]) ? sma_2 : (smma2[1] * (len2 - 1) + src2) / len2
plot(smma2, title="SMA Type 3", color=color.new(color.purple, 0), linewidth=2)
len3 = input.int(200, minval=1, title='Length Tip 4', group="SMA")
src3 = input(close, title='Source Tip 4', group="SMA")
smma3 = 0.0
sma_3 = ta.sma(src3, len3)
smma3 := na(smma3[1]) ? sma_3 : (smma3[1] * (len3 - 1) + src3) / len3
plot(smma3, title="SMA Type 4", color=color.new(color.yellow, 0), linewidth=2)
/////////////////////////////////////////
///// QUESTION = I would like to have an alertcondition for Long Entry that will be triggered when SMA 3 crosses under SMA 7, and this should happen below the lower band of the Gaussian Channel.
///// How is it possible to integrate this to the script? Thank you
/////////////////////////////////////////
// SMA 3 crosses over SMA 7
SMAcrossover = ta.crossover(sma_0, sma_1)
plotshape(SMAcrossover ? low : na, title='SMA3-7 crossover', text='SMA3-7\nCrossover\n', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), size=size.tiny)
// SMA 3 crosses over sMA 7, and this happens below the lower Gaussian channel
LongEntry = SMAcrossover < lband
// Alert Condition
alertcondition(LongEntry, title="SMA3-7 crossover below the lower channel", message=" SMA3-7 crossover below the lower channel")
SMAcrossover
是 bool
类型,lband
是 float
。您不能将 bool
与 float
进行比较。
您实际上是将 sma 值或价格与 lband
进行比较。
下面的代码检查交叉是否发生,以及此时 sma3
是否低于 lband
。
// SMA 3 crosses over sMA 7, and this happens below the lower Gaussian channel
LongEntry = SMAcrossover and (sma_0 < lband)