OBV_X3
{OBV_X3
【背景】考虑到OBV_X03在情况1的时候,采用的是寻找波段线的同价K线,
但是由于此种情况下必须使用CONST(C)或通过输入参数CONSTCC设定固定值,
无法当前K线的CLOSE同时变化,所以改进为OBV_X03
【效果】此指标的卖出信号对大盘、创业板指数15分钟其准确,虽然不能做
到每次见顶都发出信号,但是只要一出信号,0.5-1个月内一定会有大跌25%的情况
同时情况TJ调整位1, 2,分别对应情况TJ11,20 和 12, 30
同时还能提示OBV突破向下、向上的
【文档】REF: G:\D电子书\29 股票\MY选股公式\OBV背离(OBV_X)\README.DOCX
CONSTCC: 2095.00
}
{INFO}
INFO:='此指标的卖出信号对大盘、创业板指数15分钟及其准确(尤其当和前一个大峰顶中间间隔1个以上小峰时)。只要一有S,0.5-1个月内一定会有大跌25%的情况';
DRAWTEXT_FIX(ISLASTBAR, 0,35, 0, INFO ),COLOR00FF00;
{=======================OBV变量定义=============================}
VA:=IF(CLOSE>REF(CLOSE,1),VOL,-VOL), NODRAW;
OBV:SUM(IF(CLOSE=REF(CLOSE,1),0,VA),0);
MAOBV:=MA(OBV,M){, NODRAW};
{ICONPOS:=OBV{TAN_OUT}
{=======================DAY分隔线=======================}
{结果从0到13,依次分别是1/5/15/30/60分钟,日/周/月,多分钟,}
5分钟 := (1==PERIOD);
十五分钟:= (2==PERIOD);
30分钟:= (3==PERIOD);
60分钟:= (4==PERIOD);
日线 := (5==PERIOD);
{DRAWKLINE(H,O,L,C);}
A:=REF(OBV,BARSLAST(IF(CURRBARSCOUNT<=CONST(BARSLAST(DAY!=REF(DAY,1))+7*0+1),OBV,DRAWNULL)));
ISNEWDAY:= REF(DAY,1)!=DAY AND(2==PERIOD);
STICKLINE(ISNEWDAY,OBV*0.5,OBV*1.5,0,0),COLORYELLOW;
DRAWTEXT(ISNEWDAY, OBV*1.5, VAR2STR(DATE+19000000-20170000, 0) );
{========================OBV 和价格的关系===============================}
PREDAYBAR : REF(BARSLAST(ISNEWDAY), 1)+1+1, NODRAW;
BAR_H:HHVBARS(C, 44*4*4), NODRAW;
BAR_L:LLVBARS(C, 44*4*4), NODRAW;
P_L:REF(C, BAR_L), NODRAW;
P_H:REF(C, BAR_H), NODRAW;
OBV_L:REF(OBV, BAR_L), NODRAW;
OBV_H:REF(OBV, BAR_H), NODRAW;
DELT_P12 :100*(C-P_L)/(P_H-P_L), NODRAW;
DELT_OBV12:100*(OBV-OBV_L)/(OBV_H-OBV_L), NODRAW;
P_OBV:DELT_P12/DELT_OBV12, NODRAW;
DRAWTEXT(ISNEWDAY AND P_OBV>=0.5, OBV*0.5, VAR2STR(P_OBV, 2) ), COLORYELLOW;
DRAWTEXT(ISNEWDAY AND P_OBV<0.5 , OBV*0.5, VAR2STR(P_OBV, 2) ), COLORRED;
{========================OBV背离===============================}
{ZIG 顶底定义}
ZIGT2:=1{ZIGT/6};
L6底 :=ZIG(3,ZIGT)>REF(ZIG(3,ZIGT),1) AND REF(ZIG(3,ZIGT),1)<=REF(ZIG(3,ZIGT),2) AND REF(ZIG(3,ZIGT),2)<=REF(ZIG(3,ZIGT),3);
L6顶 :=ZIG(3,ZIGT)<REF(ZIG(3,ZIGT),1) AND REF(ZIG(3,ZIGT),1)>=REF(ZIG(3,ZIGT),2) AND REF(ZIG(3,ZIGT),2)>=REF(ZIG(3,ZIGT),3) ;
L1底:=ZIG(3,ZIGT2)>REF(ZIG(3,ZIGT2),1) AND REF(ZIG(3,ZIGT2),1)<=REF(ZIG(3,ZIGT2),2) AND REF(ZIG(3,ZIGT2),2)<=REF(ZIG(3,ZIGT2),3);
L1顶:=ZIG(3,ZIGT2)<REF(ZIG(3,ZIGT2),1) AND REF(ZIG(3,ZIGT2),1)>=REF(ZIG(3,ZIGT2),2) AND REF(ZIG(3,ZIGT2),2)>=REF(ZIG(3,ZIGT2),3) ;
{向前最多寻找4个同价的参照BAR,对OBV的变动进行比较}
{ZIG BAR}
L6_BOTTOM_BAR1:=BARSLAST(L6底)+1, NODRAW;
L6_BOTTOM_BAR2:=REF(BARSLAST(L6底), L6_BOTTOM_BAR1)+L6_BOTTOM_BAR1, NODRAW;
L6_TOP_BAR1:=BARSLAST(L6顶)+1, NODRAW;
L6_TOP_BAR2:=REF(BARSLAST(L6底), L6_TOP_BAR1)+L6_TOP_BAR1, NODRAW;
MIN_ZIG_BAR:=MIN(L6_BOTTOM_BAR1, L6_TOP_BAR1), NODRAW;
MAX_ZIG_BAR:=MAX(L6_BOTTOM_BAR1, L6_TOP_BAR1), NODRAW;
DELT顶1:=ABS(REF(C, L6_TOP_BAR1)-REF(C, L6_TOP_BAR2)), NODRAW;
DELT顶2:=0.33*(REF(C, L6_TOP_BAR1)-REF(C, L6_BOTTOM_BAR1)), NODRAW;
DELT顶3:=0.50*(REF(C, L6_TOP_BAR1)-REF(C, L6_BOTTOM_BAR1)), NODRAW;
DELT顶:=MIN(DELT顶3, MAX(DELT顶1, DELT顶2)), NODRAW;
DELT底1:=ABS(REF(C, L6_BOTTOM_BAR1)-REF(C, L6_BOTTOM_BAR2)), NODRAW;
DELT底2:=0.33*(REF(C, L6_TOP_BAR1)-REF(C, L6_BOTTOM_BAR1)), NODRAW;
DELT底3:=0.50*(REF(C, L6_TOP_BAR1)-REF(C, L6_BOTTOM_BAR1)), NODRAW;
DELT底:=MIN(DELT底3, MAX(DELT底1, DELT底2)), NODRAW;
{状态1:当前价格处于前一ZIG峰谷价格范围内}
{状态10:前一ZIG峰谷上部}
TJ10C:=REF(CLOSE, L6_TOP_BAR1), NODRAW;
TJ10DELT:-DELT顶, NODRAW;
TJ10:= CLOSE>REF(CLOSE, L6_TOP_BAR1)-DELT顶; {BOTTOM_BAR>TOP_BAR从顶部降下来}
TJ11:= L6_BOTTOM_BAR1>L6_TOP_BAR1 AND TJ10; {BOTTOM_BAR>TOP_BAR从顶部降下来}
LASTBAR10:=BARSLAST(L1顶)+1;
{状态20:前一ZIG峰谷下部}
TJ20C:=REF(CLOSE, L6_BOTTOM_BAR1), NODRAW;
TJ20DELT:DELT底, NODRAW;
TJ20:= CLOSE<REF(CLOSE, L6_BOTTOM_BAR1)+DELT底; {BOTTOM_BAR<TOP_BAR从底部升下来}
TJ21:= L6_BOTTOM_BAR1<L6_TOP_BAR1 AND TJ20; {BOTTOM_BAR<TOP_BAR从底部升下来}
LASTBAR20:=BARSLAST(L1底)+1;
{参照点计算}
REF_BAR: IF (TJ10, LASTBAR10,
IF (TJ20, LASTBAR20,
0)), NODRAW, COLORGREEN;
{FOR DEBUG——配合对CONSTC的调节,使用}
{INFO_TJ: 2016=YEAR AND 7=MONTH AND 15=DAY AND 14=HOUR AND 0=MINUTE AND NOT(ISLASTBAR);}
{INFO_A:=STRCAT('INFO_A=', STRCAT(CON2STR(REF(MONTH, REF_BAR_A), 0), STRCAT('-', STRCAT(CON2STR(REF(DAY, REF_BAR_A), 0), STRCAT(' ', STRCAT(CON2STR(REF(HOUR, REF_BAR_A), 0), STRCAT(':', CON2STR(REF(MINUTE, REF_BAR_A), 0)) ))))));}
{角度计算方法1:将四个参照点的角度求平均}
{通过归一化,将TAN1,TAN2,变成0-100的数值}
DELT_CLOSE:CLOSE-REF(CLOSE, REF_BAR), NODRAW;
DELT_OBV: OBV-REF(OBV, REF_BAR), NODRAW;
TAN_C :100*DELT_CLOSE/ABS(REF(CLOSE, REF_BAR)), NODRAW;
TAN_O :100*DELT_OBV/ABS(REF(OBV, REF_BAR)), NODRAW;
TAN_CO_UP:100*(TAN_C-TAN_O), NODRAW;
TAN_CO_DOWN:(100*100+TAN_C*TAN_O), NODRAW;
TAN_CO: IF (0=REF_BAR, 0, 100*(TAN_C-TAN_O)/(100*100+TAN_C*TAN_O) ), COLORWHITE, NODRAW;
BEILI10:=DELT_CLOSE>0 AND DELT_OBV<0, NODRAW;{价升量跌}
BEILI20:=DELT_CLOSE<0 AND DELT_OBV>0, NODRAW;{价跌量升}
BEILI: IF (BEILI10, 10,
IF (BEILI20, 20,
0)), NODRAW;
{B/S}
{注意不一定是价升量跌才是卖出信号,高位价跌量升也是卖出信号}
TJ: IF (TJ10, 10,
IF (TJ20, 20,
IF (TJ11, 11,
IF (TJ21, 21,
0)))), NODRAW;
WS: IF(TJ10 AND BEILI=10, 1, 0), COLORRED, NODRAW;{WARNNING}
WB: IF(TJ20 AND BEILI=20, 1, 0), COLORGREEN, NODRAW;{WARNNING}
S: IF(TJ11 AND BEILI>0, 1, 0), COLORRED, NODRAW;{LIFE AND DEATH}
B: IF(TJ21 AND BEILI>0, 1, 0), COLORGREEN, NODRAW;{LIFE AND DEATH}
{显示}
TAN_OUT:TAN_CO, NODRAW;
MATAN12:MA(TAN_CO,M), NODRAW;
{
DRAWICON(WS, ICONPOS*1.005, 6);
DRAWICON(WB, ICONPOS*0.995, 5);
DRAWICON(S, ICONPOS*1.01, 8);
DRAWICON(B, ICONPOS*0.99, 7);
DRAWICON(WS AND NOT(S), ICONPOS*1.005, 6);
DRAWICON(WB AND NOT(B), ICONPOS*0.995, 5);
DRAWICON(S, ICONPOS*1.01, 8);
DRAWICON(B, ICONPOS*0.99, 7);
}
{========================箱体突破===============================}
支撑价:LLV(OBV,34) ,COLOR7FFF00,LINETHICK2;
阻力价:HHV(OBV,19),COLORFF9900, LINETHICK2;
BOXDOWN:=支撑价<REF(支撑价, 1) AND REF(支撑价, 1)<REF(支撑价, 2) AND REF(支撑价, 2)<REF(支撑价, 3) AND REF(支撑价, 3)<REF(支撑价, 4), NODRAW;{60分钟内连续下跌}
BOXDUP :=阻力价>REF(阻力价, 1) AND REF(阻力价, 1)>REF(阻力价, 2) AND REF(阻力价, 2)>REF(阻力价, 3) AND REF(阻力价, 3)>REF(阻力价, 4), NODRAW;{60分钟内连续下跌}
{
DRAWICON(BOXDOWN, ICONPOS*0.985, 2);
DRAWICON(BOXDUP, ICONPOS*1.015, 1);
};