Type/to search
0
Follow
0
Followers
Xin hãy giúp tôi, làm thế nào tôi có thể triển khai chu kỳ đặt hàng trong chiến lược ngôn ngữ thông? Bây giờ tôi chỉ có thể đặt một đơn hàng nhưng không theo dõi
Help
Created 2022-11-14 10:11:47  
 7
 1371

//@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)

// Compute values
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

// Plot values
plot(series=ema1, color=color.orange, linewidth=2)
plot(series=ema2, color=color.maroon, linewidth=2)
plot(series=ema3, color=color.blue, linewidth=2)

// Submit orders
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 thử nghiệm, một lệnh sẽ được đặt ở đầu tiên, và các lệnh khác dường như không được kích hoạt, có một ông chủ nào có thể hướng dẫn cách thực hiện vòng quay chiến lược không, cảm ơn.

Related Recommendations
Comment
All comments (7)

    strategy.entry(id="Enter Long", long=strategy.long),这个函数调用写错了吧。
    直接写:strategy.entry("Enter Long", strategy.long, 1) 这样就下单1手,张,一个币。

    4 years ago

    //@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)

    // Compute values
    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

    // Plot values
    plot(series=ema1, color=color.orange, linewidth=2)
    plot(series=ema2, color=color.maroon, linewidth=2)
    plot(series=ema3, color=color.blue, linewidth=2)

    // Submit orders
    if enterLong and strategy.position_size == 0
    strategy.entry("Enter_Long", strategy.long, 1)
    strategy.exit("exit_long", "Enter_Long", when = enterShort)

    if enterShort and strategy.position_size == 0
    strategy.entry("Enter_Short", strategy.short, 1)
    strategy.exit("exit_short", "Enter_Short", when =enterLong)

    // Colour background
    backgroundColour = (strategy.position_size > 0) ? color.green : color.red

    bgcolor(color=backgroundColour, transp=85)

    调整了一下,但是还是只有策略开始的时候触发了一次,后面就没有触发了。辛苦小小梦再帮忙看看是哪里出错了。 img

    4 years ago
    // Submit orders if enterLong and strategy.position_size <= 0 strategy.entry("Enter_Long", strategy.long, 1) // strategy.exit("exit_long", "Enter_Long", when = enterShort) if enterShort and strategy.position_size >= 0 strategy.entry("Enter_Short", strategy.short, 1) // strategy.exit("exit_short", "Enter_Short", when =enterLong)

    这里判断设置不合适,我修改了下正常了。如果你写成==0,那么开仓以后另一个就不会触发了,因为有持仓了就不等于0了。

    4 years ago

    还想咨询一下同方向持续触发信号的写法,目前的写法只能是一个方向开一次仓位,如果enterLong持续被触发,那么后面的触发没法下单。请教一下应该怎么写,能让我连续开多呢?

    4 years ago

    需要设置金字塔加仓选项:strategy函数的pyramiding参数。

    4 years ago

    谢谢,可以了,又可以继续打怪通关了~

    4 years ago

    666,加油~

    4 years ago
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)