pine-script - 将策略转换为研究,停止金字塔式增长
问题描述
我是 Pine 的新手,我正在尝试将以下策略转换为研究:
//@version=4
strategy(title="test", default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=.0020, pyramiding=0, slippage=3, overlay=true)
ema8 = ema(close, 8)
ema13 = ema(close, 13)
ema55 = ema(close, 55)
longEmaCondition = ema8 > ema13
exitLongEmaCondition = ema13 < ema55
// STRATEGY //
longCondition = longEmaCondition and strategy.position_size == 0
exitLongCondition = exitLongEmaCondition and strategy.position_size > 0
if longCondition
strategy.entry("LONG", strategy.long)
if exitLongCondition
strategy.close("LONG")
这是我目前的尝试:
//@version=4
study("My Script",overlay = true)
ema8 = ema(close, 8)
ema13 = ema(close, 13)
ema55 = ema(close, 55)
longEmaCondition = ema8 > ema13
exitLongEmaCondition = ema13 < ema55
// STRATEGY //
longCondition = longEmaCondition
exitLongCondition = exitLongEmaCondition
alertcondition(longCondition, title = "Entry Long")
alertcondition(exitLongCondition, title = "Exit Long")
plotshape(longCondition,text='LONG' ,color=color.green, location=location.abovebar,style=shape.arrowup)
plotshape(exitLongCondition, color=color.green,text='Close \n LONG', location=location.belowbar)
然而,当绘制上面的图时,有很多金字塔交易(见下面的图片链接)。我该如何阻止这个?我删除了strategy.position_size
变量,因为我在研究脚本中找不到等效函数。这是导致金字塔的原因吗?
任何帮助将不胜感激。
解决方案
推荐阅读
- java - 使用 Gradle 将单片 Spring Boot 应用程序转换为多模块失败
- c# - C# 8 可空引用类型 - [NotNullWhen(bool)] 与异步任务
- .net - Dbcontext 属性中的动态类型
- java - 如何确保在 JSOUP FormElement 上调用提交,如果表单有 2 个“提交”类型的按钮,则触发第一个按钮
- redux - 在 Redux/React Js 的 Reducer 中收到 NaN
- python - 如何估计 a+xb=c 的系数?
- javascript - 执行 put 请求时,Req.body 为空对象
- react-native - 我如何获得这个 ES6 Class 的道具?
- html - 更改 src 属性时防止 iframe 重新加载?
- python - 在 Python 的数据框中将日期列转换为 MM/DD/YYYY 格式