同花顺MACD背离
BACKGROUNDSTYLE(2); DIFF:EMA(CLOSE,SHORT)-EMA(CLOSE,LONG),COLORWHITE,PRECIS3; DEA :EMA(DIFF,M),COLORYELLOW,PRECIS3; MACD:(DIFF-DEA)*2,COLORSTICK,PRECIS3; GJ:=MAX(C,O); L4:=LLV(GJ,4); JL:=(HHV(DIFF,55)-LLV(DIFF,55))/5; GT:=DEA>REF(DEA,1) AND REF(DEA,1)<REF(DEA,2); A1:=BARSLAST(REF(GT,1)); 底背离:=REF(L4,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND GT; DRAWTEXT(底背离,REF(DEA,A1)*1.18,' 底背离'),COLORRED; H4:=HHV(GJ,4); GT2:=DEA<REF(DEA,1) AND REF(DEA,1)>REF(DEA,2); A2:=BARSLAST(REF(GT2,1)); 顶背离:= REF(H4,A2+1)<H4 AND DIFF<REF(DIFF,A2+1) AND GT2; DRAWTEXT(顶背离,REF(DEA,A2)*1.18,' 顶背离'),COLORGREEN;
traddingview的OBV背离 pinescript(主要代码出自lazybear)
// // @author LazyBear // // Appreciate a note if you use this code anywhere. // study(title="OBV with Divergence", shorttitle="OBV_Divergence_LB") len = input(20) src = close lbR = input(title="Pivot Lookback Right", defval=5) lbL = input(title="Pivot Lookback Left", defval=5) rangeUpper = input(title="Max of Lookback Range", defval=60) rangeLower = input(title="Min of Lookback Range", defval=5) plotBull = input(title="Plot Bullish", defval=true) plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) plotBear = input(title="Plot Bearish", defval=true) plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) bearColor = red bullColor = green hiddenBullColor = color(green, 80) hiddenBearColor = color(red, 80) textColor = white noneColor = color(white, 100) obv(src) => cum(change(src) > 0 ? volume : change(src) < 0 ? -volume : 0*volume) os=obv(src) obv_osc = (os - ema(os,len)) obc_color=obv_osc > 0 ? green : red plot(obv_osc, color=obc_color, style=line,title="OBV-Points", linewidth=2) plot(obv_osc, color=silver, transp=70, title="OBV", style=area) hline(0) plFound = na(pivotlow(obv_osc, lbL, lbR)) ? false : true phFound = na(pivothigh(obv_osc, lbL, lbR)) ? false : true _inRange(cond) => bars = barssince(cond == true) rangeLower <= bars and bars <= rangeUpper //------------------------------------------------------------------------------ // Regular Bullish // Osc: Higher Low oscHL = obv_osc[lbR] > valuewhen(plFound, obv_osc[lbR], 1) and _inRange(plFound[1]) // Price: Lower Low priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) bullCond = plotBull and priceLL and oscHL and plFound plot( plFound ? obv_osc[lbR] : na, offset=-lbR, title="Regular Bullish", linewidth=2, color=(bullCond ? bullColor : noneColor), transp=0 ) plotshape( bullCond ? obv_osc[lbR] : na, offset=-lbR, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 ) //------------------------------------------------------------------------------ // Hidden Bullish // Osc: Lower Low oscLL = obv_osc[lbR] < valuewhen(plFound, obv_osc[lbR], 1) and _inRange(plFound[1]) // Price: Higher Low priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound plot( plFound ? obv_osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=2, color=(hiddenBullCond ? hiddenBullColor : noneColor), transp=0 ) plotshape( hiddenBullCond ? obv_osc[lbR] : na, offset=-lbR, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 ) //------------------------------------------------------------------------------ // Regular Bearish // Osc: Lower High oscLH = obv_osc[lbR] < valuewhen(phFound, obv_osc[lbR], 1) and _inRange(phFound[1]) // Price: Higher High priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) bearCond = plotBear and priceHH and oscLH and phFound plot( phFound ? obv_osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=2, color=(bearCond ? bearColor : noneColor), transp=0 ) plotshape( bearCond ? obv_osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 ) //------------------------------------------------------------------------------ // Hidden Bearish // Osc: Higher High oscHH = obv_osc[lbR] > valuewhen(phFound, obv_osc[lbR], 1) and _inRange(phFound[1]) // Price: Lower High priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound plot( phFound ? obv_osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=2, color=(hiddenBearCond ? hiddenBearColor : noneColor), transp=0 ) plotshape( hiddenBearCond ? obv_osc[lbR] : na, offset=-lbR, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 )
标签:lbR,title,color,公式,tradding,phFound,obv,osc,背离 From: https://www.cnblogs.com/ip99/p/17999921