求python大佬翻一个tradingview指标到python

查看 40|回复 0
作者:一只小怪兽   
   
尝试翻译了不到100行菜鸡真的翻译不出来啊
这是指标地址 https://cn.tradingview.com/script/aRxQ1g82-QQE-Weighted-Oscillator-LuxAlgo/
只要能计算出  rsi 和ts 两个数值就好  代码在最底下
[ol]// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("QQE Weighted Oscillator [LuxAlgo]", "LuxAlgo - QQE Weighted Oscillator")
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(14, minval = 1)
factor = input.float(4.236, minval = 0)
smooth = input.int(5, minval = 1)
weight = input.float(2)
src    = input(close)
//Style
rsiCss = input(#3179f5, 'RSI', group = 'Style')
tsBearCss = input(color.red, 'Trailing Stop', group = 'Style', inline = 'inline1')
tsBullCss = input(color.teal, '', group = 'Style', inline = 'inline1')
//-----------------------------------------------------------------------------}
//Weighted QQE
//-----------------------------------------------------------------------------{
var ts = 0.
var rsi = 0.
delta = src - src[1]
w = nz(delta * (rsi - ts) > 0 ? weight : 1, 1)
//Rsi
num = ta.rma(delta * w, length)
den = ta.rma(math.abs(delta * w), length)
rsi := 50 * ta.ema(num / den, smooth) + 50
//Trailing stop
diff = ta.rma(math.abs(rsi - rsi[1]), length)
crossover = ta.crossover(rsi, ts)
crossunder = ta.crossunder(rsi, ts)
ts := nz(crossover ? rsi - diff * factor
  : crossunder ? rsi + diff * factor
  : rsi > ts ? math.max(rsi - diff * factor, ts)
  : math.min(rsi + diff * factor, ts), rsi)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css = rsi > ts ? tsBullCss : tsBearCss
plot_rsi = plot(rsi, 'RSI', rsiCss)
plot_ts  = plot(ts, 'Traling Stop', css)
fill(plot_rsi, plot_ts, rsi, ts, color.new(rsiCss, 50), color.new(css, 50))
hline(70)
hline(30)
//-----------------------------------------------------------------------------}[/ol]复制代码
我自己想办法翻译 的 不行啊  
[ol]def crossover(a, b):
        """
        检查两个指标是否在给定时间点交叉。
        Args:
            a: 第一个指标值。
            b: 第二个指标值。
        Returns:
            如果两个指标在给定时间点交叉,则返回 True,否则返回 False。
        """
        if a[-1] = b[-2]:
            return True
        elif a[-1] >= b[-1] and a[-2] 复制代码
[ol]
        # Settings
        length = 14  # RSI 计算长度
        factor = 4.236  # 追踪止损因子
        smooth = 5  # RSI 平滑周期
        weight = 2  # 基于追踪止损对 RSI 应用的权重
        src =  dataframe['close'] # 输入数据(通常是收盘价)
        # 加权 QQE
        ts = 0.0  # 追踪止损值
        rsi = 0.0  # 相对强弱指数值
        # 计算差额
        delta = src - src[1]
        # 计算权重
        w = 1.0 if delta * (rsi - ts)  ts else min(rsi + diff * factor, ts)[/ol]复制代码

止损, 指标, 代码

您需要登录后才可以回帖 登录 | 立即注册

返回顶部