pine script 多行的开头空格不能是四个,以后我形成习惯都是2个空格

在pine script的编码上对于有 一个函数或者一个字符串的多行拼写的时候,一定要记得,多行的开头空格不能是四个,以后我形成习惯都是2个空格吧。这样就不至于老是报错了。
label.new(
bar_index, low, “交叉发生!\nClose=” + str.tostring(close, “#.##”) + “\nMA=” + str.tostring(ma, “#.##”), style=label.style_label_up, color=color.green,
textcolor=color.white,
tooltip = “交叉发生!\nClose=” + str.tostring(close, “#.##”) + “\nMA=” + str.tostring(ma, “#.##”),
size=size.tiny
)// 标签出现在当前 K 线上方

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thanklife

//@version=6
strategy("交叉追踪策略回测", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === 用户输入 ===
length = input.int(14, "MA 周期")
takeProfitPct = input.float(3.0, "止盈 %", step=0.1)
stopLossPct   = input.float(1.5, "止损 %", step=0.1)

// === 指标计算 ===
ma = ta.sma(close, length)
xUp = ta.crossover(close, ma)

// === 计算止盈止损价格 ===
longTakeProfit = close * (1 + takeProfitPct / 100)
longStopLoss   = close * (1 - stopLossPct / 100)

// === 策略执行 ===
// 1. 进场条件:上穿均线
if xUp
    strategy.entry("多头进场", strategy.long)

// 2. 离场条件:止盈或止损(系统会自动触发)
strategy.exit("出场", from_entry="多头进场", 
  limit=longTakeProfit, 
  stop=longStopLoss)


// === 可视化辅助 ===
// 标记交叉点
plot(ma, title="SMA", color=color.orange)
plotshape(xUp, title="上穿", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)

// 标签显示:显示止盈止损价位
if xUp
    label.new(bar_index, low, 
      "进场价: " + str.tostring(close, "#.##") + "\n止盈: " + str.tostring(longTakeProfit, "#.##") + "\n止损: " + str.tostring(longStopLoss, "#.##"),
      style=label.style_label_down, color=color.green, textcolor=color.white, size=size.small)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

零点零一

您的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值