//@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)
इस समय, यह कोड हमेशा एक आदेश देता है जब यह वापस आ जाता है, और फिर अन्य को ट्रिगर नहीं किया जाता है, क्या कोई मुझे बता सकता है कि रणनीति चक्र को कैसे निष्पादित किया जाए, धन्यवाद।
strategy.entry(id="Enter Long", long=strategy.long),这个函数调用写错了吧。
直接写:strategy.entry("Enter Long", strategy.long, 1) 这样就下单1手,张,一个币。
//@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)
// 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了。
- 1

