首页 > 解决方案 > 如何在 Pine Editor 中添加代码以交叉检查同一股票代码的不同时间范围的图表

问题描述

到目前为止,我有一个程序,使用箭头指示 MACD 和 Stoch RSI 和 RSI 的价格低于超卖水平或 MACD 和 Stoch RSI 和 RSI 高于超买水平。虽然买入和卖出都有好的入口,但仍然有很多不好的入口。我想添加将“D”的低 MACD 与“1m”的低 MACD 进行比较的代码。如果两者的 MACD 均较低,则指标将显示为“D”。这将有助于消除大部分虚假条目。我遇到的唯一问题是我似乎无法编写一个代码来交叉检查'1m'的MACD和'D'的MACD。如果可能,请查看并回答。谢谢!

//@version=4
study(title = "Long_entry", shorttitle = 'long', overlay = true, precision = 6)
//overlay = true to have it on price graph
//overlay = false to have it separately




//user input
rsiLength = 21
rsiOB = 70.00
rsiOS = 50.00

//Check RSI signal
rsi =  rsi(close, rsiLength)
rsi_bear = rsi >= rsiOB
rsi_bull = rsi <= rsiOS


//Input Stoch RSI
smoothK = 3
smoothD = 3
lengthRSI = 21
lengthStoch = 21
src = close
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)

stoch_bull = if d > k and d< 30.00 and k<30.00
    true
else if crossunder(d, k) and d< 30.00 and k<30.00
    true

stoch_bear = iff(d< k and k > 80.00 and d > 80.00, true, false)

//Input MACD
fast_length = 12
slow_length = 26
src_macd = close
signal_length = 9
sma_source = false
sma_signal = false
fast_ma = sma_source ? sma(src_macd, fast_length) : ema(src_macd, fast_length)
slow_ma = sma_source ? sma(src_macd, slow_length) : ema(src_macd, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)
diff = macd - signal
macd_bull = if macd <= signal and macd < 0 and signal < 0
    true
else if diff < 0.02 and macd <0 and signal < 0
    true
macd_bear = iff(macd >= signal and macd > 0, true, false)

//*Double check with MACD from 1m

//*new_frame_blue = security(syminfo.tickerid, "1m", macd)
//*new_frame_orange = security(syminfo.tickerid, "1m", signal)
//
//*confirm = if(new_frame_blue > 0 and new_frame_orange>0 and new_frame_blue < new_frame_orange)
//*   true

good_entry = rsi_bull and stoch_bull and macd_bull
good_sell = rsi_bear and stoch_bear and macd_bear

//Draw indicator to chart
plotshape(good_entry, style =shape.arrowup, color = color.green, location = location.belowbar, title="Buy signal" )
plotshape(good_sell, style =shape.arrowdown, color = color.white, location = location.abovebar, title="Sell signal" )

我用 * 表示了我最新的失败代码

标签: pine-script

解决方案


推荐阅读