如何定义两个头寸之间的亏损或获胜

时间:2020-05-27 20:00:23

标签: pine-script

在此代码中,如何注册在“ X”处停止并标记为损益的位置Golong? 我需要对此进行定义,以便能够将其用作过滤器,以便在失去前一个位置之后仅显示Golong或Goshort标签。
X是在Golong或Goshort信号之后的特定位置,以停止该位置。 X发生在价格与前一周的高点或低点交叉时(对于Golong信号为低,对于Goshort信号为高)。我的问题是,相对于进行中的Golong或Goshort头寸的位置,如何定义X特定位置的赢利或损失。

win or loss ?

// This source code is subject to the terms of the Mozilla Public License 2.0 at    https://mozilla.org/MPL/2.0/
//@version=4
//By Juros

study(title="Universal weekly breakout + universal filter", shorttitle="weekly breakout+  filter", overlay=true, precision=8)
prevwkH = input(true, title="Show previous week high?")
prevwkL = input(true, title="show previous week low?")

//previous week high and low
prevWeekHigh = security(syminfo.tickerid, 'W', high[1], lookahead=true)
prevWeekLow = security(syminfo.tickerid, 'W', low[1], lookahead=true)

//previous Week high and low Plots
plot(prevwkH and prevWeekHigh ? prevWeekHigh : na, title="Prev Week High", style=plot.style_stepline, linewidth=1, color=color.fuchsia, transp=20)
plot(prevwkL and prevWeekLow ? prevWeekLow : na, title="Prev Week Low", style=plot.style_stepline, linewidth=1, color=color.fuchsia, transp=20)

//------------------------------------------------------------------------------------------

// stop location for short and long position (at crossover of previous week low or high)
Stopshort = crossover (high, prevWeekHigh)
Stoplong = crossunder (low, prevWeekLow)

Longposmemo = false
Longposmemo := Stopshort ? true : Stoplong ? false : Longposmemo[1]

Longcond = Stopshort and not Longposmemo[1]
color_1 = color.new(color.green, 70)


Shortposmemo = false
Shortposmemo := Stoplong ? true : Stopshort ? false : Shortposmemo[1]

Shortcond = Stoplong and not Shortposmemo[1]
color_2 = color.new(color.red, 70)
//bgcolor(Sellnow ? color_2 : na)

//------------------------------------------------------------------------------------------

// Signal for long and short
Golong = false 
Golong := high > prevWeekHigh and Longcond[1]

Goshort = false
Goshort := low < prevWeekLow and Shortcond[1]


//------------------------------------------------------------------------------------------

// plots : X where the position is stopped
plotchar (Longcond, char='X', location=location.abovebar, color=color.yellow)
plotchar (Shortcond, char='X', location=location.belowbar, color=color.yellow)


plotshape (Golong ? high : na, style = shape.labelup, location = location.belowbar,   color=color.lime, size=size.tiny, text = 'GOLONG', textcolor=color.black)
plotshape (Goshort ? low : na, style = shape.labeldown, location = location.abovebar, color=color.fuchsia, size=size.tiny, text ='GOSHORT', textcolor=color.black)

// alerts
alertcondition(Golong, title="Weakly breakout go long", message="WBO go long")
alertcondition(Goshort, title="weakly breakout go short", message="WBO go short")

//------------------------------------------------------------------------------------------

// Filter to show only those signals that follow on the previous position (long or short) that was a loss

0 个答案:

没有答案