EBBXの基本的な見方
まとめ
EBBXの入力
g 指数重みのパラメータ。(指数重み)重心がgにあることを示す。
EBBXの出力
e0p (指数重み)0次推定値。(指数重み)平均ともいう。
e0d (指数重み)標準偏差。σを使って表されることもある。
e1p (指数重み)1次推定値。(指数重み)近似直線が時間0に通るところ。
これらのチャートでの表示を説明します。チャートには、灰色の線4本と、色付き帯の縁の線2本があります。計6本のうち5本が等間隔です。その中央が平均のe0pです。間隔が標準偏差のe0dです。上下2本ずつはボリンジャーバンドの類推で±1σ、±2σとも呼びます。等間隔でない残りの1本がe1pで±1σのあいだを動いています。基本的にこのe1pが増えていれば強気、減っていれば弱気です。
EBBXの特徴
指数重みの公比はg/(g+1)
e1p-e0pは近似直線の傾き(gあたりの値幅)
(e1p-e0p)/e0dは時間とpriceの相関係数
priceが+1σの線(e0p+e0d)超なら、e0d(標準偏差)増加
priceがe1p超なら、e1p-e0p(傾き)増加
priceが(e0p+e1p)/2超なら、e1p(1次推定値)増加
priceがe0p超なら、e0p(0次推定値)増加
重心がgにある指数重みの公比はg/(g+1)
重心がgにある指数重みの公比を求めてみます。指数減衰する重みは、公比$${ 0 < r < 1 }$$を使って、時間 $${0, 1, 2, 3, … }$$ で $${1, r, r^2, r^3, …}$$ と表現できます。
重心は座標(ここでは時間)の重み付け平均です。重み付け平均は、重み付け合計を重みの合計で割ることで得られます。
重みの合計 $${ 1+r+r^2+r^3+… = \sum\limits_{t=0}^\infty r^t }$$
座標の重み付け合計 $${ 0・1+1r+2r^2+3r^3+… = \sum\limits_{t=0}^\infty tr^t }$$
なので、重心gは次のように書けます。
$$
g = \dfrac{\sum\limits_{t=0}^\infty tr^t}{\sum\limits_{t=0}^\infty r^t}
$$
これを WolframAlpha に丸投げすると、次のように $${ r= \dfrac{g}{g+1} }$$となり、上の特徴1を導けました。(虚数解の意義はよく分かりません。)
WolframAlpha はこちらから行くと上の式が呼び出された状態になるみたいです。
指数重みのグラフ
重心がgにある指数重みは、1bar過去になるごとにg/(g+1)倍になることが分かりました。その重みを棒グラフにすると次のようになります。
g=60b(bはbar、ロウソク足の数で60本を意味します)で作成した図です。横軸を兼ねて、1g(60b)ずつ増加するラベルが下部に描いてあります。0bの位置のEBBXを計算するときの重み付けが黒の棒グラフです。
重み付けの値は、0bで最も大きく0.016強、左に行くほど小さくなっています。小さくなる割合は、barで1つ左に行く毎にg/(g+1)≒0.98倍です。
g=60b毎に背景が色分けしてあります。赤の部分は0bから59bまでです。そこに63%とあるのは、0bから59bまで1gのあいだの重みの合計が全体の63%であることを示します。同様に1g毎にオレンジ、黄緑などで色分けし、その1gのあいだの重みの割合が載っています。
図示されている通り、1g毎の重みの割合は、63%、23%、9%、3%、1%と減っていき、その後は四捨五入して0%です。(合計は四捨五入のため100になっていません。)これを63:23:9:…の指数重みと呼ぶことにします。
この63:23:9:…の指数重みで平均を計算したものがe0p、標準偏差を計算したものがe0dです。
指数重み付け近似直線
横方向の重み付け重心は横方向の重み付け平均でgでした。
縦方向の重み付け重心は縦方向の重み付け平均でe0pです。
重み付け近似直線は重み付け重心を通るという性質があるので、(g, e0p)を通ります。
一方、重み付け近似直線が時間0に通るところがe1pというのがe1pの定義なので、近似直線は(0, e1p)を通ります。
以上の2点を結ぶ線を次のチャートの緑線で示しました。これが63:23:9:…の指数重みで計算した近似直線ということになります。
63%の重みがある赤や23%重みのある黄色のところでは、指数重みによって重視されているため近似直線とpriceが近いです。1%の重みのある青のところでは近似直線とpriceが遠くなっていますが、指数重みによって影響を減らして計算している結果です。
上の図では、灰色の縦線が時間0でe0pからe1pまで描かれています。
灰色の横線が時間0から時間1g(=60b)までe0pに描かれています。
この2本の灰色の線と緑色の線の関係から、近似直線の傾きはgあたりe1p-e0pになっていることが分かります。これは最初に書いた特徴の2番です。
このチャートを作るのに使ったインジケータは、次のように自動で多くの近似直線を描きます。EBBXの指数重み直線近似がどういうものになっているか、いろいろ見てみてください。ソースは最後につけておきます。
おまけ
いつものようにソースをつけておきます。
まず、指数重みのグラフのソースです。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dig_dig_11
//@version=5
indicator("ebbx weight", max_labels_count=500)
import dig_dig_11/lib_beta/2 as dd11b
var g = 60
var offset = 0
var num_colors = 7 // 背景色をいくつ使うか
var hue_step = 45 // 背景色の色相をどれだけ変えるか
t = g*num_colors - ((bar_index+offset) % (g*num_colors)) - 1 // 横座標
var total_weight = g+1 // 重みの合計 1 + g/(g+1) + (g/(g+1))^2 + …
weight = math.pow(float(g)/(g+1), t) / total_weight
plot(weight, style=plot.style_histogram, color=dd11b.black())
var sum_weight = 0.0
sum_weight += weight
col = dd11b.hsv2color(int(t/g)*hue_step, 30, 100)
bgcolor(col)
if t % g == 0
label.new(bar_index-g/2, -0.2/total_weight, text=str.tostring(sum_weight, "0%"), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_none, size=size.huge)
label.new(bar_index, -0.05/total_weight, text=str.format("{0}g\n({1}b)", t/g, t), color=dd11b.white(), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_up, size=size.large)
sum_weight := 0
続いて近似直線の例のソースです。「タイトル画像で使った」と書いてある下の6行はタイトル画像で使ったラベルを出力するところです。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dig_dig_11
//@version=5
indicator("e1p line", overlay=true, max_labels_count=500)
import dig_dig_11/lib202408/1 as dd11
import dig_dig_11/lib_beta/2 as dd11b
var g_value = input.int(60, title="g value", minval=0, inline="g")
var g_unit = input.string("b", title="unit", options=["b"], inline="g",
tooltip="今回はgをintに制限するのでbだけにしました")
var exclude = input.int(5, title="exclude", minval=4, display=display.none, // display.noneはalertメッセージを簡潔にするため
tooltip="最初のexclude*gで、塗りつぶしをしない")
var lic = input.string("", title="lic", display=display.none,
tooltip="入力なしで15分足まで使えます\n"
+ "より短い足で使うには https://x.com/dig_dig_11 のプロフィールから")
var vline_width = input.int(1, title="vline width", display=display.none,
tooltip="g毎に描かれる縦線の太さ")
var info_position = input.string(position.bottom_left, title="info table position",
options=[position.bottom_left, position.bottom_right, position.top_right], inline="info", display=display.none)
var extra_space = input.bool(true, title="extra space", inline="info",
tooltip="TradingViewのロゴが邪魔なときにチェックしてください")
// gを計算
var g = g_value
// ebbx計算
[e0p, e0d, e1p] = dd11.ebbx(open, high, low, close, g, lic)
// バンド描画
var col_line = dd11b.gray(75)
plot(e0p + e0d*2, color=col_line, title="+2σ")
plot(e0p + e0d*1, color=col_line, title="+1σ")
plot(e0p - e0d*1, color=col_line, title="-1σ")
plot(e0p - e0d*2, color=col_line, title="-2σ")
// 塗りつぶし描画
var margin = dd11b.get_margin(g*timeframe.in_seconds()/60)
pos = dd11b.get_ebbx_pos(e1p, e0p, e0d, margin)
// pos = dd11b.get_ebbx_pos_simple(e1p, e0p) // simple_ebbx互換
col = dd11b.pos2col4(pos, not_enough=bar_index<g*exclude) // 4色版
// col = dd11b.pos2col3(pos, not_enough=bar_index<g*exclude) // 3色版
pe0p = plot(e0p, editable=false, display=display.none+display.price_scale, title="e0p")
pe1p = plot(e1p, editable=false, display=display.none+display.price_scale, title="e1p")
fill(pe0p, pe1p, color=col)
// 情報テーブル出力
var a_str = array.from(dd11b.second2readable(g*timeframe.in_seconds()))
var a_str_tt = array.from(str.tostring(g, "g=#.#bars ") + str.tostring(margin, "margin=#.0%"))
var tbl = dd11b.get_table(a_str, a_str_tt, columns=2, extra_space=extra_space)
if barstate.islast
tbl.cell_set_text(2, 0, text=str.tostring(e0d/syminfo.mintick, "#"))
for x = 1 to 2 // 0はextra spaceに使われている
tbl.cell_set_bgcolor(x, 0, dd11b.tune_color(col, transp=20))
// ここまではほぼebbxのコード
var offset = input.int(360, title="offset", tooltip="e1pの線の開始位置の微調整")
var num_colors = 7 // 背景色をいくつ使うか
var hue_step = 45 // 背景色の色相をどれだけ変えるか
t = g*num_colors - ((bar_index+offset) % (g*num_colors)) - 1 // 横座標
if t % (g*num_colors) == 0 // 一組のe1pの線とラベルを描く
line.new(bar_index, e0p, bar_index, e1p, width=3, color=dd11b.gray()) // 長さe1p-e0pの縦線
line.new(bar_index-g, e0p, bar_index, e0p, width=3, color=dd11b.gray()) // 長さgの横線
line.new(bar_index-g*6, e0p+(e0p-e1p)*5, bar_index, e1p, width=3, color=dd11b.green()) // 近似直線
sty_e1p = e1p > e0p ? label.style_label_lower_left : label.style_label_upper_left
sty_e0p = e1p > e0p ? label.style_label_upper_left : label.style_label_lower_left
var size = size.huge
label.new(bar_index, e1p, text="(0,e1p)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=sty_e1p, size=size)
label.new(bar_index, e0p, text="(0,e0p)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=sty_e0p, size=size)
label.new(bar_index-g+1, e0p, text="(g,e0p)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=sty_e0p, size=size)
// タイトル画像で使った
// label.new(bar_index, e1p, text="e1p", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_upper_left, size=size)
// label.new(bar_index, e0p, text="e0p", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=sty_e0p, size=size)
// label.new(bar_index, e0p+e0d, text="+1σ(=e0p+e0d)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_lower_left, size=size)
// label.new(bar_index, e0p+e0d*2, text="+2σ(=e0p+e0d*2)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_lower_right, size=size)
// label.new(bar_index, e0p-e0d, text="-1σ(=e0p-e0d)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_upper_left, size=size)
// label.new(bar_index, e0p-e0d*2, text="-2σ(=e0p-e0d*2)", color=dd11b.white(transp=15), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_label_upper_left, size=size)
var int int_all1 = int(math.pow(2, 53) - 1) // 最も多く1が並ぶ数
var float_max = int_all1 * math.pow(2, 1024-53)
var float_min = -float_max
var highest = float_min
var lowest = float_max
var int left_bar_index = na
if chart.left_visible_bar_time < time and time < chart.right_visible_bar_time
left_bar_index := nz(left_bar_index, bar_index)
highest := math.max(highest, high, e0p+e0d*2) // 表示範囲のhighest
lowest := math.min(lowest, low, e0p-e0d*2) // 表示範囲のlowest
if barstate.islast // highest、lowestが確定してから、lowestよりちょっと高めに座標を表示する
i = bar_index - left_bar_index
while i >= 0
var total_weight = g+1 // 重みの合計 1 + g/(g+1) + (g/(g+1))^2 + …
weight = math.pow(float(g)/(g+1), t[i]) / total_weight
var sum_weight = 0.0
sum_weight += weight
if t[i] % g == 0
if t[i] / g != num_colors-1
label.new(bar_index-i-g/2,lowest, text=str.tostring(sum_weight, "0%"), textcolor=dd11b.black(), text_font_family=font.family_monospace, style=label.style_none, size=size.huge)
label.new(bar_index-i, lowest+(highest-lowest)*0.1, text=str.tostring(t[i]/g)+"g\n("+str.tostring(t[i])+"b)", color=dd11b.white(), textcolor=dd11b.black(), text_font_family=font.family_monospace, size=size.large, style=label.style_label_up)
sum_weight := 0
i -= 1
bgcolor(dd11b.hsv2color(int(t/g)*hue_step, 15, 100))
ここから先は
この記事が気に入ったらサポートをしてみませんか?