我正试图写一个策略。我要卖的价格是_1.01的买入价。如果买入价格是50,卖出价格是50_1.01= 50.5
下面是我的代码:
strategy("test",pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
rsi = rsi(close,6)
ilong = input(23, title="period")
isig = input(3, title="signal")
bcwsma(s,l,m) =>
_s = s
_l = l
_m = m
_bcwsma = (_m*_s+(_l-_m)*nz(_bcwsma[1]))/_l
_bcwsma
c = close
h = highest(high, ilong)
l = lowest(low,ilong)
RSV = 100*((c-l)/(h-l))
pK = bcwsma(RSV, isig, 1)
pD = bcwsma(pK, isig, 1)
pJ = 3 * pK-2 * pD
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
plot(pK, color=orange)
plot(pD, color=lime)
plot(pJ, color=fuchsia)
bgcolor(pJ>pD? green : red, transp=70)
entry_price = strategy.opentrades.entry_price(strategy.opentrades-1)
sell_price = entry_price * 1.01
shortCondition = sell_price
longCondition = crossover(pJ,pD) and macdLine > -0.5
strategy.entry("Buy", strategy.long, when=longCondition)
strategy.close("Buy", when=shortCondition)
发布于 2022-08-22 08:36:10
如果您想将您的利润设置为1%,请使用strategy.position_avg_price
内置变量。
long_take_profit_price = strategy.position_avg_price * 1.01 // 1%然后将该变量传递给strategy.exit()
调用的limit
参数。
如果您真的想找出buy_price * 1.01
,可以使用strategy.opentrades.entry_price()
内置函数来获得入门价格。
entry_price = strategy.opentrades.entry_price(strategy.opentrades-1)
sell_price = entry_price * 1.01
https://stackoverflow.com/questions/73442177
复制相似问题