Skip to content

Commit

Permalink
添加通达信BOLL_M指标
Browse files Browse the repository at this point in the history
  • Loading branch information
wukan1986 committed Dec 20, 2024
1 parent a6cc96d commit ae7ff95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions polars_ta/prefix/tdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from polars_ta.tdx.over_bought_over_sold import RSI as ts_RSI # noqa
from polars_ta.tdx.over_bought_over_sold import RSV as ts_RSV # noqa
from polars_ta.tdx.pressure_support import BOLL as ts_BOLL # noqa
from polars_ta.tdx.pressure_support import BOLL_M as ts_BOLL_M # noqa
from polars_ta.tdx.reference import BARSLAST as ts_BARSLAST # noqa
from polars_ta.tdx.reference import BARSLASTCOUNT as ts_BARSLASTCOUNT # noqa
from polars_ta.tdx.reference import BARSSINCE as ts_BARSSINCE # noqa
Expand Down
26 changes: 23 additions & 3 deletions polars_ta/tdx/pressure_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from polars import Expr

from polars_ta.tdx.arithmetic import SQRT
from polars_ta.tdx.reference import MA
from polars_ta.tdx.statistic import STDP

Expand All @@ -13,6 +14,25 @@ def BOLL(close: Expr, M: int = 20, N: int = 2) -> Expr:
ma = MA(close, M)
# it should be total standard deviation, the value is smaller than sample standard deviation.
# 这里是总体标准差,值比样本标准差小。部分软件使用样本标准差是错误的,
_std = STDP(close, M)
UB = ma + _std * N
return UB
std = STDP(close, M)
return ma + std * N


def BOLL_M(close: Expr, M: int = 20, N: int = 2) -> Expr:
"""
{参数 N: 2 250 20 }
MID:=MA(C,N);
VART1:=POW((C-MID),2);
VART2:=MA(VART1,N);
VART3:=SQRT(VART2);
UPPER:=MID+2*VART3;
LOWER:=MID-2*VART3;
BOLL:REF(MID,1),COLORFFFFFF;
UB:REF(UPPER,1),COLOR00FFFF;
LB:REF(LOWER,1),COLORFF00FF;
"""
ma = MA(close, M)
# 这里var不一样
# close-close.mean()与close-MA(close)的区别
std = SQRT(MA((close - ma) ** 2, M))
return ma + std * N

0 comments on commit ae7ff95

Please sign in to comment.