首页 > 解决方案 > 需要一个简单的 Pinescript 代码的帮助

问题描述

我可能拥有最简单的 pine 脚本之一,出于某种原因,我只能显示“卖出”绘图形状,而不能显示“买入”绘图形状。我不知道这段代码有什么问题,请有人帮忙!这是我的脚本:

// © tommyf1001

//@version=4
study(title="EMAs + Stoch RSI", overlay=true, resolution="")


// ---------- Indicators

smoothK = input(3, "K", minval=1, group="Stoch RSI")
smoothD = input(3, "D", minval=1, type=input.integer, group="Stoch RSI")
lengthRSI = input(14, "RSI Length", minval=1, group="Stoch RSI")
lengthStoch = input(14, "Stochastic Length", minval=1, group="Stoch RSI")
stoch_low = input(10, title="Stoch Low", group="Stoch RSI")
stoch_high = input(90, title="Stoch High", group="Stoch RSI")

ema_1 = input(21, "EMA Fast", group="EMAs")
ema_2 = input(50, "EMA Slow", group="EMAs")


// ------------- Functions

// --------- Stoch RSI
rsi1 = rsi(close, lengthRSI)
stoch_k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
stoch_d = sma(stoch_k, smoothD)

stoch_rsi_bull = (barssince(stoch_k < stoch_low) <= 10 and crossover(stoch_k, stoch_low))
stoch_rsi_bear = (barssince(stoch_k > stoch_high) <= 10 and crossunder(stoch_k, stoch_high))


// --------- EMAs

ema_bull = (ema_1 > ema_2)
ema_bear = (ema_1 < ema_2)

bull = (ema_bull and stoch_rsi_bull)
bear = (ema_bear and stoch_rsi_bear)


// -----------------------------------------------------------
// Plots

plotshape(bull ? close : na, title='Buy', style=shape.arrowup, location=location.belowbar, color=color.green, text='Buy', size=size.small)
plotshape(bear ? close : na, title='Sell', style=shape.arrowdown, location=location.abovebar, color=color.red, text='Sell', size=size.small)```

标签: pine-script

解决方案


我认为这正如预期的那样,ema_bull 和 ema_bear 之间存在负相关。如果 ema_bull 为真,那么 ema_bear 应该为假,反之亦然。如果 (ema_1 > ema_2) 为真,则 (ema_1 < ema_2) 为假。这就是为什么 plotshape 只绘制这两者之一的原因。


推荐阅读