简体   繁体   English

尽管条件得到满足,但策略不会出售

[英]Strategy won't sell despite condition being met

The simple strategy should open a long position when SMA9 is greater than SMA50, and it opens this position.简单的策略应该是在 SMA9 大于 SMA50 时开一个多头 position,然后开这个 position。 However, it never closes the position despite the conditions being met and I don't know why.但是,尽管满足条件,但它永远不会关闭 position,我不知道为什么。 Any help would be greatly appreciated.任何帮助将不胜感激。

//@version=5
strategy('Coinrule template - RSI and SMA',
         overlay=true,
         initial_capital=1000,
         process_orders_on_close=true,
         default_qty_type=strategy.percent_of_equity,
         default_qty_value=30,
         commission_type=strategy.commission.percent,
         commission_value=0.1)

showDate = input(defval=true, title='Show Date Range')
timePeriod = time >= timestamp(syminfo.timezone, 2022, 5, 1, 0, 0)
notInTrade = strategy.position_size <= 0

//==================================Buy Conditions============================================

//RSI
length = input(14)
rsi = ta.rsi(close, length)

//SMA
fastSMA = ta.sma(close, 9)
slowSMA = ta.sma(close, 50)
plot(fastSMA, color = color.green)
plot(slowSMA, color = color.blue)


bullish = ta.crossover(fastSMA, slowSMA) and rsi > 50
bearish = ta.crossover(slowSMA, fastSMA) and rsi < 50

//if(bullish and timePeriod)
//    strategy.entry(id="Long", direction = strategy.long)//, when=bullish and timePeriod)

//strategy.close(id="Exit", when = bearish)

strategy.entry(id='Long', direction = strategy.long, when = bullish and timePeriod)
strategy.close(id='Exit', when=bearish)

strategy.close doesn't accept a when parameter https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close strategy.close 不接受 when 参数https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close

Do

if bearish
    strategy.close("Long")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM