仅当PnL为正时金字塔形

问题描述 投票:0回答:1

快速问题。关于松策略中的金字塔式订单,我希望仅当当前PnL为正时才执行第二个及后续订单。松树中是否有解决方法?我无法提出任何想法。我不需要确切的代码,只需将我指向正确的方向即可。

pine-script
1个回答
0
投票
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov

//@version=4
strategy("My Strategy", overlay=true, pyramiding = 10)

longCondition = crossover(sma(close, 14), sma(close, 28))
if strategy.position_size > 0 and  strategy.openprofit < 0 and longCondition
    longCondition := false
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(sma(close, 14), sma(close, 28))
if strategy.position_size > 0 and  strategy.openprofit < 0 and shortCondition
    shortCondition := false
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
© www.soinside.com 2019 - 2024. All rights reserved.