pine-script - 如何在pine editor tradingview中设置基于当前资金的1%购买的单位数量?
问题描述
我正在 Tradingview 中创建一个策略,当 EMA 25 与 EMA50 交叉时,它将进入多头头寸。这是我的脚本:
strategy("MyStrategy", overlay=true, initial_capital = 10000, default_qty_value = 100, default_qty_type = strategy.percent_of_equity )
EMA25 = ema(close,25)
EMA50 = ema(close,50)
goLongCondition1 = crossover(EMA20,EMA50)
timePeriod = time >= timestamp(syminfo.timezone, 2019,6,1,0,0)
notInTrade = strategy.position_size <= 0
stoploss = close*0.95
takeprofit = close*1.1
if(goLongCondition1 and timePeriod and notInTrade)
strategy.entry("long",strategy.long)
strategy.exit("exit", "long", stop = stoploss, limit = takeprofit)
根据当前脚本,要购买的单位数量是根据我目前拥有的总资本计算的。但是,我想输入的实际单位数量是使用我当时资本除以 ATR(14) 的 1%。
例如,如果我现在有 9500 美元,则 9500 美元的 1% = 95 美元。假设我想购买股票那天的 ATR(14) 是 6.61,那么the number of unit that I should buy = Rounddown(95/6.61) = 14 units
.
我可以知道我应该如何修改default_qty_value
以strategy
实现这一目标吗?我是 pine 编辑器的新手,任何帮助将不胜感激!
解决方案
推荐阅读
- javascript - 航班号和日期的正则表达式
- javascript - 在 Jquery 监听器中访问 THIS
- wordpress - wordpress 评论中的大文件大小图像上传问题
- r - 按组查找多个变量的最小值
- linux - pgagent 的 systemd 单元
- python - django-pyodbc-azure 2.1.0.0 不支持 Django 2.1.0
- javascript - AngularJs:ng-model 没有绑定到 ng-checked for input type="radio",与 ng-repeat 一起使用
- c++ - count_if implementation - C++
- artifactory - jfrog artifactory 为泛型类型设置智能远程存储库
- c++ - CMake 与 Visual Studio 2017 C++ 核心指南检查器 (CppCoreCheck) 的集成