松文脚本如何存储我的入境条件的高/低点?
我想测试一个简单的策略。 如果我的条件“Test_Bar”发生,我想存储该柱的蜡烛高点(“Bar_high”)。如果在一些蜡烛之后价格达到“柱高”,我想以此价格执行买入限价订单。计算止损和止盈
(这里是一个示例https://cdn.discordapp.com/attachments/669368497767448596/960639771183570974/unknown.png)
但是脚本不起作用=( 有人可以帮我吗?
strategy("Test-Bar", overlay=true)
number=input(10)
Test_Bar = high>high[2] and low<low[2]
if (Test_Bar==true)
Bar_high := high
Bar_low := low
//Stoploss + Take profit
SL = input(0.5)
TP = input(2.5)
longstop = (Bar_high - Bar_low)*SL + Bar_low //Stop-Loss calculated
longprofit = longstop * TP + Bar_high //Take Profit Calculated
//Position entry + exit
strategy.entry("My Long Entry Id", strategy.long, limit=Bar_high)
if strategy.position_avg_price >0
strategy.exit(stop=longstop or stop=longprofit)
[1]: https://i.sstatic.net/LWy3F.png
[2]: https://i.sstatic.net/bseQi.png
I want to test a simple strategy.
If my Condition "Test_Bar" is happening, I want to store the Candle high ("Bar_high) of this bar. If after some candles the price reaches the "Bar-high", I want to execute a Buy limit order at this price. Stop Loss and Take profit are calculated.
(Here an example https://cdn.discordapp.com/attachments/669368497767448596/960639771183570974/unknown.png)
But the script doesn't work =(
Can anybody help me pls?
strategy("Test-Bar", overlay=true)
number=input(10)
Test_Bar = high>high[2] and low<low[2]
if (Test_Bar==true)
Bar_high := high
Bar_low := low
//Stoploss + Take profit
SL = input(0.5)
TP = input(2.5)
longstop = (Bar_high - Bar_low)*SL + Bar_low //Stop-Loss calculated
longprofit = longstop * TP + Bar_high //Take Profit Calculated
//Position entry + exit
strategy.entry("My Long Entry Id", strategy.long, limit=Bar_high)
if strategy.position_avg_price >0
strategy.exit(stop=longstop or stop=longprofit)
[1]: https://i.sstatic.net/LWy3F.png
[2]: https://i.sstatic.net/bseQi.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
var
关键字来保持每个执行的变量值相同。因此,您可以执行以下操作:
You can use the
var
keyword to keep a variable's value the same for each execution.So, you can do the following: