我的策略是加密货币,直到现在我曾经有这些订单。我想添加利润目标和止损,这意味着我必须使用 strategy.exit
。
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.close("Buy", when = sellCondition)
盈亏是如何计算的?我想要的只是购买价格 + 自定义百分比。换句话说,profit = buy price * (1 + (5 / 100))
。止损也一样,loss = buy price * (1 - (5 / 100))
。或者简单地根据 close + syminfo.mintick
或任何方式计算它。我只是不想要像 55000 这样的数字,往下看。
strategy.exit("Custom sell", "Buy", profit = 55000)
答案 0 :(得分:1)
这样编码:(在这个例子中,TP 和 SL 分别设置为 5% 首先设置这些行:
// Stop Loss settings
StopLossPercent = input(5, title="Stop Loss", minval=0.01, step=0.5)
StopLoss = (close * (StopLossPercent / 100)) / syminfo.mintick
// Take Profit settings
TakeProfitPercent = input(5, title=" Take Profit", minval=0.01, step=0.5)
TakeProfit = (close * (TakeProfitPercent / 100)) / syminfo.mintick
然后对于你的策略,你在你的 strategy.entry 下方写下这一行
strategy.exit("Stop Loss or Take Profit", loss = StopLoss, profit = TakeProfit)