【问题标题】:How to Keep two long and short opposed positions open in tradingview pinescript?如何在tradingview pinescript中保持两个多头和空头对立头寸?
【发布时间】:2020-10-18 00:30:23
【问题描述】:

这是一个简单的代码来向您展示我的意思,多头和空头头寸都有止损,但问题是我希望能够在不关闭已经开立的多头头寸的情况下开设空头头寸。正如您可能已经猜到的那样,我想在市场紧张并且您可以从中获利时测试此策略,无论哪种方式,它只需要两个帐户。

strategy("bothways", overlay=true)

leverage=input(5,"leverage",step=.25)
partoftrade=input(1,"partoftrade",step=.01)
StoplosssS=input(0.025,"StopLOSS SHORT",step=0.001)
StoplosssL=input(0.025,"StopLOSS LONG",step=0.001)
pertpS = input(0.02,"TP Short",step=0.01)
pertpL = input(0.02,"TP Long",step=0.01)
narrow=bbw(open,20,2)<0.005
red=open>close
green=open<close
longCondition = narrow and green
if (longCondition and strategy.opentrades<2)
    strategy.entry("L", strategy.long,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name="ocg",oca_type=strategy.oca.cancel)
strategy.exit("LE",from_entry="L",profit=close*pertpL/syminfo.mintick,loss=open*StoplosssL/syminfo.mintick,oca_name="ocg")

shortCondition = narrow and red
if (shortCondition and strategy.opentrades<2)
    strategy.entry("S", strategy.short,qty=(strategy.equity/1)*partoftrade*leverage/open,oca_name="ocg",oca_type=strategy.oca.reduce)
strategy.exit("SE",from_entry="S",profit=close*pertpS/syminfo.mintick,loss=open*StoplosssS/syminfo.mintick,oca_name="ocg")    

感谢帮助

【问题讨论】:

  • 不幸的是,我相信这是不可能的
  • 我不太确定,但我认为这就是您使用 oca_name 的地方,并且必须使用不同的组。

标签: pine-script


【解决方案1】:

当然,您可以将它们分成两个不同的命令文件。我知道这个答案不会让你满意,我尽我最大的努力打败它。但只要想想一件事......盈利能力。

[ 虽然,恕我... 我建议查看每个职位的策略摘要中的“持有的合约”行,然后选择最有利可图的一个。 想象一下,您将这些订单输入到您的交易所。您的 2 多头将买入该合约。当你想卖空它时,它会先买你口袋里的东西,并让你选择借入该合约或仅当你的投资组合中没有它时才进行保证金出售。因此,如果它们不是相应的而是交织在一起的,它们就会相互抵消(当你在每一个收盘之前在同一个地方有蓝色多头和红色短裤时) ]

【讨论】:

    【解决方案2】:

    你试过 strategy.order 命令吗?并且您可以为 strategy.order 命令提供一个运行条件,直到多头达到特定的头寸规模。

    if BuyCallSignal and strategy.position_size == 1
        strategy.order("ABCall",  strategy.long ,  when = long, qty = 1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      • 2021-12-15
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多