レッドKモメントバー

作者: リン・ハーンチャオチャン, 日時: 2022-05-18 11:28:24
タグ:SMAエイマWMAHMA

モメントバー (Mo_Bars) は (相対的な) モメントを視覚化するための異なる方法を提供し,モメントの変化を読み取り,それを取引に組み込む方法に対する異なる視点を提供するために,いくつかの単純なTAコンセプトを使用します.

このアイデア (そして脚本自体) は本当に非常にシンプルで,エルダーズ・インパルス・システム (EIS) から (非常に緩やかに) 刺激を受け,他のコンセプトを活用し,混雑が少なくなり,読みやすいように進化しました.

モ_バーの建設

ベースコンセプトは3つの移動平均線を使用します: 第1行は短い長さの比較的速いMAです - 主な価格追跡ラインとして機能します

2番目はメインラインより少し遅い - 長さは2〜3バー - 既定でオープン値をソースとして使用します - 閉じる価格がオープンよりも速く動き始めるときに識別するのにうまく機能します (バーは開けるよりも頻繁に閉じる) - このラインは信号ラインとして機能します - 定期的なWMAスムージングを使用する追加の遅延の設定が追加されています - 遅延は2MA間の相対的な移動を拡大します

この2つのMAでは,他のMAタイプも使用できますが,そのMAタイプを特に使った理由は,それが優雅に動いているからです. そして2つのLazy Lineが一緒に動くと,小さな価格変動からのウィプソウを最小限に抑えます. 他のMAタイプをテストし,RSSがそこに優位性があることを発見しました.

3番目の線は,より遅いMA (長さ5〜6×高速線) で,フィルターまたはベースラインとして機能します.その線の上では,我々は長ポジションを好むべきです.我々は牛領域にあります.その線の下では,我々はショートポジションを好むことができます.そして我々は熊領域にあります.あなたの取引スタイルと時間枠に合うようにこのラインを調整します. (私はフィルターラインのMAタイプとしてWMAを使用することを選びました... それには良い理由がありますが,今後バージョンでは,他の選択可能なMAタイプを追加できます.)

Mo_Bars を使用する

幅広く見ると,MACDと同じ方法で Mo_Bars を使えます. どちらも中心型と無制限のオシレーターです. Mo_Bars は2ではなく3MAをベースにしていることに注意してください.

フィルター線) - つまり,バーの長さは2つのMA間の相対運動量を表します. Mo_Barsは,その運動量値の増加または減少を反映する方法で色付けされます (ここでの視覚は,私たちの尊敬するウィザードによって最近公開された別の指標にインスピレーションを受けた可能性があります - それは完璧に機能しました - ここでクレジットです:)

単純に言えば,メインMAが信号MAの下にある場合,バーは赤色で,メインMAが信号MAの上にある場合,バーは緑色で,相対モメント方向の変化が検出されたとき,通常白色バーが表示されます (これはトレンド方向とは異なりますが,マックドのように収束と逸脱を表示し,利用するのに役立ちます).

  • 上記のグラフでは,この方法で相対運動勢を視覚化することで,切断領域 (Mo_Barsがゼロ以上だが赤色または下向き,またはMo_Barsがゼロ以下で緑色または上向きである場合) - 価格との収束/離散 - がどのように暴露されるかを示しました.

  • このセットアップで遊ぶことはもっとたくさんあります - そして,もしかしたら,十分な関心があるなら,それをどのように利用するか,さらに進化させるかのための将来の専用の投稿があるかもしれません - ここには,より多くのフィルター (ボリュームベースのかもしれない),アラート,信号...などを追加する,多くの可能性があります - だから,興味を見てみましょう:)

価格チャート上のMAの設定は,下のパネルのMo_Bars設定とマッチ/同期して,スクリプトがどのように動作し,価格チャート上のMAアクションをどのように下記のものに変換するかを示しています.

バックテスト

img


