2 Phát hiện hướng màu trung bình chuyển động

Tác giả:ChaoZhang, Ngày: 2022-05-20 16:44:13
Tags:SMAEMAWMAVWMASMMADEMATEMA

Tùy chọn điền được thêm vào giữa các đường trung bình động (nó được tắt mặc định, kích hoạt trong cấu hình nếu bạn muốn), nếu 2 đường trung bình màu xanh lá cây thì việc điền sẽ màu xanh lá cây, nếu 2 đường trung bình màu đỏ thì việc điền sẽ màu đỏ, điều này sẽ xác nhận một xu hướng lành mạnh trong trường hợp bạn đang sử dụng một đường trung bình nhanh và chậm, trong trường hợp các thay đổi hướng trung bình nhanh sẽ được điền màu tím, điều này có thể chỉ ra một số điều: một sự điều chỉnh của xu hướng đang được tạo ra, có thể nghỉ ngơi của giá, có thể bắt đầu của laterality, có thể thay đổi xu hướng, khi màu tím thương nhân sẽ phải phân tích bối cảnh chung để có thể xác định những gì có thể xảy ra.

Các cảnh báo sau đây đã được tạo ra:

  • Thay đổi hướng 1-MA
  • Thay đổi hướng 2-MA
  • Chạy dưới 2-Ma/1-Ma
  • Đi qua dưới 1-Ma/2-Ma
  • Chạy qua 2-Ma/1-Ma
  • Quay qua 1-Ma/2-Ma
  • Xác 1-Ma/2-Ma

backtest

img


//@version=3
study(shorttitle="MA_2X", title="2 Moving Average Color Direction Detection ", overlay=true)

// === INPUTS

ma_1 = input(true, title="1-MA")
ma_type   = input(defval="SMA", title="1-MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
ma_len    = input(defval=20, title="1-MA Lenght", minval=1)
ma_src    = input(close, title="1-MA Source")
reaction_ma_1  = input(defval=3, title="1-MA Reaction", minval=1)

ma_2 = input(true, title="2-MA")
ma_type_b   = input(defval="SMA", title="2-MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
ma_len_b    = input(defval=8, title="2-MA Lenght", minval=1)
ma_src_b    = input(close, title="2-MA Source")
reaction_ma_2  = input(defval=3, title="2-MA Reaction", minval=1)

filling = input(false, title="FILLING")

// SuperSmoother filter
// © 2013  John F. Ehlers
variant_supersmoother(src,len) =>
    a1 = exp(-1.414*3.14159 / len)
    b1 = 2*a1*cos(1.414*3.14159 / len)
    c2 = b1
    c3 = (-a1)*a1
    c1 = 1 - c2 - c3
    v9 = 0.0
    v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
    v9
    
variant_smoothed(src,len) =>
    v5 = 0.0
    v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
    v5

variant_zerolagema(src,len) =>
    ema1 = ema(src, len)
    ema2 = ema(ema1, len)
    v10 = ema1+(ema1-ema2)
    v10
    
variant_doubleema(src,len) =>
    v2 = ema(src, len)
    v6 = 2 * v2 - ema(v2, len)
    v6

variant_tripleema(src,len) =>
    v2 = ema(src, len)
    v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)             
    v7
    
variant(type, src, len) =>
    type=="EMA"     ? ema(src,len) : 
      type=="WMA"   ? wma(src,len): 
      type=="VWMA"  ? vwma(src,len) : 
      type=="SMMA"  ? variant_smoothed(src,len) : 
      type=="DEMA"  ? variant_doubleema(src,len): 
      type=="TEMA"  ? variant_tripleema(src,len): 
      type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
      type=="SSMA"  ? variant_supersmoother(src,len) : 
      type=="ZEMA"  ? variant_zerolagema(src,len) : 
      type=="TMA"   ? sma(sma(src,len),len) : sma(src,len)


// === Moving Average
ma_series = variant(ma_type,ma_src,ma_len)
ma_series_b = variant(ma_type_b,ma_src_b,ma_len_b)

direction = 0
direction := rising(ma_series,reaction_ma_1) ? 1 : falling(ma_series,reaction_ma_1) ? -1 : nz(direction[1])
change_direction= change(direction,1)

direction_b = 0
direction_b := rising(ma_series_b,reaction_ma_2) ? 1 : falling(ma_series_b,reaction_ma_2) ? -1 : nz(direction_b[1])
change_direction_b= change(direction_b,1)

// Plot MA series and color it according too direction
pcol = direction>0 ? lime : direction<0 ? red : na
a=plot( ma_1? ma_series :na, color=pcol,style=line,join=true,linewidth=3,transp=10,title="1-MA Plot")

pcol_b = direction_b>0 ? lime : direction_b<0 ? red : na
b=plot( ma_2? ma_series_b :na, color=pcol_b,style=line,join=true,linewidth=2,transp=10,title="2-MA Plot")

fill(a,b,color=direction==1 and direction_b==1 and filling == true?lime:direction==-1 and direction_b==-1and filling == true?red:direction==1 and direction_b==-1and filling == true?purple:direction==-1 and direction_b==1and filling == true?purple:white,transp=80)

/////// Alerts ///////

alertcondition(change_direction,title="Change Direction 1-MA",message="Change Direction 1-MA")
alertcondition(change_direction_b,title="Change Direction 2-MA",message="Change Direction 2-MA")

alertcondition(crossunder(ma_series_b,ma_series),title="Cross Under 2-Ma/1-Ma",message="Cross Under 2-Ma/1-Ma")
alertcondition(crossunder(ma_series,ma_series_b),title="Cross Under 1-Ma/2-Ma",message="Cross Under 1-Ma/2-Ma")

alertcondition(crossover(ma_series_b,ma_series),title="Cross Over 2-Ma/1-Ma",message="Cross Over 2-Ma/1-Ma")
alertcondition(crossover(ma_series,ma_series_b),title="Cross Over 1-Ma/2-Ma",message="Cross Over 1-Ma/2-Ma")

alertcondition(cross(ma_series_b,ma_series),title="Cross 1-Ma/2-Ma",message="Cross 1-Ma/2-Ma")



if crossunder(ma_series,ma_series_b)
    strategy.entry("Enter Long", strategy.long)
else if crossunder(ma_series_b,ma_series)
    strategy.entry("Enter Short", strategy.short)

Có liên quan

Thêm nữa