给一份在tradingview中设置警报的代码:当15分钟线的最高价和最低价为整数时触发
- User
给一份在tradingview中设置警报的代码:当15分钟线的最高价和最低价为整数时触发
- Assistant
在TradingView中设置条件警报的代码如下:
//@version=4 study(title="整数最高价最低价警报", overlay=true)
// 计算15分钟的最高价和最低价 highestHigh = request.security(syminfo.tickerid, "15", high) lowestLow = request.security(syminfo.tickerid, "15", low)
// 判断最高价和最低价是否为整数 isHighestInt = highestHigh == floor(highestHigh) isLowestInt = lowestLow == floor(lowestLow)
// 触发警报条件:最高价和最低价为整数 alertcondition(isHighestInt and isLowestInt, title="整数最高价和最低价警报", message="最高价和最低价为整数")
在此代码中,我们首先使用request.security函数计算出15分钟的最高价和最低价。然后,使用floor函数来判断最高价和最低价是否为整数。最后,使用alertcondition函数来设置条件警报。如果最高价和最低价都是整数,则触发警报,并显示警报消息"最高价和最低价为整数"。
- User
请用version=5的版本
- Assistant
在 TradingView 中设置警报的代码版本 5 如下所示:
//@version=5 indicator("整数最高价最低价警报", overlay=true)
// 计算15分钟的最高价和最低价 highestHigh = ta.highest(high, 15) lowestLow = ta.lowest(low, 15)
// 判断最高价和最低价是否为整数 isHighestInt = highestHigh == math.floor(highestHigh) isLowestInt = lowestLow == math.floor(lowestLow)
// 触发警报条件:最高价和最低价为整数 alertcondition(isHighestInt and isLowestInt, title="整数最高价和最低价警报", message="最高价和最低价为整数")
在此代码中,我们使用 ta.highest 和 ta.lowest 函数计算 15 分钟的最高价和最低价。然后,使用 math.floor 函数来判断最高价和最低价是否为整数。最后,使用 alertcondition 函数来设置条件警报。如果最高价和最低价都是整数,则触发警报,并显示警报消息"最高价和最低价为整数"。请注意,此代码适用于 TradingView 版本 5。
- User
添加一个附加内容:最高价和最低价为整数时绘图,分别标记为sell和buy
- Assistant
在 TradingView 中设置绘图和警报的代码版本 5 如下所示:
//@version=5 indicator("整数最高价最低价警报", overlay=true) // 计算15分钟的最高价和最低价 highestHigh = ta.highest(high, 15) lowestLow = ta.lowest(low, 15) // 判断最高价和最低价是否为整数 isHighestInt = highestHigh == math.floor(highestHigh) isLowestInt = lowestLow == math.floor(lowestLow) // 绘制信号标记 plotshape(isHighestInt, title="Buy", location=location.belowbar, color=color.green, transp=0, style=shape.labeltext, text="Buy") plotshape(isLowestInt, title="Sell", location=location.abovebar, color=color.red, transp=0, style=shape.labeltext, text="Sell") // 触发警报条件:最高价和最低价为整数 alertcondition(isHighestInt, title="整数最高价警报", message="最高价为整数") alertcondition(isLowestInt, title="整数最低价警报", message="最低价为整数")在更新的代码中,我们添加了
plotshape函数来绘制信号标记。如果最高价为整数,我们使用plotshape绘制一个绿色的 "Buy" 标记在当前柱子下方;如果最低价为整数,我们使用plotshape绘制一个红色的 "Sell" 标记在当前柱子上方。此外,我们保留了之前的警报条件,并更新了
alertcondition函数,使其分别触发 "整数最高价警报" 和 "整数最低价警报"。当最高价和最低价为整数时,将触发相应的警报,同时显示包含相应信息的消息。 - User
请给我一个k线上影线的识别代码
- Assistant
在TradingView中识别K线上影线的代码如下:
//@version=5 indicator("K线上影线识别", overlay=true) // 计算上影线的长度 upperShadowLength = high - max(open, close) // 绘制上影线 plotshape(upperShadowLength > 0, title="Upper Shadow", location=location.abovebar, color=color.red, transp=0, style=shape.labeldown, text="Upper") // 触发警报条件:上影线的长度大于0 alertcondition(upperShadowLength > 0, title="上影线警报", message="检测到K线上影线")在此代码中,我们计算了K线的上影线长度,通过
high - max(open, close)来获取。接着,使用plotshape函数绘制了一个红色的 "Upper" 标记在有上影线的柱子上方。最后,使用alertcondition函数设置了一个条件警报,当上影线长度大于0时触发,同时显示警报消息"检测到K线上影线"。这样,通过该代码,可以识别出K线上是否有上影线,并可根据需要进行相关操作或警报。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.