松树脚本策略Stoploss和Take -Profit问题
我尝试编写带有止损和止盈的策略。信号栏之后,宣布入场(蓝线)、止损(红线)和止盈(绿线)。
问题一:建仓时触发止损。即使价格没有触及红线。我做错了什么? (比较 Imagelink) 1
问题 2:当仓位平仓后,在下一根柱线进入新仓位。即使价格高于入场价(蓝线)。这些购买不应该发生。 (比较 Imagelink) 2
这是我的代码:
//Stoploss + Take profit
SL = input.float(0.5, step=0.1)
TP = input.float(2.5, step=0.1)
buyprice = BB_high
longstop = BB_high - (BB_high - BB_low)*SL
longprofit = BB_high + (BB_high - BB_low)/2 * TP
plot (longstop, color=color.red, linewidth=2)
plot (longprofit, color=color.green, linewidth=2)
//Position entry + exit (stoploss or takeprofit)
strategy.entry("Buy", strategy.long, stop=buyprice)
if strategy.position_size >0
strategy.exit (id="Long SL", from_entry="Buy", limit=longstop)
strategy.exit (id="Long TP", from_entry="Buy", stop=longprofit)
I tried to code a strategy with Stoploss and Takeprofit. After the signal bar, the entry (blue Line), stoploss (red line) and takeprofit (green line) are declared.
Problem 1: When a position is entered, the stoploss is triggered. Even if the red line is not touched by the price. What am i doing wrong? (compare Imagelink) 1
Problem 2: When a position is closed, a new position is entered at the next bar. Even if the price is higher than the entry price (blue line). These buys should not happen. (compare Imagelink) 2
Here my Code:
//Stoploss + Take profit
SL = input.float(0.5, step=0.1)
TP = input.float(2.5, step=0.1)
buyprice = BB_high
longstop = BB_high - (BB_high - BB_low)*SL
longprofit = BB_high + (BB_high - BB_low)/2 * TP
plot (longstop, color=color.red, linewidth=2)
plot (longprofit, color=color.green, linewidth=2)
//Position entry + exit (stoploss or takeprofit)
strategy.entry("Buy", strategy.long, stop=buyprice)
if strategy.position_size >0
strategy.exit (id="Long SL", from_entry="Buy", limit=longstop)
strategy.exit (id="Long TP", from_entry="Buy", stop=longprofit)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
限制
以获取利润和停止
以进行停止损失。你把那些混在一起了。Use
limit
for take profit andstop
for stop loss. You got those mixed up.