Pine script 在入口/出口问题上配置获利、止损和三角形 我正在尝试一些最终目标是在每个入口/出口点上设置三角形的方法。我在入口/出口点添加了这些三角形,但它们有点忽略了获利回吐/止损,出现在买入条件中的每个蜡烛上

Pine script 在入口/出口问题上配置获利、止损和三角形 我正在尝试一些最终目标是在每个入口/出口点上设置三角形的方法。我在入口/出口点添加了这些三角形,但它们有点忽略了获利回吐/止损,出现在买入条件中的每个蜡烛上,pine-script,Pine Script,我怎样才能解决这个问题 我也不太确定我的获利/止损公式是否正确 //此源代码受Mozilla公共许可证2.0的条款约束,位于https://mozilla.org/MPL/2.0/ //©团队贸易1 //@版本=4 策略(“趋势检测策略”,overlay=true) //-------输入 // { i_emaPeriod=输入(200,“EMA Period”,最小值=1) // } //-------计算 // { 均线=均线(收盘,i_期) // } //-------执行 // { i

我怎样才能解决这个问题

  • 我也不太确定我的获利/止损公式是否正确
  • //此源代码受Mozilla公共许可证2.0的条款约束,位于https://mozilla.org/MPL/2.0/
    //©团队贸易1
    //@版本=4
    策略(“趋势检测策略”,overlay=true)
    //-------输入
    // {
    i_emaPeriod=输入(200,“EMA Period”,最小值=1)
    // }
    //-------计算
    // {
    均线=均线(收盘,i_期)
    // }
    //-------执行
    // {
    isLong=策略位置大小>0
    isShort=策略位置大小<0
    购买条件=关闭>均线
    sellCondition=关闭<均线和isLong
    //止损设置
    StopLossPercent=输入(5,title=“止损”,minval=0.01,step=0.5)
    StopLoss=(close*(StopLossPercent/100))/syminfo.mintick
    //获取利润设置
    TakeProfitPercent=输入(15,title=“Take Profit”,minval=0.01,step=0.5)
    TakeProfit=(关闭*(TakeProfitPercent/100))/syminfo.mintick
    strategy.entry(“Long”,strategy.Long,when=buyCondition)
    策略.退出(“多头止损或获利回吐”,亏损=止损,利润=获利回吐)
    strategy.entry(“Short”,strategy.Short,when=sellCondition)
    策略.退出(“短期止损或获利回吐”,亏损=止损,利润=获利回吐)
    // }
    //-------情节
    // {
    //----三角形
    plotshape(购买条件?关闭:na,
    style=shape.triangleup,size=size.small,location=location.belowbar,
    color=color.lime,transp=0)
    plotshape(sellCondition?close:na,
    style=shape.triangledown,size=size.small,location=location.overbar,
    颜色=颜色。紫红色,透明度=0)
    //-----条形图颜色
    barcolor(buyCondition?color.lime:sellCondition?color.fuchsia:na)
    //----EMA
    绘图(ema,color=color.blue)
    // }
    
    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © TeamTrading1
    
    //@version=4
    strategy("Trend Detection Strategy", overlay = true)
    
    // —————————— Inputs
    // {
    i_emaPeriod = input(200, "EMA Period", minval = 1)
    // }
    
    // —————————— Calculations
    // {
    ema = ema(close, i_emaPeriod)
    // }
    
    // —————————— Execution
    // {
    isLong = strategy.position_size > 0
    isShort = strategy.position_size < 0
    
    buyCondition =  close > ema
    sellCondition = close < ema and isLong
    
    // Stop Loss settings
    StopLossPercent = input(5, title = "Stop Loss", minval = 0.01, step = 0.5)
    StopLoss = (close * (StopLossPercent / 100)) / syminfo.mintick
    
    // Take Profit settings
    TakeProfitPercent = input(15, title = "Take Profit", minval = 0.01, step = 0.5)
    TakeProfit = (close * (TakeProfitPercent / 100)) / syminfo.mintick
    
    strategy.entry("Long", strategy.long, when = buyCondition)
    strategy.exit("Long Stop Loss or Take Profit", loss = StopLoss, profit = TakeProfit)
    
    strategy.entry("Short", strategy.short, when = sellCondition)
    strategy.exit("Short Stop Loss or Take Profit", loss = StopLoss, profit = TakeProfit)
    
    // }
    
    // —————————— Plots
    // {
    // ————— Triangles
    plotshape(buyCondition ? close : na,
              style = shape.triangleup, size = size.small, location = location.belowbar,
              color = color.lime, transp = 0)
    
    plotshape(sellCondition ? close : na,
              style = shape.triangledown, size = size.small, location = location.abovebar,
              color = color.fuchsia, transp = 0)
    
    // ————— Bar colors
    barcolor(buyCondition ? color.lime : sellCondition ? color.fuchsia : na)
    
    // ————— EMA
    plot(ema, color = color.blue)
    // }