“数组中的数据仅存在于当前柱形。如何引用历史数值?”

huangapple go评论51阅读模式
英文:

Data from array only exists for current bar. How can I reference historical values?

问题

以下是您提供的代码的翻译部分:

脚本在当前K线上打印了两个标签。这些标签是突破关键水平的看涨和看跌概率。我已将这些字符串拆分,只提取百分比字符串值,并转换为浮点数值,以便可以使用它们创建规则。这些浮点数存储在它们各自的变量"bull_prob"和"bear_prob"中。

问题在于这些变量只包含当前K线的数据,在历史K线上都是零值。我创建了两个新数组bull_hist[]和bear_hist[],并将当前K线的值推送到它们,以便可以在历史上引用它们。当我检查数组大小时,我可以看到它已经推送了所有历史K线的值。然而,除了最后一个索引之外,它们仍然都是零值。

为了测试,我创建了基本的指标规则,简单地表示在看涨蜡烛上买入,在看跌蜡烛上卖出,但也考虑了概率规则是否成立。

当前结果:指标仅在当前K线上正确运行。这意味着在实时或回放期间,规则会适当处理。但除非回放,否则无法看到任何过去的指标。这也意味着如果我将其转换为策略,它将找不到任何交易。

预期结果:bull_prob和bear_prob应该显示在数据窗口中看到的那个K线上的概率值。我目前正在将它们的输出绘制到数据窗口中。以前的指标应该在图表上可见。

希望这有助于您理解代码的翻译部分。如果您有任何进一步的问题或需要进一步的帮助,请随时提问。

英文:

The script prints 2 labels on the current bar. These labels are the bullish and bearish probabilities of breaking a key level. I have split these strings to pull out just the percentage string value and converted to float values so that rules can be created with them. These floats are stored in their respective variables "bull_prob" and "bear_prob".

The problem is these variables only have data on the current bar and zero values on historical bars. I created 2 new arrays bull_hist[] and bear_hist[] and push the current bar value to them so that they can be referenced historically. When I check the array size I can see that it has pushed values for all historical bars. However they are still all zero values except for the last index.

For testing I have created basic indicator rules that simply indicate buy on a bull candle and sell on a bear candle, but also considers if the probability rule is true.

Current result: Indicator works correctly for the current bar only. This means that while live or during replay the rules are processed appropriately. However you cannot see any past indicators unless you replay. This also means if I convert this to a strategy it would find zero trades.

Intended result: bull_prob and bear_prob should show the probability value that existed on that bar as seen in the data window. I'm currently plotting their output to data window. Previous indicators should be visible on the chart.

Full Code:

