首页 > 解决方案 > 如何在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_valuestrategy实现这一目标吗?我是 pine 编辑器的新手,任何帮助将不胜感激!

标签: pine-scripttradingback-testing

解决方案


推荐阅读