SMT-CR Strategy
SMT-CR Strategy
SMT-CR Strategy
//@version=5
strategy("SMT-CR scalp [promuckaj]", "SMT-CR scalp [promuckaj]", overlay=true,
default_qty_type=strategy.cash, default_qty_value=15, initial_capital = 15,
max_labels_count = 500, max_lines_count = 500)
// HeikinAshi candles
ha_open =
request.security(ticker.heikinashi(syminfo.tickerid),timeframe.period,open,lookahea
d = barmerge.lookahead_off, gaps = barmerge.gaps_off)
ha_close =
request.security(ticker.heikinashi(syminfo.tickerid),timeframe.period,close,lookahe
ad = barmerge.lookahead_off, gaps = barmerge.gaps_off)
ha_high =
request.security(ticker.heikinashi(syminfo.tickerid),timeframe.period,high,lookahea
d = barmerge.lookahead_off, gaps = barmerge.gaps_off)
ha_low =
request.security(ticker.heikinashi(syminfo.tickerid),timeframe.period,low,lookahead
= barmerge.lookahead_off, gaps = barmerge.gaps_off)
_open = open
_close = close
_high = high
_low = low
if useHA
_open := ha_open
_close := ha_close
_high := ha_high
_low := ha_low
float ph = 0.
float pl = 0.
// RSI ------------------------------------------------
rsiLengthInput = input.int(11, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(ohlc4, "Source", group="RSI Settings")
// StochRSI -------------------------------------------
useStoch = input(false, "Use Stoch RSI instead of classic RSI", group = "Stoch
RSI")
smoothK = input.int(3, "K", minval=1, group = "Stoch RSI")
smoothD = input.int(3, "D", minval=1, group = "Stoch RSI")
lengthRSI = input.int(14, "RSI Length", minval=1, group = "Stoch RSI")
lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "Stoch RSI")
stochsrc = input(close, title="RSI Source", group = "Stoch RSI")
rsi1 = ta.rsi(stochsrc, lengthRSI)
stochk = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
stochd = ta.sma(stochk, smoothD)
// ----------------------------------------------------
Ldiv = false
Hdiv = false
var smhahaopen = 0.
smhahaclose = (smhao+smhah+smhal+smhac)/4
smhahaopen := na(smhahaopen[1]) ? (smhao + smhac)/2 : (smhahaopen[1] +
smhahaclose[1]) / 2
smhahahigh = math.max (smhah, math.max(smhahaopen,smhahaclose))
smhahalow = math.min (smhal, math.min(smhahaopen,smhahaclose))
smhao2=ta.ema(smhahaopen, smhalen)
smhac2=ta.ema(smhahaclose, smhalen)
smhah2=ta.ema(smhahahigh, smhalen)
smhal2=ta.ema(smhahalow, smhalen)
// SMHA 2
smhao21=ta.ema(_open,smhalen2)
smhac21=ta.ema(_close,smhalen2)
smhah21=ta.ema(_high,smhalen2)
smhal21=ta.ema(_low,smhalen2)
var smhahaopen2 = 0.
smhahaclose2 = (smhao21+smhah21+smhal21+smhac21)/4
smhahaopen2 := na(smhahaopen2[1]) ? (smhao21 + smhac21)/2 : (smhahaopen2[1] +
smhahaclose2[1]) / 2
smhahahigh2 = math.max (smhah21, math.max(smhahaopen2,smhahaclose2))
smhahalow2 = math.min (smhal21, math.min(smhahaopen2,smhahaclose2))
smhao22=ta.ema(smhahaopen2, smhalen2)
smhac22=ta.ema(smhahaclose2, smhalen2)
smhah22=ta.ema(smhahahigh2, smhalen2)
smhal22=ta.ema(smhahalow2, smhalen2)
PVTbull = false
PVTbear = false
// BoS ------------------------------------------
showBOS = input(false, "Show BoS on the chart", group = "BoS (break of structure)")
var LastLowSWPoint = 0.
var LasthighSWPoint = 0.
var LastLowSWPoint1 = 0.
var LasthighSWPoint1 = 0.
var LastLowSWPointBroken = false
var LasthighSWPointBroken = false
var LastHighSWPointBar = 0
var LastLowSWPointBar = 0
BoSbull = false
BoSbear = false
if _high <= _high[2] and _high[1] < _high[2] and _high[3] <= _high[2] and _high[4]
<= _high[2]
LasthighSWPoint1 := LasthighSWPoint
LasthighSWPoint := _high[2]
LastHighSWPointBar := bar_index-2
LasthighSWPointBroken := false
if _low >= _low[2] and _low[1] > _low[2] and _low[3] >= _low[2] and _low[4] >=
_low[2]
LastLowSWPoint1 := LastLowSWPoint
LastLowSWPoint := _low[2]
LastLowSWPointBar := bar_index-2
LastLowSWPointBroken := false
// STRATEGY ====================
L_Final_condt = false
S_Final_condt = false
longCond := L_Final_condt
shortCond := S_Final_condt
if strategy.opentrades == 0
strategy.entry('Long', strategy.long, alert_message =
i_alert_txt_entry_long)
TrailSignal := false
TrailTPstep := 0
PlotTrailPos := false
if strategy.position_size > 0
strategy.exit('TP_L', from_entry = 'Long',alert_message =
i_alert_txt_tp_long, comment_loss = "SL long" , comment_profit = "TP Long", limit =
TrailSLContinue ? na : strategy.position_avg_price * (1 + (TakeProfit/100)), stop =
strategy.position_avg_price * (1 - (sl0 / 100)))
tplLevel := strategy.position_avg_price * (1 + (TakeProfit/100))
if GoToPosL and strategy.position_size > 0
GoToPosL := false
//if GoToPosL and (strategy.opentrades == 0 or strategy.position_size < 0)
// GoToPosL := false
// strategy.entry('Long', strategy.long, alert_message = i_alert_txt_entry_long)
// TrailSignal := false
// TrailTPstep := 0
// PlotTrailPos := false
if strategy.opentrades == 0
strategy.entry('Short', strategy.short, alert_message =
i_alert_txt_entry_short)
TrailSignal := false
TrailTPstep := 0
PlotTrailPos := false
if strategy.position_size < 0
strategy.exit('TP_S', from_entry = 'Short', alert_message =
i_alert_txt_tp_short,comment_loss = "SL Short" , comment_profit = "TP Short", limit
= TrailSLContinue ? na : strategy.position_avg_price * (1 - (TakeProfit/100)), stop
= strategy.position_avg_price * (1 + (sl0 / 100)))
tpsLevel := strategy.position_avg_price * (1 - (TakeProfit/100))
if GoToPosS and strategy.position_size < 0
GoToPosS := false
//if GoToPosS and (strategy.opentrades == 0 or strategy.position_size > 0)
// GoToPosS := false
// strategy.entry('Short', strategy.short, alert_message =
i_alert_txt_entry_short)
// TrailSignal := false
// TrailTPstep := 0
// PlotTrailPos := false
//plot
plotshape(longCond and (strategy.opentrades == 0 or strategy.position_size < 0),
title='Long', style=shape.triangleup, location=location.belowbar,
color=color.new(color.blue, 0), size=size.small, text='',
textcolor=color.new(color.white, 0))
plotshape(shortCond and (strategy.opentrades == 0 or strategy.position_size > 0),
title='Short', style=shape.triangledown, location=location.abovebar,
color=color.new(color.red, 0), size=size.small, text='',
textcolor=color.new(color.white, 0))
//Long
if useTrailSL and strategy.position_size > 0
if TrailSteps == 2
TrailPricePart := (strategy.position_avg_price * (1 +
((TakeProfit/100)/2))) - strategy.position_avg_price
if TrailSignal == false
TrailSLPrice := strategy.position_avg_price * (1 +
((TakeProfit/100)/2))
if PlotTrailPos == false
if showLines
line.new(bar_index,TrailSLPrice,bar_index+ExtendTrailLines,TrailSLPrice,color =
color.green,width = 1)
PlotTrailPos := true
if TrailSteps == 3
TrailPricePart := (strategy.position_avg_price * (1 +
((TakeProfit/100)/3))) - strategy.position_avg_price
if TrailSignal == false
TrailSLPrice := strategy.position_avg_price * (1 +
((TakeProfit/100)/3))
if PlotTrailPos == false
if showLines
line.new(bar_index,TrailSLPrice,bar_index+ExtendTrailLines,TrailSLPrice,color =
color.green,width = 1)
line.new(bar_index,TrailSLPrice+TrailPricePart,bar_index+ExtendTrailLines,TrailSLPr
ice+TrailPricePart,color = color.green,width = 1)
PlotTrailPos := true
if useWicksSL and WickSLcalc and LadderTrail ? high > TrailSLPrice : close >
TrailSLPrice
TrailSignal := true
if useWicksSL and WickSLcalc and LadderTrail ? high > TrailSLPrice : close >
TrailSLPrice
if LadderTrail
if useClosePriceForTrailTP
TrailSLLastPrice := useWicksSL ? high - TrailPricePart : close -
TrailPricePart
else
TrailSLLastPrice := useWicksSL ? high - TrailPricePart :
TrailSLPrice - TrailPricePart
else
TrailSLLastPrice := TrailSLPrice
strategy.cancel_all()
if useTrailTP
if TrailTPstep == 0
strategy.close("Long", comment = "trail TP long", qty_percent = 33,
alert_message = i_alert_txt_trailTP_long)
SecureTrailPrice := TrailSLPrice
TrailTPstep := 1
else
if TrailTPstep == 1 and TrailSteps == 3
strategy.close("Long", comment = "trail TP long", qty_percent =
50, alert_message = i_alert_txt_trailTP2_long)
SecureTrailPrice := TrailSLPrice
TrailTPstep := 2
//Short
if useTrailSL and strategy.position_size < 0
if TrailSteps == 2
TrailPricePart := strategy.position_avg_price -
(strategy.position_avg_price * (1 - ((TakeProfit/100)/2)))
if TrailSignal == false
TrailSLPrice := strategy.position_avg_price * (1 -
((TakeProfit/100)/2))
if PlotTrailPos == false
if showLines
line.new(bar_index,TrailSLPrice,bar_index+ExtendTrailLines,TrailSLPrice,color =
color.red,width = 1)
PlotTrailPos := true
if TrailSteps == 3
TrailPricePart := strategy.position_avg_price -
(strategy.position_avg_price * (1 - ((TakeProfit/100)/3)))
if TrailSignal == false
TrailSLPrice := strategy.position_avg_price * (1 -
((TakeProfit/100)/3))
if PlotTrailPos == false
if showLines
line.new(bar_index,TrailSLPrice,bar_index+ExtendTrailLines,TrailSLPrice,color =
color.red,width = 1)
line.new(bar_index,TrailSLPrice-
TrailPricePart,bar_index+ExtendTrailLines,TrailSLPrice-TrailPricePart,color =
color.red,width = 1)
PlotTrailPos := true
if useWicksSL and WickSLcalc and LadderTrail ? low < TrailSLPrice : close <
TrailSLPrice
TrailSignal := true
if useWicksSL and WickSLcalc and LadderTrail ? low < TrailSLPrice : close <
TrailSLPrice
if LadderTrail
if useClosePriceForTrailTP
TrailSLLastPrice := useWicksSL ? low + TrailPricePart : close +
TrailPricePart
else
TrailSLLastPrice := useWicksSL ? low + TrailPricePart :
TrailSLPrice + TrailPricePart
else
TrailSLLastPrice := TrailSLPrice
strategy.cancel_all()
if useTrailTP
if TrailTPstep == 0
strategy.close("Short", comment = "trail TP short", qty_percent =
33, alert_message = i_alert_txt_trailTP_short)
SecureTrailPrice := TrailSLPrice
TrailTPstep := 1
else
if TrailTPstep == 1 and TrailSteps == 3
strategy.close("Short", comment = "trail TP short", qty_percent
= 50, alert_message = i_alert_txt_trailTP2_short)
SecureTrailPrice := TrailSLPrice
TrailTPstep := 2