首页 > 解决方案 > 仅当 Strategy.Openprofit > 0 时 Strategy.Exit

问题描述

您好,松树编码专家,

只有当 Open PL 大于 0 时,我才尝试退出订单。

如果有人可以帮助我编辑下面的示例代码,我将不胜感激。

//@version=4
strategy("Strategy", overlay=true, max_lines_count=500, max_bars_back=5000, pyramiding=100)

bars_back = input(defval=50, title="Custom Bars back")

f_resInMiliseconds() => 
    _resInMiliseconds = 60000 * timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
      
bar_diff = int((timenow-time) / f_resInMiliseconds())
bar_in_window = bar_diff < bars_back

if bar_in_window
    strategy.entry("long", true, 1, when = close<open, alert_message='Long')
    strategy.entry("short", false, 1, when = close>open, alert_message='Short')

谢谢你,贾克斯。

标签: pine-script

解决方案


推荐阅读