Pinescript警报strategy.exit

时间:2020-05-30 22:02:25

标签: pine-script algorithmic-trading

我的交易视图有问题,pinescript。

我陷入了困境,我已将策略转变为研究警报。买卖警报将转换为警报,但是主要问题是,我无法在具有警报条件的研究中转换strategy.exit代码。有没有办法我也可以将其转换为警报?

下面是我的代码:

//@version=4
strategy("My Strategy", overlay=true)

strategy.entry("Buy", strategy.long, when=crossover(sma(close, 14), sma(close, 28)), comment="Buy")
strategy.exit("Buy", trail_points=100, loss=100, comment="Exit")

strategy.entry("Sell", strategy.short, when=crossover(sma(close, 14), sma(close, 28)), comment="Sell")
strategy.exit("Sell", trail_points=100, loss=100, comment="Exit")

loss =当价格距触发的买入/卖出价格相差100刻时,则出现退出条件。因此损失固定为100。

trail_points =当价格到来时,买/卖定单上的价格上涨了100个报价,然后在收盘价结束时出现了退出条件。蜡烛收盘时,利润是可变的,但在100时触发。

可以在警报状态下给出这两种退出策略吗?我无法在警报中转换整个策略。

1 个答案:

答案 0 :(得分:0)

您必须跟踪自己的头寸并停止变量损失。 (isLong,isShort,stopPrice等),然后根据您的进入和退出条件进行更新。 对于尾随止损,您必须在每根蜡烛上对其进行更新,并且检查它是否在每根蜡烛上都命中。 正确地将所有内容都跟踪为变量后,便可以根据需要调用alertcondition。

这篇文章也许可以帮助您:https://marketscripters.com/pine-script-strategy-vs-study/