You are on page 1of 3

//@version=5

initial_capital=10000

strategy("SSL_strategy", shorttitle='SSL_strategy', overlay=true,


initial_capital=initial_capital)

// contracts
leverage = input.float(1, step=0.1)
balance = strategy.initial_capital + strategy.netprofit
contracts = leverage * balance/close

//如果赚钱的话则用本金投资,不复利
if balance > strategy.initial_capital
contracts = leverage * initial_capital/close

//MA TYPES
mat(source, length, type) =>
type == "SMA" ? ta.sma(source, length) :
type == "EMA" ? ta.ema(source, length) :
type == "RMA" ? ta.rma(source, length) :
type == "WMA" ? ta.wma(source, length) :
type == "VWMA" ? ta.vwma(source, length) :
type == "HMA" ? ta.hma(source, length) :
na

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

// SSL

wicks = input(false, "Take Wicks into Account ?")


highlightState = input(true, "Highlight State ?")

show_ma1 = input(true , "MA High", inline="MA #1", group="Channel №1")


ma1_type = input.string("SMA" , "" , inline="MA #1", options=["SMA", "EMA",
"SMMA (RMA)", "WMA", "VWMA"], group="Channel №1")
ma1_source = input(high , "" , inline="MA #1", group="Channel №1")
ma1_length = input.int(200 , "" , inline="MA #1", minval=1, group="Channel
№1")
ma1_color = input(color.green, "" , inline="MA #1", group="Channel №1")
ma1 = mat(ma1_source, ma1_length, ma1_type)

show_ma2 = input(true , "MA Low", inline="MA #2", group="Channel №1")


ma2_type = input.string("SMA" , "" , inline="MA #2", options=["SMA", "EMA",
"SMMA (RMA)", "WMA", "VWMA"], group="Channel №1")
ma2_source = input(low , "" , inline="MA #2", group="Channel №1")
ma2_length = input.int(200 , "" , inline="MA #2", minval=1, group="Channel
№1")
ma2_color = input(color.red, "" , inline="MA #2", group="Channel №1")
ma2 = mat(ma2_source, ma2_length, ma2_type)
showLabels1 = input(true, "Show Buy/Sell Labels ?", group="Channel №1")
show_ma3 = input(false , "MA High", inline="MA #3", group="Channel №2")
ma3_type = input.string("SMA" , "" , inline="MA #3", options=["SMA", "EMA",
"SMMA (RMA)", "WMA", "VWMA"], group="Channel №2")
ma3_source = input(high , "" , inline="MA #3", group="Channel №2")
ma3_length = input.int(20 , "" , inline="MA #3", minval=1, group="Channel
№2")
ma3_color = input(color.orange, "" , inline="MA #3", group="Channel №2")
ma3 = mat(ma3_source, ma3_length, ma3_type)

show_ma4 = input(false , "MA Low", inline="MA #4", group="Channel №2")


ma4_type = input.string("SMA" , "" , inline="MA #4", options=["SMA", "EMA",
"SMMA (RMA)", "WMA", "VWMA"], group="Channel №2")
ma4_source = input(low , "" , inline="MA #4", group="Channel №2")
ma4_length = input.int(20 , "" , inline="MA #4", minval=1, group="Channel
№2")
ma4_color = input(color.blue, "" , inline="MA #4", group="Channel №2")
ma4 = mat(ma4_source, ma4_length, ma4_type)
showLabels2 = input(true, "Show Buy/Sell Labels ?", group="Channel №2")

Hlv1 = float(na)
Hlv1 := (wicks ? high : close) > ma1 ? 1 : (wicks ? low : close) < ma2 ? -1 :
Hlv1[1]
sslUp1 = Hlv1 < 0 ? ma2 : ma1
sslDown1 = Hlv1 < 0 ? ma1 : ma2

Color1 = Hlv1 == 1 ? ma1_color : ma2_color


fillColor1 = highlightState ? (color.new(Color1, 90)) : na

highLine1 = plot(show_ma1 ? sslUp1 : na, title="UP", linewidth=2, color = Color1)


lowLine1 = plot(show_ma2 ? sslDown1 : na, title="DOWN", linewidth=2, color =
Color1)

plotshape(show_ma1 and showLabels1 and Hlv1 == 1 and Hlv1[1] == -1, title="Buy


Label", text="Buy", location=location.belowbar, style=shape.labelup,
size=size.tiny, color=Color1, textcolor=color.white)
plotshape(show_ma2 and showLabels1 and Hlv1 == -1 and Hlv1[1] == 1, title="Sell
Label", text="Sell", location=location.abovebar, style=shape.labeldown,
size=size.tiny, color=Color1, textcolor=color.white)

fill(highLine1, lowLine1, color = fillColor1)

Hlv2 = float(na)
Hlv2 := (wicks ? high : close) > ma3 ? 1 : (wicks ? low : close) < ma4 ? -1 :
Hlv2[1]
sslUp2 = Hlv2 < 0 ? ma4 : ma3
sslDown2 = Hlv2 < 0 ? ma3 : ma4

Color2 = Hlv2 == 1 ? ma3_color : ma4_color


fillColor2 = highlightState ? (color.new(Color2, 90)) : na

highLine2 = plot(show_ma3 ? sslUp2 : na, title="UP", linewidth=2, color = Color2)


lowLine2 = plot(show_ma4 ? sslDown2 : na, title="DOWN", linewidth=2, color =
Color2)

plotshape(show_ma3 and showLabels2 and Hlv2 == 1 and Hlv2[1] == -1, title="Buy


Label", text="Buy", location=location.belowbar, style=shape.labelup,
size=size.tiny, color=Color2, textcolor=color.white)
plotshape(show_ma4 and showLabels2 and Hlv2 == -1 and Hlv2[1] == 1, title="Sell
Label", text="Sell", location=location.abovebar, style=shape.labeldown,
size=size.tiny, color=Color2, textcolor=color.white)

fill(highLine2, lowLine2, color = fillColor2)

long_cond = close > sslUp2 and Hlv1 == 1 and Hlv1[1] == -1


short_cond = close < sslDown2 and Hlv1 == -1 and Hlv1[1] == 1

if long_cond
strategy.entry("long_entry", strategy.long, qty=contracts)

if short_cond
strategy.entry("short_entry", strategy.short, qty=contracts)
//strategy.close("long_entry")

You might also like