松文脚本如何存储我的入境条件的高/低点?

发布于 2025-01-19 01:02:55 字数 1017 浏览 0 评论 0原文

我想测试一个简单的策略。 如果我的条件“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清君侧 2025-01-26 01:02:55

您可以使用var关键字来保持每个执行的变量值相同。

因此,您可以执行以下操作:

var float my_high = na
var float my_low = na

if (Test_Bar)
    my_high := high
    my_low := low

You can use the var keyword to keep a variable's value the same for each execution.

So, you can do the following:

var float my_high = na
var float my_low = na

if (Test_Bar)
    my_high := high
    my_low := low
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文