计算均线LLT

用户头像mx_***307okn
2023-10-15 发布

均线LLT

低延迟趋势线 LLT

  1. 概念:在EMA的基础上的进一步改良
  2. 优缺点:
    1. 优点:可以在平滑趋势线的同时尽量跟紧趋势,解决“时滞”问题。
    2. 缺点:拐点处可能出现切线方向变动较为频繁的现象。
  3. 数学公式:

代码

# 均线LLT
def llt(context,bar_dict):
    import pandas as pd
    g.yb=100+g.n
    #需按分钟运行。按分钟运行能取到当日的指标,若按日运行只能取到昨日指标且需要调整代码
    end_date = get_datetime().strftime('%Y%m%d %H:%M')
    df1 = get_price(securities=[context.security], end_date=end_date, fre_step='60m', fields=['close'], skip_paused = False, fq = 'pre', bar_count = g.yb, is_panel = 1)
    df2 = get_price(securities=[context.security], end_date=end_date, fre_step='1m', fields=['close'], skip_paused = False, fq = 'pre', bar_count = g.yb, is_panel = 1)
    a1=float(2)/(g.n+1)
    c1=df1['close'][context.security][-1]
    c2=df1['close'][context.security][-2]
    c0=df2['close'][context.security][-1]
    y=[df1['close'][context.security][0],df1['close'][context.security][1]]
    for i in range(g.yb-2):
        a=(a1-a1*a1/4)*df1['close'][context.security][i+2]+(a1*a1/2)*df1['close'][context.security][i+1]-(a1-3*a1*a1/4)*df1['close'][context.security][i]+2*(1-a1)*y[-1]-(1-a1)*(1-a1)*y[-2];
        y.append(a)
    b=(a1-a1*a1/4)*c0+(a1*a1/2)*df1['close'][context.security][g.yb-1]-(a1-3*a1*a1/4)*df1['close'][context.security][g.yb-2]+2*(1-a1)*y[-1]-(1-a1)*(1-a1)*y[-2];
    y.append(b)
  
    return y

评论