Làm thế nào để chiến lược ngôn ngữ Pine thực hiện vòng lặp từ dưới xuống, và bây giờ chỉ có một từ sau mà không có tiếp tục.

Tác giả:CryptoLiu, Tạo: 2022-11-14 10:11:47, Cập nhật:

//@version=4 chiến lược ((title=EMA crosses, overlay=true)

// Input priceData = input ((title=Price data, type=input.source, defval=hl2) Ema1Length = input(title=EMA 1, type=input.integer, defval=12) Ema2Length = input ((title=EMA 2, type=input.integer, defval=24) Ema3Length = input ((title=EMA 3, type=input.integer, defval=36)

// Tính toán giá trị ema1 = ta.ema ((giá dữ liệu, ema1Length) ema2 = ta.ema ((giá dữ liệu, ema2Dài) ema3 = ta.ema ((giá dữ liệu, ema3Length)

enterLong = ema1 > ema2 và ema2 > ema3 enterShort = ema1 < ema2 và ema2 < ema3

// Giá trị đồ thị plot ((series=ema1, color=color.orange, linewidth=2) plot ((series=ema2, color=color.maroon, linewidth=2) plot ((series=ema3,color=color.blue, chiều rộng đường = 2)

// Gửi lệnh if (enterLong) strategy.entry ((id=Enter Long, long=strategy.long)

if (enterShort) strategy.entry ((id=Enter Short, long=strategy.short)

Hiện tại, trong quá trình kiểm tra lại, bộ mã này luôn luôn bắt đầu với một lệnh, sau đó các lệnh khác dường như không được kích hoạt, ai có thể hướng dẫn cách thực hiện vòng lặp chính sách?


Thêm nữa

Giấc mơ nhỏstrategy.entry ((id="Enter Long", long=strategy.long), gọi hàm này đã bị viết sai. Đặt trực tiếp:strategy.entry (("Enter Long", strategy.long, 1) và bạn sẽ nhận được 1 bàn tay, một tờ giấy, một đồng xu.

Giấc mơ nhỏCần thiết lập tùy chọn xếp hạng kim tự tháp: tham số pyramiding của hàm strategy.

Giấc mơ nhỏ666, tiếp nhiên liệu.

CryptoLiuBạn có thể tham khảo cách viết cho một tín hiệu liên tục được kích hoạt theo cùng một hướng, hiện tại chỉ có thể mở một vị trí theo một hướng, nếu enterLong được kích hoạt liên tục, thì kích hoạt sau đó sẽ không thể đặt hàng được. Xin vui lòng viết như thế nào để tôi có thể mở liên tục hơn?

CryptoLiuXin cảm ơn, tôi có thể tiếp tục kêu gọi đóng cửa.

Giấc mơ nhỏ`` // Gửi lệnh if enterLong và strategy.position_size <= 0 "Enter_Long", strategy.long, 1) // strategy.exit (("exit_long", "Enter_Long", when = enterShort) if enterShort and strategy.position_size >= 0 "Enter_Short", strategy.short, 1) // strategy.exit (("exit_short", "Enter_Short", when =enterLong) `` Nếu bạn viết == 0, thì sau khi mở lệnh, lệnh khác sẽ không được kích hoạt, vì giữ lệnh không bằng 0.

CryptoLiu//@version=4 strategy ((title="EMA_crosses", overlay=true) // Inputs priceData = input ((title="Price_data", type=input.source, defval=hl2) Ema1Length = input ((title="EMA_1", type=input.integer, defval=12) Ema2Length = input ((title="EMA_2", type=input.integer, defval=24) Ema3Length = input ((title="EMA_3", type=input.integer, defval=36) // Tính toán giá trị ema1 = ta.ema ((priceData, ema1Length) ema2 = ta.ema ((priceData, ema2Length) ema3 = ta.ema ((priceData, ema3Length) enterLong = ema1 > ema2 and ema2 > ema3 enterShort = ema1 < ema2 and ema2 < ema3 // Giá trị phác thảo plot ((series=ema1, color=color.orange, linewidth=2) plot ((series=ema2, color=color.maroon, linewidth=2) plot ((series=ema3, color=color.blue, linewidth=2) // Gửi lệnh if enterLong và strategy.position_size == 0 "Enter_Long", strategy.long, 1) strategy.exit (("exit_long", "Enter_Long", when = enterShort) if enterShort and strategy.position_size == 0 "Enter_Short", strategy.short, 1) strategy.exit (("exit_short", "Enter_Short", when =enterLong) // Color background - nền màu backgroundColour = (strategy.position_size > 0)? color.green : color.red bgcolor ((color=backgroundColour, transp=85)) Một chút điều chỉnh, nhưng vẫn chỉ kích hoạt một lần khi chính sách bắt đầu, sau đó không kích hoạt. /upload/asset/573cd6ad4478a20fdb02.png