首页 > 解决方案 > 脚本编译并满足 strategy.entry 条件,但回测中未启动交易

问题描述

不知道为什么 Tradingview 没有显示此策略进入任何交易 - 我对一个指标使用相同的进入条件来显示满足条件的点。一直试图调试这个几个小时。将不胜感激这里的任何帮助。谢谢!

strategy("Good news", overlay=true, margin_long=500, margin_short=100, initial_capital=100, calc_on_order_fills=true, calc_on_every_tick=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)

periods = 144
multip = 5
volthreshMA = multip*ta.sma(volume[1], periods)

longCondition = (volume > volthreshMA and close > open)
if (longCondition)
    strategy.entry("long", strategy.long)
    

//2% stop loss
stopCondition = strategy.opentrades.profit(0) < (-0.02*strategy.opentrades.size(0))
if (stopCondition)
    strategy.close("stop loss")

//take profit when profit is 80% of max profit during trade    
takeprofitCondition = ((strategy.opentrades.max_runup(0) - strategy.opentrades.profit (0))/strategy.opentrades.max_runup(0)) > 0.2
if (takeprofitCondition)
    strategy.close("take profit")```

标签: pine-script

解决方案


得到它的工作!

//@version=5
strategy("Good news", overlay=true, margin_long=20, calc_on_order_fills=true, calc_on_every_tick=true, commission_type = strategy.commission.percent, commission_value = 0.07)

//recommended settings
//for 15min: 
//for 5min
//for 3min
//for 1min
periods = input(144,"Number of periods for MA")
multip = input(5, "Volume MA multiplier")


volthreshMA = multip*ta.sma(volume[1], periods)

longCondition = volume > volthreshMA and close > open
orderSize = strategy.equity/close
if (longCondition)
    strategy.entry("long", strategy.long, qty=orderSize)

//2% stop loss    
strategy.exit("stop loss", "long", loss = 200)

//take profit when price crosses under moving average
strategy.close("long", when = ta.crossunder(close,ta.sma(close,6)))

推荐阅读