如何在采取职位之前记住行动

发布于 2025-01-25 09:23:46 字数 1349 浏览 2 评论 0原文

我试图将停止损失设置在位置打开并保存之前发生的最后一个枢轴点。我的问题是,我无法成功保存它,因此每当市场提出新的枢纽时,它总是会移动并遵循该职位。

这是枢轴点的代码:

// PIVOTS
lengthGroupTitle = "LENGTH LEFT / RIGHT"
colorGroupTitle = "Text Color / Label Color"
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
textColorH = input(title="Pivot High", defval=color.black, inline="Pivot High", group=colorGroupTitle)
labelColorH = input(title="", defval=color.white, inline="Pivot High", group=colorGroupTitle)

leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
textColorL = input(title="Pivot Low", defval=color.black, inline="Pivot Low", group=colorGroupTitle)
labelColorL = input(title="", defval=color.white, inline="Pivot Low", group=colorGroupTitle)

ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
lastph = ph
lastpl = pl

drawLabel(_offset, _pivot, _style, _color, _textColor) =>
    if not na(_pivot)
        label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)

谢谢

I'm trying to set my stop loss at the last pivot point that happened before the position opened and save it. My issue is that I don't succeed in saving it so it will always move and follow the position everytime the market make a new pivot point.

Here is the code for the pivot point :

// PIVOTS
lengthGroupTitle = "LENGTH LEFT / RIGHT"
colorGroupTitle = "Text Color / Label Color"
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
textColorH = input(title="Pivot High", defval=color.black, inline="Pivot High", group=colorGroupTitle)
labelColorH = input(title="", defval=color.white, inline="Pivot High", group=colorGroupTitle)

leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
textColorL = input(title="Pivot Low", defval=color.black, inline="Pivot Low", group=colorGroupTitle)
labelColorL = input(title="", defval=color.white, inline="Pivot Low", group=colorGroupTitle)

ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
lastph = ph
lastpl = pl

drawLabel(_offset, _pivot, _style, _color, _textColor) =>
    if not na(_pivot)
        label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)

Thank you

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

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

发布评论

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

评论(1

携余温的黄昏 2025-02-01 09:23:46

您可以使用var变量

var是用于分配和一次性初始化的关键字
变量。

通常,变量分配的语法,没有
包括关键字var,导致变量的值为
覆盖数据的每一个更新。与此相反,当
用关键字var分配变量,它们可以“保持状态”
尽管有数据更新,只有在情况内的条件时才将其更改
if-expressions被满足。

或使用ta.valuewhen()

返回source系列的值
条件在第n个最近发生的情况下是正确的。

ta.valuewhen(条件,来源,发生)→串联浮点

//@version=5
indicator("ta.valuewhen")
slow = ta.sma(close, 7)
fast = ta.sma(close, 14)
// Get value of `close` on second most recent cross
plot(ta.valuewhen(ta.cross(slow, fast), close, 1))

You can either use a var variable

var is the keyword used for assigning and one-time initializing of the
variable.

Normally, a syntax of assignment of variables, which doesn’t
include the keyword var, results in the value of the variable being
overwritten with every update of the data. Contrary to that, when
assigning variables with the keyword var, they can “keep the state”
despite the data updating, only changing it when conditions within
if-expressions are met.

Or use ta.valuewhen()

Returns the value of the source series on the bar where the
condition was true on the nth most recent occurrence.

ta.valuewhen(condition, source, occurrence) → series float

//@version=5
indicator("ta.valuewhen")
slow = ta.sma(close, 7)
fast = ta.sma(close, 14)
// Get value of `close` on second most recent cross
plot(ta.valuewhen(ta.cross(slow, fast), close, 1))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文