pine-script - 脚本编译并满足 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")```
解决方案
得到它的工作!
//@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)))
推荐阅读
- javascript - 使用 d3.js 创建的数组识别空向量
- sql-server - 结合 IN 和 LIKE 功能
- r - 如何在 pivot_longer() 中使用 names_to 参数
- apache-spark - 加入后停止 pyspark 返回两个“on”列
- ios - 在 Swift 中对另一个视图控制器执行 Segue 后关闭游戏视图控制器
- swift - 如何快速获取 NSImage 格式和 alpha?
- javascript - 在 HTML5 画布中快速操作 drawImage() 亮度
- android - 我想从 API 数据 Android Java 中显示头像
- c - 为什么 snprintf 在 %s 之后不读取?
- python - CNN中输入的不平衡纵横比