繁体   English   中英

脚本编译并满足 strategy.entry 条件,但在回测中未启动任何交易

[英]Script compiles and strategy.entry condition is met but no trades are initiated in backtest

不知道为什么 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")```

搞定了!

//@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)))

您正在尝试关闭一个不存在的“止损”订单。 我猜您正试图退出“长”订单。 所以这应该是 Strategy.close() 中的第一个参数。

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("long", comment="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("long", comment = "take profit")```

暂无
暂无

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

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