0

我需要一些有关 pine 脚本的帮助,因为我不熟悉脚本。问题是算法在前三个订单打开后停止而不继续。我想添加三个连续的订单,每个订单都有其 SL 和 TP。

第一个订单 O1 应该在 CP 开仓,SL 在 CP * 1.01 和 SL 在 CP * 0.98

如果价格下跌 0.1% 第二个订单 O2 应该在 CP * 0.99 开仓,SL 在 CP * 1.01 和 SL 在 CP * 0.97

当 O2 开仓时,O1 的 TP 应更改为 CP * 1.00 等等,当价格以每 0.1% 的步幅下跌时。

如果一个 TP 被关闭,所有其他订单都应该被关闭并重置流程。

使用下面的代码,订单只打开一次,然后算法不会继续。这是我们遇到的问题。

O - 订单 / CP - 当前价格 / SL - 止损 / TP - 获利

//@version=4
strategy(title="Example", overlay=true)

get_dolInBTC(x) =>
    x / close

var firstPrice = 0.0
var secondPrice = 0.0
var thirdPrice = 0.0

calc_on_every_tick=true

if (firstPrice == 0.0)
    firstPrice := close
    strategy.entry("10", strategy.long, get_dolInBTC(10), limit=firstPrice)
    strategy.exit("10 exit", "10", profit = close * 0.02 / syminfo.mintick, loss = close * 0.02 / syminfo.mintick)

if (close < firstPrice * 0.99 and secondPrice == 0.0)
    secondPrice := close * 0.99
    strategy.entry("20", strategy.long, get_dolInBTC(20), limit=secondPrice)
    strategy.exit("10 exit", "10", profit = close * 0.0 / syminfo.mintick, loss = close * 0.002 / syminfo.mintick)
    strategy.exit("20 exit", "20", profit = close * 0.01 / syminfo.mintick, loss = close * 0.02 / syminfo.mintick)

if (close < secondPrice * 0.99 and thirdPrice == 0.0)
    thirdPrice := close * 0.98
    strategy.entry("40", strategy.long, get_dolInBTC(40), limit=thirdPrice)
    strategy.exit("20 exit", "20", profit = close * 0.00 / syminfo.mintick, loss = close * 0.02 / syminfo.mintick)
    strategy.exit("40 exit", "40", profit = close * 0.01 / syminfo.mintick, loss = close * 0.02 / syminfo.mintick)

希望您能提供帮助,非常感谢!:)

4

0 回答 0