通达信线性回归主图公式
AAA:=REFDATE(HHV(H,120),DATE);
BBB:=REFDATE(LLV(L,120),DATE);
DRAWBAND(AAA,RGB(35,35,65),BBB,RGB(35,35,65));
UR:=10;LR:=10;
{线性回归线}
TC1:=IF(H=HHV(H,8*UR),H,DRAWNULL);
TC2:=CONST(BARSLAST(TC1=H))+1;
UP:CONST(IF(TC2=1,H,REF(H,TC2-1)));
BC1:=IF(L=LLV(L,8*LR),L,DRAWNULL);
BC2:=CONST(BARSLAST(BC1=L))+1;
LL:CONST(IF(BC2=1,L,REF(L,BC2-1)));
LP:=CURRBARSCOUNT =BC2 AND L=LL;{低点定位}
HP:=CURRBARSCOUNT =TC2 AND H=UP;{高点定位}
STICKLINE(IF(BC2 TC2,HP,LP),LL,UP,0,0),COLOR66DDDD,LINETHICK3;
STICKLINE(IF(BC2 TC2,LP,HP),LL,UP,0,0),COLOR66DDDD,LINETHICK3;
NOD:=(IF(TC2 BC2,TC2,BC2)-IF(TC2 BC2,BC2,TC2));{用时}
LR1:=FORCAST(C,NOD+1);
NP:IF(CURRBARSCOUNT =MAX(BC2,TC2),CONST(IF(MIN(TC2,BC2)=1,LR1,REF(LR1,MIN(TC2,BC2)-1))),DRAWNULL),POINTDOT,COLOR93BDA8;{近点}
LR2:=SLOPE(C,NOD+1);
LR3:=CONST(IF(MIN(TC2,BC2)=1,LR2,REF(LR2,MIN(TC2,BC2)-1)));
FP:NP-LR3*(NOD),POINTDOT,COLOR93BDA8;{远点}
EQU:(NP+FP)/2,POINTDOT,COLOR93BDA8;
AD:=ABS(NP-FP);{高差};
DBL:=BARSLAST(BC1!=DRAWNULL)+1;
DBH:=BARSLAST(TC1!=DRAWNULL)+1;
BSP:=IF(BC2 TC2,DBL,DBH)-1;
LRL:=IF(NP FP,FP+AD/NOD*BSP,FP-AD/NOD*BSP);
AT1:=IF(BETWEEN(CURRBARSCOUNT,BC2,TC2) AND H LRL,H,LRL);
AT2:=HHV(AT1-LRL,MAX(BC2,TC2));
AT3:=CONST(BARSLAST(AT1-LRL=AT2));
AT4:=CONST(IF(AT3=0,H,REF(H,AT3)));
AT5:=CONST(IF(AT3=0,AT1-LRL,REF(AT1-LRL,AT3)));
ATL:=LRL+AT5;
UT1:=IF(BETWEEN(CURRBARSCOUNT,BC2,TC2) AND L LRL,L,LRL);
UT2:=HHV(LRL-UT1,MAX(BC2,TC2));
UT3:=CONST(BARSLAST(LRL-UT1=UT2));
UT4:=CONST(IF(UT3=0,H,REF(H,UT3)));
UT5:=CONST(IF(UT3=0,LRL-UT1,REF(LRL-UT1,UT3)));
UTL:=LRL-UT5;
RH:=IF(CURRBARSCOUNT =MIN(BC2,TC2)-10,ATL,CONST(REF(ATL,MIN(BC2,TC2)-11)));{限制高}
RL:=IF(CURRBARSCOUNT =MIN(BC2,TC2)-10,UTL,CONST(REF(UTL,MIN(BC2,TC2)-11)));{限制低}
中轨:IF(NP FP,IF(LRL =RH,LRL,DRAWNULL),IF(LRL =RL,LRL,DRAWNULL)),COLOR66DDDD,LINETHICK3;
上轨:IF(NP FP,IF(ATL =RH,ATL,DRAWNULL),IF(ATL =RL,ATL,DRAWNULL)),COLOR66DDDD,LINETHICK3;
下轨:IF(NP FP,IF(UTL =RH,UTL,DRAWNULL),IF(UTL =RL,UTL,DRAWNULL)),COLOR66DDDD,LINETHICK3;
N1:=N*10;
CY:=BARSLAST(CURRBARSCOUNT=N1);
GD:=CONST(IF(ISLASTBAR=1,HHV(H,CY),0));
DD:=CONST(IF(ISLASTBAR=1,LLV(L,CY),0));
预顶百分比%:(GD-C)/C*100,NODRAW;
H5:=GD-(GD-DD)*0.191;
H4:=GD-(GD-DD)*0.382;
H3:=GD-(GD-DD)*0.5;
H2:=GD-(GD-DD)*0.618;
H1:=GD-(GD-DD)*0.809;
DH5:=STRCAT(STRCAT('80.9% ',CON2STR(H5,3)),'');
DH4:=STRCAT(STRCAT('61.8% ',CON2STR(H4,3)),'');
DH3:=STRCAT(STRCAT('50.0% ',CON2STR(H3,3)),'');
DH2:=STRCAT(STRCAT('38.2% ',CON2STR(H2,3)),'');
DH1:=STRCAT(STRCAT('19.1% ',CON2STR(H1,3)),'');
BASE:=STRCAT(STRCAT('BASE ',CON2STR(DD,3)),' 随浪飞扬');
%100:=STRCAT(STRCAT('100% ',CON2STR(GD,3)),'');
DRAWBAND(IF(CURRBARSCOUNT =1,DD,DRAWNULL),
RGB(16,36,46),IF(CURRBARSCOUNT =N1,DD,DRAWNULL)-(H4-H3)/2,RGB(0,0,0));
{DRAWBAND(IF(CURRBARSCOUNT =N1,GD,DRAWNULL)+(H4-H3)/2,
RGB(16,36,46),IF(CURRBARSCOUNT =N1,DD,DRAWNULL)-(H4-H3)/2,RGB(0,0,0));}{背景}
DRAWKLINE(H,O,L,C);
DRAWBAND(IF(CURRBARSCOUNT =N1,H1,DRAWNULL),RGB(200,0,200),H1,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,H2,DRAWNULL),RGB(200,0,200),H2,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,H3,DRAWNULL),RGB(200,0,200),H3,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,H4,DRAWNULL),RGB(200,0,200),H4,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,H5,DRAWNULL),RGB(200,0,200),H5,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,GD,DRAWNULL),RGB(200,0,200),GD,RGB(0,0,0));
DRAWBAND(IF(CURRBARSCOUNT =N1,DD,DRAWNULL),RGB(200,0,200),DD,RGB(0,0,0));
DRAWTEXT(CURRBARSCOUNT=N1-1,H5,DH5),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,H4,DH4),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,H3,DH3),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,H2,DH2),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,H1,DH1),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,DD,BASE),COLORAA99AA;
DRAWTEXT(CURRBARSCOUNT=N1-1,GD,%100),COLORAA99AA;
{K线优化}
STICKLINE(CLOSE =OPEN,HIGH,LOW,0,1 ),COLOR5B5BFF;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,2.7,0 ),COLOR0000CC;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,2,0 ),COLOR0E0EFF;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,1.2,0 ),COLOR4848FF;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,0.6,0 ),COLOR7878FF;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,0.1,0 ),COLORA1A1FF;
STICKLINE(CLOSE =OPEN,OPEN,CLOSE,0,0 ),COLORCACAFF;
STICKLINE(CLOSE OPEN,HIGH,LOW,0,1 ),COLORCYAN;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,2.7,0 ),COLOR990000;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,2,0 ),COLORCC0000;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,1.2,0 ),COLORFF4400;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,0.6,0 ),COLORFF8800;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,0.1,0 ),COLORFFCC00;
STICKLINE(CLOSE OPEN,OPEN,CLOSE,0,0 ),COLORCYAN;