/*backtest
start: 2022-05-10 00:00:00
end: 2022-05-16 23:59:00
period: 3m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RedKTrader

//@version=5
indicator('[dev]RedK Momentum Bars', shorttitle='RedK MoBars v3.0', explicit_plot_zorder = true, timeframe='', timeframe_gaps=false)

// A trading system composed of 2 short Lazy Lines (preferably one open and one close - 2-3 bars apart) and a WMA long filter 
// loosely inspired by Edler Impulse
// v2.0 cleaned up code and added MA options to be able to mix and match, and experiment with various setups 
// default values (my personal preference) remain the same as in v1.0 
// for example, some traders will consider "bear territory" only below SMA50, others will use EMA30 .. and so on.
// ---------------------------------------------------------------------------------------------------------------
// MoBars v3.0: 
// updated defaults to match the most common 3x MA cross-over set-up of SMA (10, 20, 50)
// updated visuals to push the 0 line to the background of the plot (using the explcit_plot_zorder param)
// and added alerts for crossing up, down and swing around the 0 line (the Bullish/Bearish Filter MA)

//==============================================================================
f_LazyLine(_data, _length) =>
    w1 = 0,     w2 = 0,     w3 = 0
    L1 = 0.0,   L2 = 0.0,   L3 = 0.0
    w = _length / 3

    if _length > 2
        w2 := math.round(w)
        w1 := math.round((_length - w2) / 2)
        w3 := int((_length - w2) / 2)

        L1 := ta.wma(_data, w1)
        L2 := ta.wma(L1, w2)
        L3 := ta.wma(L2, w3)
        
    else
        L3 := _data
        
    L3
//==============================================================================

// =============================================================================    
f_getMA(source, length, type) =>
    type == "SMA" ? ta.sma(source, length) : 
      type == "EMA" ? ta.ema(source, length) :
      type == "WMA" ? ta.wma(source, length) :
      type == "HMA" ? ta.hma(source, length) :
      f_LazyLine(source, length)
// =============================================================================    

// ------------------------------------------------------------------------------------------------
// Inputs
// Note, in v3.0, changed default lengths to 10, 20 and 50  -- and all MA types to SMA. 
// ------------------------------------------------------------------------------------------------

Fast_Src    = input.source(close,   title='Fast MA Source',          inline = 'Fast')
Fast_Length = input.int(10,          title = 'Length',   minval = 1, inline = 'Fast')
Fast_Type   = input.string('SMA', title = 'Type',                    inline = 'Fast',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'])

Slow_Src    = input.source(close,    title='Slow MA Source',         inline = 'Slow')
Slow_Length = input.int(20,          title='Length',     minval = 1, inline = 'Slow')
Slow_Type   = input.string('SMA', title = 'Type',                    inline = 'Slow',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'])

Slow_Delay  = input.int(3,          title='Delay (1 = None)',       minval = 1)

Fil_Length  = input.int(50,       title='Filter MA Length', minval = 1, inline = 'Filter')
Fil_Type    = input.string('SMA', title = 'Type',                   inline = 'Filter',
  options = ['RSS_WMA', 'WMA', 'EMA', 'SMA', 'HMA'])


// ------------------------------------------------------------------------------------------------
// Calculation
// ------------------------------------------------------------------------------------------------

Fast    = f_getMA(Fast_Src, Fast_Length, Fast_Type)
Slow    = f_getMA(Slow_Src, Slow_Length, Slow_Type)

Filter  = f_getMA(close, Fil_Length, Fil_Type)

Fast_M  = Fast - Filter
Slow_M  = Slow - Filter

Rel_M   = ta.wma(Slow_M, Slow_Delay)

// prep the Momentum bars
o = Rel_M
c = Fast_M
h = math.max(o, c)
l = math.min(o, c)

rising      = ta.change(c) > 0


// ------------------------------------------------------------------------------------------------
// Colors & Plots
// ------------------------------------------------------------------------------------------------

hline(0, title = 'Zero Line', color = color.blue, linestyle = hline.style_solid)

c_barup     = #11ff20ff
c_bardn     = #ff1111ff
c_bardj     = #ffffffff

c_barupb    = #1b5e20ff
c_bardnb    = #981919ff
c_bardjb    = #9598a1ff

barcolor    = c > o and rising ? c_barup : c < o and not rising ? c_bardn : c_bardj
borcolor    = c > o and rising ? c_barupb : c < o and not rising ? c_bardnb : c_bardjb
//plotcandle(o, h, l, c, 'MoBars', barcolor, barcolor, bordercolor = borcolor)


// ===========================================================================================================
//      v3.0 adding alerts 
// these alerts will trigger as soon as the Momentum Bar touches above the filter line 
// this approach can lead to "false signals" but also has an advantage (of alerting to a possible mood/mode change)
// another option - maybe in an updated version - could be to trigger alerts *only* when the full Momentum Bar completely clears the filter line (above or below)
// and it's easy to make that a user choice in the study inputs
// ===========================================================================================================

Alert_up    = ta.crossover(h,0)
Alert_dn    = ta.crossunder(l,0)
Alert_swing = Alert_up or Alert_dn

// "." in alert title for the alerts to show in the right order up/down/swing 
alertcondition(Alert_up,    ".   MoBars Crossing 0 Up",         "MoBars Up - Bullish Mode Detected!")
alertcondition(Alert_dn,    "..  MoBars Crossing 0 Down",       "MoBars Down - Bearish Mode Detected!")
alertcondition(Alert_swing, "... MoBars Crossing 0",            "Mobars Swing - Possible Reversal Detected!")



if Alert_up
    strategy.entry("Enter Long", strategy.long)
else if Alert_dn
    strategy.entry("Enter Short", strategy.short)

関連性

もっと