我无法在绘图()和浮点变量上克服的基本问题

发布于 2025-01-31 19:05:16 字数 1014 浏览 3 评论 0原文

我在这里要问的是太简单了,但我在编程和pinescript上的新手不太好。 我试图编写一种基本策略,以便准备好算法,然后在编写整个策略之前查看其是否有效,以将其编写为指标。 我有几个问题。首先是系列浮动和整数。为了过来,我尝试了一些愚蠢的想法将我的var定义为已经定义的浮子,就像这里:

Sar = ta.sar(0.02, 0.02, 0.2)
[BBmiddle, BBupper, BBlower] = ta.bb(close, 20, 2)
SarMid = BBmiddle-BBmiddle
SarMidH = SarMid
stopP = SarMid

然后在我的if上使用它们:

if Sar[2] > close[2] and Sar[1] < close[1]
    stopP := BBlower,
    takeP1 := open - BBlower

然后更好地可视化,我使用了这样的绘图形状:

plotshape(stopP, color=color.red, style=shape.triangleup, text="Stop Point", location=location.absolute)
plotshape(takeP1, color=color.green, style=shape.triangledown, text="Take Profit Point 1", location=location.absolute)

到目前为止, '但是在这个阶段,主要问题是图表也将这些图也放在图表的底部。我猜这是因为我之前已经定义了stopp和takep1,但是我无法在if中创建它们。什么会帮助我克服这一点?预先感谢您

“这就是它的样子”

most probably what im going to ask here is too simple but im not that much good on programming and total newbie on pinescript.
im trying to write a basic strategy, in order to ger algo ready and see if its working before writing whole strategy im writing it as an indicator.
im having a couple of issues. first, series float and integer. in order to over come this i tried some silly idea to define my vars to tw already defined floats, like here:

Sar = ta.sar(0.02, 0.02, 0.2)
[BBmiddle, BBupper, BBlower] = ta.bb(close, 20, 2)
SarMid = BBmiddle-BBmiddle
SarMidH = SarMid
stopP = SarMid

then used them on my if's like:

if Sar[2] > close[2] and Sar[1] < close[1]
    stopP := BBlower,
    takeP1 := open - BBlower

and then to better visualize this i used plotshapes like this:

plotshape(stopP, color=color.red, style=shape.triangleup, text="Stop Point", location=location.absolute)
plotshape(takeP1, color=color.green, style=shape.triangledown, text="Take Profit Point 1", location=location.absolute)

so far so good'ish' but at this stage main problem im having is chart puts these plots to the very bottom of chart as well. im guessing its because i've already defined stopP and takeP1 before but i cant create them inside the if. what would help me to overcome this? thank you in advance

this is how it looks like

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2025-02-07 19:05:16

sarmid始终是零(bbmiddle-bbmiddle),除非您在其他地方修改其值。

SarMid = BBmiddle-BBmiddle  // This is zero
SarMidH = SarMid  // Hence, SarMidH is zero too
stopP = SarMid    // Hence, stopP is zero too

您仅修改stopp当您的条件为true时。否则,它将保留

由于您使用的location = location.absolute在基于stopp绘制形状时,它将这些形状绘制为

SarMid is always zero (BBmiddle-BBmiddle) at the beginning unless you modify its value somewhere else.

SarMid = BBmiddle-BBmiddle  // This is zero
SarMidH = SarMid  // Hence, SarMidH is zero too
stopP = SarMid    // Hence, stopP is zero too

You only modify stopP when your condition is true. Otherwise, it will remain zero.

Since you are using location=location.absolute when plotting your shape based on stopP, it plots those shapes at zero

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文