Что делать, чтобы запустить мой торговый алгоритм, запускаемый после каждого закрытия свечи, появляется для моей стратегии в скрипте Pine

#algorithmic-trading #tradingview-api #pine-script-v4

Вопрос:

 strategy.exit("Exit Long Position",id = "long", stop = up, comment = "long exit")  

Выше приведен мой код для выхода из стратегии.длинная позиция. выше указана цена выхода из стратегии.

Но я сомневаюсь, что когда когда-либо свечи вика касаются цены вверх, длинная позиция закрывается. Я хочу, чтобы алгоритм подождал, пока свеча полностью не появится, затем он должен решить, выходить или нет со значением закрытия свечи.

Как это сделать…

Эта фотография может более точно указать на то, в чем я сомневаюсь

Ниже приведен мой полный код:

 //@version=4 // study("Supertrend - Buy or Sell Signal", overlay = true)  strategy(title = "Supertrend", shorttitle = "ST", overlay = true, precision = 2)  //Time range for testing   fromDay = input(defval = 1, title = "From Date", type = input.integer, minval = 1, maxval = 31) fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12) fromYear = input(defval = 2005, title = "From Year", type = input.integer, minval = 1992, maxval = 2021) toDay = input(defval = 1, title = "To Date", type = input.integer, minval = 1, maxval = 31) toMonth = input(defval = 12, title = "To Month", type = input.integer, minval = 1, maxval = 12) toYear = input(defval = 2021, title = "To Year", type = input.integer, minval = 1992, maxval = 2023)  from = timestamp(fromYear, fromMonth, fromDay, 00, 00) finish = timestamp(toYear, toMonth, toDay, 23, 59)  window() =gt; time gt;= from and time lt;= finish ? true : false  //inputs emaPeriods = input(title = "emaPeriod", type = input.integer, defval = 50, step = 25) Periods = input(title="ATR Period", type=input.integer, defval=10) Source = input(close, title="Source") Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)  //Compute ATR Levels atr= atr(Periods)  ema50 = ema(close, emaPeriods)  //Creating Upper Channel  up=Source-(Multiplier*atr) up1 = nz(up[1],up) // up1 = up[1] up := close[1] gt; up1 ? max(up,up1) : up  //Creating Down Channel dn=Source (Multiplier*atr) dn1 = nz(dn[1], dn) // dn1 = dn[1] dn := close[1] lt; dn1 ? min(dn, dn1) : dn   //Compute the Trend Stream  1/-1 trend = 1 trend := nz(trend[1], trend) trend := trend == -1 and close gt; dn1 ? 1 : trend == 1 and close lt; up1 ? -1 : trend  //Create Stoploss for Longs upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)  //Buy Signal Buy = trend == 1 and close gt; ema50   // plotshape(Buy ? up : na, title="Go Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0) // plotshape(Buy ? up : na, title="Buy", text="Buy Mode", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)  dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)  //Sell Signal Sell = trend == -1 and close lt; ema50   style=shape.circle, size=size.tiny, color=color.red, transp=0) style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)  iPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)  longFillColor = trend == 1 ? color.green : color.white shortFillColor = trend == -1 ? color.red : color.white  fill(iPlot, upPlot, title="UpTrend Highligter", color=longFillColor) fill(iPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)   if Buy  stopCond = close lt; up  strategy.entry("Long", strategy.long, qty = 1000, id = "long", when = window())  strategy.exit("Exit Long Position",id = "long", stop = up, comment = "long exit")  if Sell  strategy.entry("Short", strategy.short, qty = 1000, id = "short", when = window())  strategy.exit("Exit Short Position",id = "short", stop = dn, comment = "short exit")  plot(up, title = "UP", color = color.white, linewidth = 1, transp = 0) // plot(dn, title = "DN", color = color.white, linewidth = 1, transp = 0)  plot(ema50, color = color.blue, transp =0)