尽管满足条件,但策略条目未执行

时间:2021-01-05 05:01:28

标签: pine-script algorithmic-trading

strategy("Custom_ema_strategy", overlay=true , shorttitle="Custom EMA Strategy" ,initial_capital=10000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100.00, commission_type="percent", commission_value=0.00)

//Inputs
fastMALength = input(title = "Fast MA Length" , type = input.integer , defval = 10)
slowMALength = input(title = "Slow MA Length" , type = input.integer , defval = 20)
selectSource = input(title = "Source" , type = input.source , defval = close)
fastMA = ema(selectSource , fastMALength)
slowMA = ema(selectSource , slowMALength)
filter = input(title = 'Filter' , type = input.integer , defval = 50)

plot(fastMA , color = color.yellow , linewidth = 2 , title = 'FAST MA')
plot(slowMA , color = color.blue , linewidth = 2 , title = 'SLOW MA')
plot(low , title='Title', color=#00ffaa, linewidth=2, style=plot.style_circles)

longCondition = low > fastMA and low > slowMA
shortCondition = crossunder(fastMA , slowMA)

plotchar(longCondition , 'longCondition' , '')
plotchar(low , 'low' , '')
plotchar(fastMA , 'fastMA' , '')


if longCondition
    strategy.entry("Long Entry", long = strategy.long)

一个。上面的策略没有执行,因为我的 longCondition 是直截了当的,我只需要低点高于 fastMA 和 slowMA。如您所见,突出显示的蜡烛满足条件但不执行。不太确定为什么它不执行。

Enter Strategy

B.这个蓝色突出显示的蜡烛应该失败,因为低点是 6551.00,而 slowMA 是 6551.49,这应该是假的,因为条件是低的 >slowMA 但 longCondition 是 1.00,它返回真。

Enter Strategy

c.突出显示的部分显示条件满足时,如何在条件满足后的下一根蜡烛(箭头指示)处进入策略。

Enter Strategy

1 个答案:

答案 0 :(得分:1)

您在数据集中的早期获得了一个条目,但由于您没有退出交易,您获得的条目数量将对应于您允许的金字塔条目数量:

enter image description here