首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何设定售价=买入价格* 1.01?

如何设定售价=买入价格* 1.01?
EN

Stack Overflow用户
提问于 2022-08-22 08:27:54
回答 1查看 84关注 0票数 -1

我正试图写一个策略。我要卖的价格是_1.01的买入价。如果买入价格是50,卖出价格是50_1.01= 50.5

下面是我的代码:

代码语言:javascript
运行
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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()内置函数来获得入门价格。

代码语言:javascript
运行
复制
entry_price = strategy.opentrades.entry_price(strategy.opentrades-1)
sell_price = entry_price * 1.01
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73442177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档