Charts 当较长时间段显示上升趋势时,在较低时间段买入和卖出标记

Charts 当较长时间段显示上升趋势时,在较低时间段买入和卖出标记,charts,pine-script,Charts,Pine Script,所以,我尝试使用KDJ指标在中等时间段(1h-4h)运行一个交易机器人。我知道这不是最灵敏的指标,但它非常可靠,至少在较高的时间范围内(8h-1D)。 我希望能够使用以下脚本向我的机器人发送买入/卖出信号,但仅当资产在1D图表上没有下降趋势时。换句话说,我想运行以下脚本: //@version=4 study(title="KDJ IndicatorTV", shorttitle="KDJ_TV", format=format.price, precisi

所以,我尝试使用KDJ指标在中等时间段(1h-4h)运行一个交易机器人。我知道这不是最灵敏的指标,但它非常可靠,至少在较高的时间范围内(8h-1D)。 我希望能够使用以下脚本向我的机器人发送买入/卖出信号,但仅当资产在1D图表上没有下降趋势时。换句话说,我想运行以下脚本:

//@version=4
study(title="KDJ IndicatorTV", shorttitle="KDJ_TV", format=format.price, precision=2, resolution="", overlay=true)
periodK = input(9, title="K", minval=1)
periodD = input(5, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
multiplierJ = input(3.5, title="Jx", minval=0.1)
k = ema(stoch(hlc3, high, low, periodK), smoothK)
d = ema(k, periodD)
j = multiplierJ * k-2 * d

makeShape1 = if (crossover(j,d) or crossover(j,99))
    true
else
    false

plotshape(series=makeShape1, style=shape.cross, color=#0094FF, transp=10, text="buy", title='buy')

makeShape2 = if (crossunder(j,d) or crossunder(j,99))
    true
else
    false
    
plotshape(series=makeShape2, style=shape.cross, color=#FF6A00, transp=10, text="sell", title='sell')
//end
我想在makeShape1中添加一个条件,比如“如果1D图表上的j>d”,以确保只有当该资产的1D图表上的j大于d时(即:当该资产的市场处于上升趋势时),才会生成购买

关于我是否/如何做到这一点,有什么想法吗

谢谢!
-Daniel

您可以使用
security()
功能访问更高的TFs

//@version=4
study(title="KDJ IndicatorTV", shorttitle="KDJ_TV", format=format.price, precision=2, resolution="", overlay=true)
periodK = input(9, title="K", minval=1)
periodD = input(5, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
multiplierJ = input(3.5, title="Jx", minval=0.1)
k = ema(stoch(hlc3, high, low, periodK), smoothK)
d = ema(k, periodD)
j = multiplierJ * k-2 * d

j_sec = security(syminfo.tickerid, "D", j) // 1 day time frame for j
d_sec = security(syminfo.tickerid, "D", d) // 1 day time frame for d

makeShape1 = if (crossover(j,d) or crossover(j,99)) and j_sec > d_sec
    true
else
    false

plotshape(series=makeShape1, style=shape.cross, color=#0094FF, transp=10, text="buy", title='buy')

makeShape2 = if (crossunder(j,d) or crossunder(j,99))
    true
else
    false
    
plotshape(series=makeShape2, style=shape.cross, color=#FF6A00, transp=10, text="sell", title='sell')
//end

哇-非常感谢。这正是我所需要的。:)@DanielBauer太好了,别忘了对答案进行投票并将其标记为已解决/已接受:)