[英]Strategy won't sell despite condition being met
简单的策略应该是在 SMA9 大于 SMA50 时开一个多头 position,然后开这个 position。 但是,尽管满足条件,但它永远不会关闭 position,我不知道为什么。 任何帮助将不胜感激。
//@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 不接受 when 参数https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}close
做
if bearish
strategy.close("Long")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.