//@version=5
indicator("Probability Analyzer", overlay = true)
import HeWhoMustNotBeNamed/Logger/2 as log
var logger = log.Logger.new(minimumLevel='Trace', textSize = size.normal)
logger.init()
// Tooltips 
string t1 = "Set the pivot period"
string t2 = "Set the response period. A low value returns a short-term structure and a high value returns a long-term structure.
If you disable this option the pivot length above will be used."
// Inputs
int pa_len = input.int(defval = 20
, title = "Structure Period"
, minval = 1
, tooltip = t1)
int pa_res = input.int(defval = 7
, title = "Structure Response"
, minval = 1
, tooltip = t2)
n        = bar_index 
var pup  = float(na)
var pdn  = float(na)
var piup = int(na)
var pidn = int(na)
// Matrix & Array 
var vals          = matrix.new<float>(9, 4, 0.0)
var string [] txt = array.new<string>(2, "")
// Functions 
Current(v)=>
str = ""
val1 = float(na)
val2 = float(na)
if v >= 0
if v == 1
str  := "SMS: "
val1 := matrix.get(vals, 0, 1)
val2 := matrix.get(vals, 0, 3) 
else if v == 2
str  := "BMS: "
val1 := matrix.get(vals, 1, 1)
val2 := matrix.get(vals, 1, 3) 
else if v > 2
str  := "BMS: "
val1 := matrix.get(vals, 2, 1)
val2 := matrix.get(vals, 2, 3) 
else if v <= 0
if v == -1
str  := "SMS: "
val1 := matrix.get(vals, 3, 1)
val2 := matrix.get(vals, 3, 3) 
else if v == -2
str  := "BMS: "
val1 := matrix.get(vals, 4, 1)
val2 := matrix.get(vals, 4, 3) 
else if v < -2
str  := "BMS: "
val1 := matrix.get(vals, 5, 1)
val2 := matrix.get(vals, 5, 3)
[str, val1, val2]
// ~~ Pivots {
pup     := math.max(pup[1], high)
pdn     := math.min(pdn[1], low)
pa_high  = ta.pivothigh(high, pa_len, pa_len)
pa_low   = ta.pivotlow(low, pa_len, pa_len)
if pa_high
pup := pa_high
else if pa_low
pdn := pa_low
// Structure
var pos = 0
if pup > pup[1]
piup := n
centerBull = math.round(math.avg(piup[1] ,n))
if pos <= 0
pos := 1
matrix.set(vals, 6, 0, matrix.get(vals, 6, 0) + 1)
else if pos == 1 and pup > pup[1] and pup[1] == pup[pa_res]
pos := 2
matrix.set(vals, 6, 1,matrix.get(vals ,6 ,1) + 1)
else if pos > 1 and pup > pup[1] and pup[1] == pup[pa_res]
pos := pos + 1
matrix.set(vals ,6 ,2,matrix.get(vals, 6, 2) + 1)
else if pup < pup[1]
piup := n - pa_len
if pdn < pdn[1]
pidn := n
centerBear = math.round(math.avg(pidn[1], n))
if pos >= 0
pos := -1
matrix.set(vals, 7, 0, matrix.get(vals, 7, 0) + 1)
else if pos == -1 and pdn < pdn[1] and pdn[1] == pdn[pa_res]
pos := -2
matrix.set(vals, 7, 1, matrix.get(vals, 7, 1) + 1)
else if pos < -1 and pdn < pdn[1] and pdn[1] == pdn[pa_res]
pos := pos - 1
matrix.set(vals, 7, 2, matrix.get(vals, 7, 2) + 1)
else if pdn > pdn[1]
pidn := n - pa_len
var float[] bull_hist_txt = array.new_float()
var float[] bear_hist_txt = array.new_float()
// Probability Calculation
if ta.change(pos)
if pos > 0 and pos[1] > 0 or pos < 0 and pos[1] < 0
if  matrix.get(vals, 8, 0) < matrix.get(vals, 8, 1)
matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
else
matrix.set(vals, 8, 3, matrix.get(vals, 8, 3) + 1)
else
if  matrix.get(vals, 8, 0) > matrix.get(vals, 8, 1)
matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
else
matrix.set(vals,8, 3, matrix.get(vals, 8, 3) + 1)
//Score Calulation
float buC0 = matrix.get(vals, 0, 0), float buC1 = matrix.get(vals, 0, 2)
float buS0 = matrix.get(vals, 1, 0), float buS1 = matrix.get(vals, 1, 2)
float buB0 = matrix.get(vals, 2, 0), float buB1 = matrix.get(vals, 2, 2)
float beC0 = matrix.get(vals, 3, 0), float beC1 = matrix.get(vals, 3, 2)
float beS0 = matrix.get(vals, 4, 0), float beS1 = matrix.get(vals, 4, 2)
float beB0 = matrix.get(vals, 5, 0), float beB1 = matrix.get(vals, 5, 2)
float tbuC = matrix.get(vals, 6, 0), float tbuS = matrix.get(vals, 6, 1)
float tbuB = matrix.get(vals, 6, 2), float tbeC = matrix.get(vals, 7, 0)
float tbeS = matrix.get(vals, 7, 1), float tbeB = matrix.get(vals, 7, 2)
// Bull
if (pos[1] == 1 or pos[1] == 0) and pos < 0
matrix.set(vals, 0, 0, buC0 + 1)
matrix.set(vals, 0, 1, math.round(((buC0 + 1) / tbuC) * 100, 2))
if (pos[1] == 1 or pos[1] == 0) and pos == 2
matrix.set(vals, 0, 2, buC1 +1 )
matrix.set(vals, 0, 3, math.round(((buC1 + 1) / tbuC) * 100, 2))
if pos[1] == 2 and pos < 0
matrix.set(vals, 1, 0, buS0 + 1)
matrix.set(vals, 1, 1, math.round(((buS0 +1 ) / tbuS) * 100, 2))
if pos[1] == 2 and pos > 2
matrix.set(vals, 1, 2, buS1 + 1)
matrix.set(vals, 1, 3, math.round(((buS1 + 1) / tbuS) * 100, 2))
if pos[1] > 2 and pos < 0
matrix.set(vals, 2, 0, buB0 + 1)
matrix.set(vals, 2, 1, math.round(((buB0 + 1) / tbuB) * 100, 2))
if pos[1] > 2 and pos > pos[1]
matrix.set(vals, 2, 2, buB1 + 1)
matrix.set(vals, 2, 3, math.round(((buB1 + 1) / tbuB) * 100, 2))
// Bear
if (pos[1] == -1 or pos[1] == 0) and pos > 0
matrix.set(vals, 3, 0, beC0 + 1)
matrix.set(vals, 3, 1, math.round(((beC0 + 1) / tbeC) * 100, 2))
if (pos[1] == -1 or pos[1] == 0) and pos == -2
matrix.set(vals, 3, 2, beC1 + 1)
matrix.set(vals, 3, 3, math.round(((beC1 + 1) / tbeC) * 100, 2))
if pos[1] == -2 and pos > 0
matrix.set(vals, 4, 0, beS0 + 1)
matrix.set(vals, 4, 1, math.round(((beS0 + 1) / tbeS) * 100, 2))
if pos[1] == -2 and pos < -2
matrix.set(vals, 4, 2, beS1 + 1)
matrix.set(vals, 4, 3, math.round(((beS1 + 1) / tbeS) * 100, 2))
if pos[1] < -2 and pos > 0
matrix.set(vals, 5, 0, beB0 + 1)
matrix.set(vals, 5, 1, math.round(((beB0 + 1) / tbeB) * 100, 2))
if pos[1] < -2 and pos < pos[1]
matrix.set(vals, 5, 2, beB1 + 1)
matrix.set(vals, 5, 3, math.round(((beB1 + 1) / tbeB) * 100, 2))
[str, val1, val2] = Current(pos)
array.set(txt, 0, "CHoCH: " + str.tostring(val1, format.percent))
array.set(txt, 1, str + str.tostring(val2, format.percent))
matrix.set(vals, 8, 0, val1)
matrix.set(vals, 8, 1, val2)
// Probability 
var prob1 = label.new(na, na, na
, color = color(na)
, textcolor = chart.fg_color
, style = label.style_label_left)
var prob2 = label.new(na, na, na
, color = color(na)
, textcolor = chart.fg_color
, style = label.style_label_left)
var float bull_prob = 0.0
var float bear_prob = 0.0
var float[] bull_hist = array.new_float()
var float[] bear_hist = array.new_float()
if barstate.islast
str1 = pos < 0 ? array.get(txt, 0) : array.get(txt, 1)
label.set_xy(prob1, n, pup)
label.set_text(prob1, str1)
str2 = pos > 0 ? array.get(txt, 0) : array.get(txt, 1)
label.set_xy(prob2, n, pdn)
label.set_text(prob2, str2)
// Split the strings to pull out percentage and convert to integer
str1_split1  = str.split(str1, ':')
str1_split2  = str.split(array.get(str1_split1, 1), '%')
bull_prob    := str.tonumber(array.get(str1_split2, 0))  // Need to access this value for all historical bars
str2_split1  = str.split(str2, ':')
str2_split2  = str.split(array.get(str2_split1, 1), '%')
bear_prob    := str.tonumber(array.get(str2_split2, 0)) // Need to access this value for all historical bars
array.push(bull_hist, bull_prob)
array.push(bear_hist, bear_prob)
bull_prob_up = bull_prob > bear_prob
bear_prob_dn = bear_prob > bull_prob
plotchar(bull_prob, 'Bull Prob', color=color.new(#ffffff, 100))
plotchar(bear_prob, 'Bear Prob', color=color.new(#ffffff, 100))
plotshape(close > open and bull_prob_up
, title = 'Type 1 - Buy'
, style = shape.triangleup
, size = size.small
, location = location.belowbar
, color = color.green) 
plotshape(close < open and bear_prob_dn
, title = 'Type 1 - Sell'
, style = shape.triangledown
, size = size.small
, location = location.abovebar
, color = color.green) 

I have tried more things than I can count or remember. I an not set on any particular method. Any way that can produce the intended result is fine by me “数组中的数据仅存在于当前柱形。如何引用历史数值?”

答案1

得分: 0

使用for循环和array.get(id, index)来获取数组的历史数值。

英文:

Use for loops and array.get(id, index) to get the historical values of the array.

答案2

得分: 0

以下是您提供的代码的翻译部分:

//@version=5
indicator("概率分析器", overlay = true)

import HeWhoMustNotBeNamed/Logger/2 as log
var logger = log.Logger.new(minimumLevel='Trace', textSize = size.normal)
logger.init()

// 工具提示
string t1 = "设置枢轴期间"
string t2 = "设置响应期间。低值返回短期结构,高值返回长期结构。如果禁用此选项,则将使用上面的枢轴长度。"

// 输入
int pa_len = input.int(defval = 20
     , title = "结构期间"
     , minval = 1
     , tooltip = t1)

int pa_res = input.int(defval = 7
     , title = "结构响应"
     , minval = 1
     , tooltip = t2)

n        = bar_index 
var pup  = float(na)
var pdn  = float(na)
var piup = int(na)
var pidn = int(na)

// 矩阵和数组
var vals          = matrix.new<float>(9, 4, 0.0)
var string [] txt = array.new<string>(2, "")

// 函数

Current(v)=>
    str = ""
    val1 = float(na)
    val2 = float(na)

    if v >= 0
        if v == 1
            str  := "短信: "
            val1 := matrix.get(vals, 0, 1)
            val2 := matrix.get(vals, 0, 3) 
        else if v == 2
            str  := "BMS: "
            val1 := matrix.get(vals, 1, 1)
            val2 := matrix.get(vals, 1, 3) 
        else if v > 2
            str  := "BMS: "
            val1 := matrix.get(vals, 2, 1)
            val2 := matrix.get(vals, 2, 3) 
    else if v < 0
        if v == -1
            str  := "短信: "
            val1 := matrix.get(vals, 3, 1)
            val2 := matrix.get(vals, 3, 3) 
        else if v == -2
            str  := "BMS: "
            val1 := matrix.get(vals, 4, 1)
            val2 := matrix.get(vals, 4, 3) 
        else if v < -2
            str  := "BMS: "
            val1 := matrix.get(vals, 5, 1)
            val2 := matrix.get(vals, 5, 3)

    [str, val1, val2]

// ~~ 枢轴 {
pup     := math.max(pup[1], high)
pdn     := math.min(pdn[1], low)
pa_high  = ta.pivothigh(high, pa_len, pa_len)
pa_low   = ta.pivotlow(low, pa_len, pa_len)

if pa_high
    pup := pa_high
else if pa_low
    pdn := pa_low

// 结构
var pos = 0

if pup > pup[1]
    piup := n
    centerBull = math.round(math.avg(piup[1] ,n))
    if pos <= 0
        pos := 1
        matrix.set(vals, 6, 0, matrix.get(vals, 6, 0) + 1)
    else if pos == 1 and pup > pup[1] and pup[1] == pup[pa_res]
        pos := 2
        matrix.set(vals, 6, 1,matrix.get(vals ,6 ,1) + 1)
	else if pos > 1 and pup > pup[1] and pup[1] == pup[pa_res]
        pos := pos + 1
        matrix.set(vals ,6 ,2,matrix.get(vals, 6, 2) + 1)

else if pup < pup[1]
    piup := n - pa_len

if pdn < pdn[1]
    pidn := n
    centerBear = math.round(math.avg(pidn[1], n))
    if pos >= 0
        pos := -1
        matrix.set(vals, 7, 0, matrix.get(vals, 7, 0) + 1)
    else if pos == -1 and pdn < pdn[1] and pdn[1] == pdn[pa_res]
        pos := -2
        matrix.set(vals, 7, 1, matrix.get(vals, 7, 1) + 1)
    else if pos < -1 and pdn < pdn[1] and pdn[1] == pdn[pa_res]
        pos := pos - 1
        matrix.set(vals, 7, 2, matrix.get(vals, 7, 2) + 1)
else if pdn > pdn[1]
    pidn := n - pa_len

var float[] val1_hist = array.new_float(n+1)
var float[] val2_hist = array.new_float(n+1)

// 概率计算
if ta.change(pos)
    if pos > 0 and pos[1] > 0 or pos < 0 and pos[1] < 0
        if  matrix.get(vals, 8, 0) < matrix.get(vals, 8, 1)
            matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
        else
            matrix.set(vals, 8, 3, matrix.get(vals, 8, 3) + 1)
    else
        if  matrix.get(vals, 8, 0) > matrix.get(vals, 8, 1)
            matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
        else
            matrix.set(vals,8, 3, matrix.get(vals, 8, 3) + 1)

    // 分数计算
    float buC0 = matrix.get(vals, 0, 0), float buC1 = matrix.get(vals, 0, 2)
    float buS0 = matrix.get(vals, 1, 0), float buS1 = matrix.get(vals, 1, 2)
    float buB0 = matrix.get(vals, 2, 0), float buB1 = matrix.get(vals, 2, 2)
    float beC0 = matrix.get(vals, 3, 0), float beC1 = matrix.get(vals, 3, 2)
    float beS0 = matrix.get(vals, 4, 0), float beS1 = matrix.get(vals, 4, 2)
    float beB0 = matrix.get(vals, 5, 0), float beB1 = matrix.get

<details>
<summary>英文:</summary>

    //@version=5
    indicator(&quot;Probability Analyzer&quot;, overlay = true)
    
    import HeWhoMustNotBeNamed/Logger/2 as log
    var logger = log.Logger.new(minimumLevel=&#39;Trace&#39;, textSize = size.normal)
    logger.init()
    
    // Tooltips 
    string t1 = &quot;Set the pivot period&quot;
    string t2 = &quot;Set the response period. A low value returns a short-term structure and a high value returns a long-term structure.
      If you disable this option the pivot length above will be used.&quot;
    
    
    // Inputs
    int pa_len = input.int(defval = 20
         , title = &quot;Structure Period&quot;
         , minval = 1
         , tooltip = t1)
    
    int pa_res = input.int(defval = 7
         , title = &quot;Structure Response&quot;
         , minval = 1
         , tooltip = t2)
    
    
    n        = bar_index 
    var pup  = float(na)
    var pdn  = float(na)
    var piup = int(na)
    var pidn = int(na)
    
    // Matrix &amp; Array 
    var vals          = matrix.new&lt;float&gt;(9, 4, 0.0)
    var string [] txt = array.new&lt;string&gt;(2, &quot;&quot;)
    
    
    // Functions 
    
    Current(v)=&gt;
        str = &quot;&quot;
        val1 = float(na)
        val2 = float(na)
    
        if v &gt;= 0
            if v == 1
                str  := &quot;SMS: &quot;
                val1 := matrix.get(vals, 0, 1)
                val2 := matrix.get(vals, 0, 3) 
            else if v == 2
                str  := &quot;BMS: &quot;
                val1 := matrix.get(vals, 1, 1)
                val2 := matrix.get(vals, 1, 3) 
            else if v &gt; 2
                str  := &quot;BMS: &quot;
                val1 := matrix.get(vals, 2, 1)
                val2 := matrix.get(vals, 2, 3) 
        else if v &lt;= 0
            if v == -1
                str  := &quot;SMS: &quot;
                val1 := matrix.get(vals, 3, 1)
                val2 := matrix.get(vals, 3, 3) 
            else if v == -2
                str  := &quot;BMS: &quot;
                val1 := matrix.get(vals, 4, 1)
                val2 := matrix.get(vals, 4, 3) 
            else if v &lt; -2
                str  := &quot;BMS: &quot;
                val1 := matrix.get(vals, 5, 1)
                val2 := matrix.get(vals, 5, 3)
        
        [str, val1, val2]
    
    
    // ~~ Pivots {
    pup     := math.max(pup[1], high)
    pdn     := math.min(pdn[1], low)
    pa_high  = ta.pivothigh(high, pa_len, pa_len)
    pa_low   = ta.pivotlow(low, pa_len, pa_len)
    
    if pa_high
        pup := pa_high
    else if pa_low
        pdn := pa_low
    
    
    // Structure
    var pos = 0
    
    if pup &gt; pup[1]
        piup := n
        centerBull = math.round(math.avg(piup[1] ,n))
        if pos &lt;= 0
            pos := 1
            matrix.set(vals, 6, 0, matrix.get(vals, 6, 0) + 1)
        else if pos == 1 and pup &gt; pup[1] and pup[1] == pup[pa_res]
            pos := 2
            matrix.set(vals, 6, 1,matrix.get(vals ,6 ,1) + 1)
    	else if pos &gt; 1 and pup &gt; pup[1] and pup[1] == pup[pa_res]
            pos := pos + 1
            matrix.set(vals ,6 ,2,matrix.get(vals, 6, 2) + 1)
    
    else if pup &lt; pup[1]
        piup := n - pa_len
    
    if pdn &lt; pdn[1]
        pidn := n
        centerBear = math.round(math.avg(pidn[1], n))
        if pos &gt;= 0
            pos := -1
            matrix.set(vals, 7, 0, matrix.get(vals, 7, 0) + 1)
        else if pos == -1 and pdn &lt; pdn[1] and pdn[1] == pdn[pa_res]
            pos := -2
            matrix.set(vals, 7, 1, matrix.get(vals, 7, 1) + 1)
        else if pos &lt; -1 and pdn &lt; pdn[1] and pdn[1] == pdn[pa_res]
            pos := pos - 1
            matrix.set(vals, 7, 2, matrix.get(vals, 7, 2) + 1)
    else if pdn &gt; pdn[1]
        pidn := n - pa_len
    
    var float[] val1_hist = array.new_float(n+1)
    var float[] val2_hist = array.new_float(n+1)
    
    // Probability Calculation
    if ta.change(pos)
        if pos &gt; 0 and pos[1] &gt; 0 or pos &lt; 0 and pos[1] &lt; 0
            if  matrix.get(vals, 8, 0) &lt; matrix.get(vals, 8, 1)
                matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
            else
                matrix.set(vals, 8, 3, matrix.get(vals, 8, 3) + 1)
        else
            if  matrix.get(vals, 8, 0) &gt; matrix.get(vals, 8, 1)
                matrix.set(vals, 8, 2, matrix.get(vals, 8, 2) + 1)
            else
                matrix.set(vals,8, 3, matrix.get(vals, 8, 3) + 1)
    
        //Score Calulation
        float buC0 = matrix.get(vals, 0, 0), float buC1 = matrix.get(vals, 0, 2)
        float buS0 = matrix.get(vals, 1, 0), float buS1 = matrix.get(vals, 1, 2)
        float buB0 = matrix.get(vals, 2, 0), float buB1 = matrix.get(vals, 2, 2)
        float beC0 = matrix.get(vals, 3, 0), float beC1 = matrix.get(vals, 3, 2)
        float beS0 = matrix.get(vals, 4, 0), float beS1 = matrix.get(vals, 4, 2)
        float beB0 = matrix.get(vals, 5, 0), float beB1 = matrix.get(vals, 5, 2)
        float tbuC = matrix.get(vals, 6, 0), float tbuS = matrix.get(vals, 6, 1)
        float tbuB = matrix.get(vals, 6, 2), float tbeC = matrix.get(vals, 7, 0)
        float tbeS = matrix.get(vals, 7, 1), float tbeB = matrix.get(vals, 7, 2)
    
    
        // Bull
        if (pos[1] == 1 or pos[1] == 0) and pos &lt; 0
            matrix.set(vals, 0, 0, buC0 + 1)
            matrix.set(vals, 0, 1, math.round(((buC0 + 1) / tbuC) * 100, 2))
        
        if (pos[1] == 1 or pos[1] == 0) and pos == 2
            matrix.set(vals, 0, 2, buC1 +1 )
            matrix.set(vals, 0, 3, math.round(((buC1 + 1) / tbuC) * 100, 2))
        
        if pos[1] == 2 and pos &lt; 0
            matrix.set(vals, 1, 0, buS0 + 1)
            matrix.set(vals, 1, 1, math.round(((buS0 +1 ) / tbuS) * 100, 2))
        
        if pos[1] == 2 and pos &gt; 2
            matrix.set(vals, 1, 2, buS1 + 1)
            matrix.set(vals, 1, 3, math.round(((buS1 + 1) / tbuS) * 100, 2))
        
        if pos[1] &gt; 2 and pos &lt; 0
            matrix.set(vals, 2, 0, buB0 + 1)
            matrix.set(vals, 2, 1, math.round(((buB0 + 1) / tbuB) * 100, 2))
        
        if pos[1] &gt; 2 and pos &gt; pos[1]
            matrix.set(vals, 2, 2, buB1 + 1)
            matrix.set(vals, 2, 3, math.round(((buB1 + 1) / tbuB) * 100, 2))
        
        // Bear
        if (pos[1] == -1 or pos[1] == 0) and pos &gt; 0
            matrix.set(vals, 3, 0, beC0 + 1)
            matrix.set(vals, 3, 1, math.round(((beC0 + 1) / tbeC) * 100, 2))
        
        if (pos[1] == -1 or pos[1] == 0) and pos == -2
            matrix.set(vals, 3, 2, beC1 + 1)
            matrix.set(vals, 3, 3, math.round(((beC1 + 1) / tbeC) * 100, 2))
        
        if pos[1] == -2 and pos &gt; 0
            matrix.set(vals, 4, 0, beS0 + 1)
            matrix.set(vals, 4, 1, math.round(((beS0 + 1) / tbeS) * 100, 2))
        
        if pos[1] == -2 and pos &lt; -2
            matrix.set(vals, 4, 2, beS1 + 1)
            matrix.set(vals, 4, 3, math.round(((beS1 + 1) / tbeS) * 100, 2))
        
        if pos[1] &lt; -2 and pos &gt; 0
            matrix.set(vals, 5, 0, beB0 + 1)
            matrix.set(vals, 5, 1, math.round(((beB0 + 1) / tbeB) * 100, 2))
        
        if pos[1] &lt; -2 and pos &lt; pos[1]
            matrix.set(vals, 5, 2, beB1 + 1)
            matrix.set(vals, 5, 3, math.round(((beB1 + 1) / tbeB) * 100, 2))
        
        [str, val1, val2] = Current(pos)
    
        array.set(txt, 0, &quot;CHoCH: &quot; + str.tostring(val1, format.percent))
        array.set(txt, 1, str + str.tostring(val2, format.percent))
        matrix.set(vals, 8, 0, val1)
        matrix.set(vals, 8, 1, val2)
        array.push(val1_hist, val1)
        array.push(val2_hist, val2)
        
    
    logger.info(str.tostring(array.size(val1_hist)))
    
    // Probability 
    var prob1 = label.new(na, na, na
         , color = color(na)
         , textcolor = chart.fg_color
         , style = label.style_label_left)
    
    var prob2 = label.new(na, na, na
         , color = color(na)
         , textcolor = chart.fg_color
         , style = label.style_label_left)
    
    
    if barstate.islast
        str1 = pos &lt; 0 ? array.get(txt, 0) : array.get(txt, 1)
        label.set_xy(prob1, n, pup)
        label.set_text(prob1, str1)
    
        str2 = pos &gt; 0 ? array.get(txt, 0) : array.get(txt, 1)
        label.set_xy(prob2, n, pdn)
        label.set_text(prob2, str2)
     
    int val1_size = array.size(val1_hist) -1
    int val2_size = array.size(val2_hist) -1
    
    float bear_val = pos &gt; 0 ? array.get(val1_hist, val1_size) : array.get(val2_hist, val2_size)
    float bull_val = pos &lt; 0 ? array.get(val1_hist, val1_size) : array.get(val2_hist, val2_size)
    
    bull_prob = bull_val &gt; bear_val
    bear_prob = bear_val &gt; bull_val
    
    plotshape(close &gt; open and bull_prob
       , title = &#39;Type 1 - Buy&#39;
       , style = shape.triangleup
       , size = size.small
       , location = location.belowbar
       , color = color.green) 
    
    plotshape(close &lt; open and bear_prob
       , title = &#39;Type 1 - Sell&#39;
       , style = shape.triangledown
       , size = size.small
       , location = location.abovebar
       , color = color.green) 
    
    plotchar(bull_val, &#39;Bull Prob&#39;, color=color.new(#ffffff, 100))
    plotchar(bear_val, &#39;Bear Prob&#39;, color=color.new(#ffffff, 100))



</details>



huangapple
  • 本文由 发表于 2023年5月7日 00:05:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定