检查条件顺序
Checking the sequence of conditions
我们需要代码,在给定特定信号的情况下,检查是否满足信号条件,而不管时间间隔如何。
例如,有一定的条件顺序,如果这些条件符合,则在LIME标记处显示信号。
信号条件:RED YELLO LIME
一些条件:
1 2 3 4 5 6 7 8 9 10 11 12 13
- 在这个例子中,信号应该只显示在位置11,因为9、10和11位置确认了信号。
完成,感谢 Bjorn Mistiaen 的提示
位置结果 01/08/2022 22:00 UTC,01/09/2022 18:10 UTC 和...等
// I recommend looking at the chart BTCUSDT 5M
// Position results 01/08/2022 22:00 UTC, 01/09/2022 18:10 UTC
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
// Variant with specific values TOP DOWN //For example - there can be any other condition - true / false.
if01 = close < 41600 and close > 40500 //Condition 1. Red.
if02 = close < 41750 and close > 41650 //Condition 2. Yellow.
if03 = close < 42100 and close > 42000 //Condition 3. Lime.
// To work with volume Close
plotSignal = false
var bufferR = 0 // Red signal buffer
var bufferY = 0 // Red signal buffer
// Red signals
if if01
bufferR:=1
if if03 and bufferY != 1 // Red buffer clear condition
bufferR:=0
// Yellow signals
if if02 and bufferR == 1 // Yellow Buffer Accumulation Condition
bufferY+=1
if if01 // Yellow buffer clear condition
bufferY:=0
// Lime signals / all signal conditions are met
if if03 and bufferR == 1 and bufferY == 1
plotSignal:=true
// Clear all buffer
bufferR:=0
bufferY:=0
plotchar(plotSignal, char='', size = size.normal, location=location.top)
plotchar(if01, char='!', size = size.tiny, color=color.new(color.red, 0))
plotchar(if02, char='!', size = size.tiny, color=color.new(color.yellow, 0))
plotchar(if03, char='!', size = size.tiny, color=color.new(color.lime, 0))
plot(bufferR, color=color.new(color.red, 0))
plot(bufferY, color=color.new(color.yellow, 0))
这应该符合您的预期。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var int offset = input.int(30, 'Offset', 0) // Check period
var bool if01 = close > 40000 // Condition 1 for example - there can be any other condition - true / false
var bool if02 = close > 50000 // Condition 2
var bool if03 = close > 60000 // Condition 3
var bool n4 = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
var int barCount = 0
// once a signal is triggered, keep it triggered until reset
// next signal (for example if03) can only trigger if previous signal (for example if02) is triggered
if01_triggered := if01_triggered[1] or if01
if02_triggered := if02_triggered[1] or (if02 and if01_triggered)
if03_triggered := if03_triggered[1] or (if03 and if02_triggered)
// first signal triggered?
if if01_triggered
// start counting bars
barCount += 1
// last signal triggered?
if if03_triggered
// final signal (to plot) becomes true
n4 := true
// last signal triggered, or barCount exceeds offset?
if if03_triggered or barCount >= offset
// reset barCount
barCount := 0
// reset triggers
if01_triggered := false
if02_triggered := false
if03_triggered := false
// reset final signal (to plot)
n4 := false
plotchar(n4, char='', size = size.normal, location=location.top)
编辑 1 以响应
我发现我之前的代码有误,因为一旦if03
被触发,并且将n4
设置为true
,它会立即再次重置,所以n4
永远不会是 true
.
这应该可以解决问题。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var int offset = input.int(30, 'Offset', 0) // Check period
var bool if01 = close > 40000 // Condition 1 for example - there can be any other condition - true / false
var bool if02 = close > 50000 // Condition 2
var bool if03 = close > 60000 // Condition 3
var bool n4 = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
var int barCount = 0
// last signal triggered, or barCount exceeds offset?
if if03_triggered[1] or barCount >= offset
// reset barCount
barCount := 0
// reset triggers
if01_triggered := false
if02_triggered := false
if03_triggered := false
// reset final signal (to plot)
n4 := false
// once a signal is triggered, keep it triggered until reset
// next signal (for example if03) can only trigger if previous signal (for example if02) is triggered
if01_triggered := if01_triggered[1] or if01
if02_triggered := if02_triggered[1] or (if02 and if01_triggered)
if03_triggered := if03_triggered[1] or (if03 and if02_triggered)
// first signal triggered?
if if01_triggered
// start counting bars
barCount += 1
// last signal triggered?
if if03_triggered
// final signal (to plot) becomes true
n4 := true
plotchar(n4, char='', size = size.normal, location=location.top)
此外,如果您没有找到解决方案,请编辑您的问题和 post 您的整个代码,因为处理实际代码总是比处理伪代码容易。这样社区就能更好地帮助你。
编辑 2
我刚刚注意到您使用代码示例编辑了您的问题。
根据您的示例,这应该有效。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var color c_red = color.new(color.red, 0)
var color c_yellow = color.new(color.yellow, 0)
var color c_lime = color.new(color.lime, 0)
var bool plotSignal = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
if01 = close < 41350 and close > 41240 //Condition 1. Red.
if02 = close < 41400 and close > 41295 //Condition 2. Yellow.
if03 = close < 41650 and close > 41540 //Condition 3. Lime. For example - there can be any other condition - true / false.
if plotSignal[1]
if01_triggered := false
if02_triggered := false
if03_triggered := false
plotSignal := false
if01_triggered := if01_triggered or if01
if02_triggered := if02_triggered or (if02 and if01_triggered)
if03_triggered := if03_triggered or (if03 and if02_triggered)
if if03_triggered
plotSignal := true
plotchar(if01, 'if01', '!', location.belowbar, c_red, size = size.tiny)
plotchar(if02, 'if02', '!', location.belowbar, c_yellow, size = size.tiny)
plotchar(if03, 'if03', '!', location.belowbar, c_lime, size = size.tiny)
plotchar(plotSignal, 'plotSignal', '', location.top, size = size.small)
我们需要代码,在给定特定信号的情况下,检查是否满足信号条件,而不管时间间隔如何。
例如,有一定的条件顺序,如果这些条件符合,则在LIME标记处显示信号。 信号条件:RED YELLO LIME 一些条件: 1 2 3 4 5 6 7 8 9 10 11 12 13
- 在这个例子中,信号应该只显示在位置11,因为9、10和11位置确认了信号。
完成,感谢 Bjorn Mistiaen 的提示 位置结果 01/08/2022 22:00 UTC,01/09/2022 18:10 UTC 和...等
// I recommend looking at the chart BTCUSDT 5M
// Position results 01/08/2022 22:00 UTC, 01/09/2022 18:10 UTC
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
// Variant with specific values TOP DOWN //For example - there can be any other condition - true / false.
if01 = close < 41600 and close > 40500 //Condition 1. Red.
if02 = close < 41750 and close > 41650 //Condition 2. Yellow.
if03 = close < 42100 and close > 42000 //Condition 3. Lime.
// To work with volume Close
plotSignal = false
var bufferR = 0 // Red signal buffer
var bufferY = 0 // Red signal buffer
// Red signals
if if01
bufferR:=1
if if03 and bufferY != 1 // Red buffer clear condition
bufferR:=0
// Yellow signals
if if02 and bufferR == 1 // Yellow Buffer Accumulation Condition
bufferY+=1
if if01 // Yellow buffer clear condition
bufferY:=0
// Lime signals / all signal conditions are met
if if03 and bufferR == 1 and bufferY == 1
plotSignal:=true
// Clear all buffer
bufferR:=0
bufferY:=0
plotchar(plotSignal, char='', size = size.normal, location=location.top)
plotchar(if01, char='!', size = size.tiny, color=color.new(color.red, 0))
plotchar(if02, char='!', size = size.tiny, color=color.new(color.yellow, 0))
plotchar(if03, char='!', size = size.tiny, color=color.new(color.lime, 0))
plot(bufferR, color=color.new(color.red, 0))
plot(bufferY, color=color.new(color.yellow, 0))
这应该符合您的预期。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var int offset = input.int(30, 'Offset', 0) // Check period
var bool if01 = close > 40000 // Condition 1 for example - there can be any other condition - true / false
var bool if02 = close > 50000 // Condition 2
var bool if03 = close > 60000 // Condition 3
var bool n4 = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
var int barCount = 0
// once a signal is triggered, keep it triggered until reset
// next signal (for example if03) can only trigger if previous signal (for example if02) is triggered
if01_triggered := if01_triggered[1] or if01
if02_triggered := if02_triggered[1] or (if02 and if01_triggered)
if03_triggered := if03_triggered[1] or (if03 and if02_triggered)
// first signal triggered?
if if01_triggered
// start counting bars
barCount += 1
// last signal triggered?
if if03_triggered
// final signal (to plot) becomes true
n4 := true
// last signal triggered, or barCount exceeds offset?
if if03_triggered or barCount >= offset
// reset barCount
barCount := 0
// reset triggers
if01_triggered := false
if02_triggered := false
if03_triggered := false
// reset final signal (to plot)
n4 := false
plotchar(n4, char='', size = size.normal, location=location.top)
编辑 1 以响应
我发现我之前的代码有误,因为一旦if03
被触发,并且将n4
设置为true
,它会立即再次重置,所以n4
永远不会是 true
.
这应该可以解决问题。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var int offset = input.int(30, 'Offset', 0) // Check period
var bool if01 = close > 40000 // Condition 1 for example - there can be any other condition - true / false
var bool if02 = close > 50000 // Condition 2
var bool if03 = close > 60000 // Condition 3
var bool n4 = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
var int barCount = 0
// last signal triggered, or barCount exceeds offset?
if if03_triggered[1] or barCount >= offset
// reset barCount
barCount := 0
// reset triggers
if01_triggered := false
if02_triggered := false
if03_triggered := false
// reset final signal (to plot)
n4 := false
// once a signal is triggered, keep it triggered until reset
// next signal (for example if03) can only trigger if previous signal (for example if02) is triggered
if01_triggered := if01_triggered[1] or if01
if02_triggered := if02_triggered[1] or (if02 and if01_triggered)
if03_triggered := if03_triggered[1] or (if03 and if02_triggered)
// first signal triggered?
if if01_triggered
// start counting bars
barCount += 1
// last signal triggered?
if if03_triggered
// final signal (to plot) becomes true
n4 := true
plotchar(n4, char='', size = size.normal, location=location.top)
此外,如果您没有找到解决方案,请编辑您的问题和 post 您的整个代码,因为处理实际代码总是比处理伪代码容易。这样社区就能更好地帮助你。
编辑 2
我刚刚注意到您使用代码示例编辑了您的问题。
根据您的示例,这应该有效。
//@version=5
indicator("Checking the sequence of conditions", overlay=true)
var color c_red = color.new(color.red, 0)
var color c_yellow = color.new(color.yellow, 0)
var color c_lime = color.new(color.lime, 0)
var bool plotSignal = false
var bool if01_triggered = false
var bool if02_triggered = false
var bool if03_triggered = false
if01 = close < 41350 and close > 41240 //Condition 1. Red.
if02 = close < 41400 and close > 41295 //Condition 2. Yellow.
if03 = close < 41650 and close > 41540 //Condition 3. Lime. For example - there can be any other condition - true / false.
if plotSignal[1]
if01_triggered := false
if02_triggered := false
if03_triggered := false
plotSignal := false
if01_triggered := if01_triggered or if01
if02_triggered := if02_triggered or (if02 and if01_triggered)
if03_triggered := if03_triggered or (if03 and if02_triggered)
if if03_triggered
plotSignal := true
plotchar(if01, 'if01', '!', location.belowbar, c_red, size = size.tiny)
plotchar(if02, 'if02', '!', location.belowbar, c_yellow, size = size.tiny)
plotchar(if03, 'if03', '!', location.belowbar, c_lime, size = size.tiny)
plotchar(plotSignal, 'plotSignal', '', location.top, size = size.small)