【问题标题】:How can I calculate or memorize the profit and loss status of the last transaction in Pine Script?如何在 Pine Script 中计算或记忆最后一笔交易的盈亏状态?
【发布时间】:2021-11-14 11:59:26
【问题描述】:

如何计算或记忆Pine Script中最后一笔交易的盈亏状态? 例如, 如果我上一笔交易亏损 10%,我想在下一笔交易中使用不同的条件。所以我需要能够计算或记住最后一笔交易。 感谢您的帮助。

【问题讨论】:

    标签: pine-script algorithmic-trading


    【解决方案1】:

    为此,您需要一个内置函数和一个内置变量。

    strategy.closedtrades.profit():返回平仓的盈亏 贸易。损失表示为负值。

    strategy.closedtrades:在 整个交易区间。

    所以,您要做的是将交易数量输入strategy.closedtrades.profit() 函数。

    这是一个例子:

    //@version=5
    strategy("My Strategy", overlay=true, pyramiding=1)
    
    pl = strategy.closedtrades.profit(strategy.closedtrades - 1) + strategy.closedtrades.commission(strategy.closedtrades - 1)
    strategy.entry("buy", strategy.long, when = open[1] > close[1])
    strategy.entry("sell", strategy.short, when = open[1] < close[1])
    
    plot(pl, color=color.orange)
    plot(strategy.closedtrades, color=color.red)
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2015-07-14
      • 2011-03-07
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 2023-02-13
      • 2020-07-26
      相关资源
      最近更新 更多