Reversal Signals Pinescript Code
Reversal Signals Pinescript Code
0)
https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
//------------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------{
bSh = input.string('Completed', 'Display Phases', options = ['Completed', 'Detailed', 'None'], group = bGR,
tooltip = bTP)
srL = input.bool(true , 'Support & Resistance Levels', inline = 'bSh', group = bGR)
ptLT = input.string('Step Line w/ Diamonds', '', options = ['Circles', 'Step Line', 'Step Line w/ Diamonds'], inline
= 'bSh', group = bGR)
rsB = input.bool(false, 'Momentum Phase Risk Levels', inline = 'bSh2', group = bGR)
ptSR = input.string('Circles', '', options = ['Circles', 'Step Line'], inline = 'bSh2', group = bGR)
tTP = 'All phase specific trade setups, presented as options, are triggered once the selected phase is completed
and folowed by a price flip in the direction of the trade setup. Please pay attention to the phase specific risk
levels as well as the overall trend direction\n' +
tso = input.string('None', 'Phase Specific Trade Setup Options', options = ['Momentum', 'Exhaustion', 'Qualified',
'None'], group = tGR, tooltip = tTP)
war = input.bool(false , 'Price Flips against the Phase Specific Trade Setups', group = tGR)
//-----------------------------------------------------------------------------}
// General Calculations
//-----------------------------------------------------------------------------{
//-----------------------------------------------------------------------------}
// User Defined Types
//-----------------------------------------------------------------------------{
type bar
float o = open
float h = high
float l = low
float c = close
int i = bar_index
type trb
int bSC
float bSH
float bSL
int sSC
float sSH
float sSL
type tre
int bCC
float bC8
float bCHt
float bCH
float bCL
float bCLt
float bCD
int sCC
float sC8
float sCHt
float sCH
float sCL
float sCLt
float sCT
//-----------------------------------------------------------------------------}
// Variables
//-----------------------------------------------------------------------------{
bar b = bar.new()
var trb S = trb.new()
var tre C = tre.new()
noC = #00000000
rdC = #f23645
gnC = #089981
whC = #ffffff
blC = #2962ff
grC = #787b86
bgC = #00bcd4
shpD = shape.labeldown
shpU = shape.labelup
locA = location.abovebar
locB = location.belowbar
dspN = false
pltL = plot.style_circles
pltS = size.tiny
//-----------------------------------------------------------------------------}
// Functions / Methods
//-----------------------------------------------------------------------------{
f_lnS(_s) =>
s = switch _s
'Circles' => plot.style_circles
'Step Line' => plot.style_steplinebr
'Step Line w/ Diamonds' => plot.style_steplinebr
//-----------------------------------------------------------------------------}
// Calculations
//-----------------------------------------------------------------------------{
ptLB = f_lnS(ptLT)
ptRS = f_lnS(ptSR)
//-----------------------------------------------------------------------------}
// Momentum Phase
//-----------------------------------------------------------------------------{
if con
S.bSC := S.bSC == 9 ? 1 : S.bSC + 1
S.sSC := 0
else
S.sSC := S.sSC == 9 ? 1 : S.sSC + 1
S.bSC := 0
pbS = (b.l <= b.l[3] and b.l <= b.l[2]) or (b.l[1] <= b.l[3] and b.l[1] <= b.l[2])
plotshape(BnoShw and not Bcmpltd and S.bSC == 1, '', shpD, locA, noC, 0, '₁', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 2, '', shpD, locA, noC, 0, '₂', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 3, '', shpD, locA, noC, 0, '₃', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 4, '', shpD, locA, noC, 0, '₄', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 5, '', shpD, locA, noC, 0, '₅', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 6, '', shpD, locA, noC, 0, '₆', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 7, '', shpD, locA, noC, 0, '₇', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 8 and not pbS, '', shpD, locA, noC, 0, '₈', gnC, dspN)
plotshape(BnoShw and not Bcmpltd and S.bSC == 8 and pbS, '', shpD, locA, color.new(gnC, 75), 0, 'ᵖ\n₈',
whC, dspN)
//plotshape(BnoShw and not Bcmpltd and S.bSC == 9, '', shpD, locA, noC, 0, '₉', gnC, dspN)
plotshape(BnoShw and S.bSC == 9 and not pbS, 'Bullish Momentum Phases', shpU, locB, color.new(gnC, 25),
0, '', whC, not dspN, pltS)
plotshape(BnoShw and S.bSC == 9 and pbS, 'Perfect Bullish Momentum Phases', shpU, locB,
color.new(gnC, 25), 0, 'ᵖ', whC, not dspN, pltS)
plotshape(BnoShw and S.bSC[1] == 8 and S.sSC == 1, 'Early Bullish Momentum Phases', shpU, locB,
color.new(gnC, 25), 0, '', whC, not dspN, pltS)
sR = ta.highest(9)
bSR = 0.0
bSR := S.bSC == 9 or bC8 ? sR : b.c > bSR[1] ? 0 : bSR[1]
plot(srL and bSR > 0 ? bSR : na, "Resistance Levels", color.new(rdC, 50), 2, ptLB)
plotshape(srL and bSR > 0 and bSR != bSR[1] and str.contains(ptLT, 'Diamonds') ? bSR : na, '', shape.diamond,
location.absolute, rdC, editable = dspN, size = size.tiny)
if S.bSC == 1
S.bSL := b.l
if S.bSC > 0
S.bSL := math.min(b.l, S.bSL)
if b.l == S.bSL
S.bSH := b.h
bSD = 0.0
bSD := S.bSC == 9 ? 2 * S.bSL - S.bSH : b.c < bSD[1] or S.sSC == 9 ? 0 : bSD[1]
plot(rsB and bSD > 0 ? bSD : na, "Bullish Momentum Risk Levels", blC, 1, ptRS)
psS = (b.h >= b.h[3] and b.h >= b.h[2]) or (b.h[1] >= b.h[3] and b.h[1] >= b.h[2])
plotshape(BnoShw and not Bcmpltd and S.sSC == 1, '', shpD, locA, noC, 0, '₁', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 2, '', shpD, locA, noC, 0, '₂', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 3, '', shpD, locA, noC, 0, '₃', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 4, '', shpD, locA, noC, 0, '₄', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 5, '', shpD, locA, noC, 0, '₅', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 6, '', shpD, locA, noC, 0, '₆', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 7, '', shpD, locA, noC, 0, '₇', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 8 and not psS, '', shpD, locA, noC, 0, '₈', rdC, dspN)
plotshape(BnoShw and not Bcmpltd and S.sSC == 8 and psS, '', shpD, locA, color.new(rdC, 75), 0, 'ᵖ\n₈',
whC, dspN)
//plotshape(BnoShw and not Bcmpltd and S.sSC == 9, '', shpD, locA, noC, 0, '₉', gnC, dspN)
plotshape(BnoShw and S.sSC == 9 and not psS, 'Completed Bearish Momentum Phases' , shpD, locA,
color.new(rdC, 25), 0, '' , whC, not dspN, pltS)
plotshape(BnoShw and S.sSC == 9 and psS, 'Perfect Bearish Momentum Phases' , shpD, locA,
color.new(rdC, 25), 0, 'ᵖ', whC, not dspN, pltS)
plotshape(BnoShw and S.sSC[1] == 8 and S.bSC == 1, 'Early Bearish Momentum Phases', shpD, locA,
color.new(rdC, 25), 0, '' , whC, not dspN, pltS)
sS = ta.lowest(9)
sSS = 0.0
sSS := S.sSC == 9 or sC8 ? sS : b.c < sSS[1] ? 0 : sSS[1]
plot(srL and sSS > 0 ? sSS : na, "Support Levels", color.new(gnC, 50), 2, ptLB)
plotshape(srL and sSS > 0 and sSS != sSS[1] and str.contains(ptLT, 'Diamonds') ? sSS : na, '', shape.diamond,
location.absolute, gnC, editable = dspN, size = size.tiny)
if S.sSC == 1
S.sSH := b.h
if S.sSC > 0
S.sSH := math.max(b.h, S.sSH)
if b.h == S.sSH
S.sSL := b.l
sSD = 0.0
sSD := S.sSC == 9 ? 2 * S.sSH - S.sSL : b.c > sSD[1] or S.bSC == 9 ? 0 : sSD[1]
plot(rsB and sSD > 0 ? sSD : na, "Bearish Momentum Risk Levels", blC, 1, ptRS)
//-----------------------------------------------------------------------------}
// Trend Exhaustion Phase
//-----------------------------------------------------------------------------{
shwBC = noShw and not cmpltd and sbC and C.bCC != C.bCC[1]
plotshape(shwBC and C.bCC == 1 , '', shpD, locB, noC, 0, '₁' , gnC, dspN)
plotshape(shwBC and C.bCC == 2 , '', shpD, locB, noC, 0, '₂' , gnC, dspN)
plotshape(shwBC and C.bCC == 3 , '', shpD, locB, noC, 0, '₃' , gnC, dspN)
plotshape(shwBC and C.bCC == 4 , '', shpD, locB, noC, 0, '₄' , gnC, dspN)
plotshape(shwBC and C.bCC == 5 , '', shpD, locB, noC, 0, '₅' , gnC, dspN)
plotshape(shwBC and C.bCC == 6 , '', shpD, locB, noC, 0, '₆' , gnC, dspN)
plotshape(shwBC and C.bCC == 7 , '', shpD, locB, noC, 0, '₇' , gnC, dspN)
plotshape(shwBC and C.bCC == 8 , '', shpD, locB, noC, 0, '₈' , gnC, dspN)
plotshape(shwBC and C.bCC == 9 , '', shpD, locB, noC, 0, '₉' , gnC, dspN)
plotshape(shwBC and C.bCC == 10, '', shpD, locB, noC, 0, '₁₀', gnC, dspN)
plotshape(shwBC and C.bCC == 11, '', shpD, locB, noC, 0, '₁₁', gnC, dspN)
plotshape(shwBC and C.bCC == 12, '', shpD, locB, noC, 0, '₁₂', gnC, dspN)
plotshape(noShw and not cmpltd and sbC and C.bCC == C.bCC[1] and C.bCC == 12 and b13, '', shpD, locB,
noC, 0, '₊', gnC, dspN)
//plotshape(shwBC and C.bCC == 13, '', shpD, locB, noC, 0, '₁₃', gnC, dspN)
plotshape(noShw and sbC and C.bCC != C.bCC[1] and C.bCC == 13, 'Completed Bullish Exhaustions', shpU,
locB, color.new(#006400, 25), 0, 'E', whC, not dspN, pltS)
if C.bCC == 1
C.bCLt := b.l
C.bCHt := b.h
if sbC
C.bCHt := math.max(b.h, C.bCHt)
C.bCLt := math.min(b.l, C.bCLt)
if b.h == C.bCHt
C.bCL := b.l
if b.l == C.bCLt
C.bCH := b.h
shwSC = noShw and not cmpltd and ssC and C.sCC != C.sCC[1]
plotshape(shwSC and C.sCC == 1 , '', shpD, locB, noC, 0, '₁' , rdC, dspN)
plotshape(shwSC and C.sCC == 2 , '', shpD, locB, noC, 0, '₂' , rdC, dspN)
plotshape(shwSC and C.sCC == 3 , '', shpD, locB, noC, 0, '₃' , rdC, dspN)
plotshape(shwSC and C.sCC == 4 , '', shpD, locB, noC, 0, '₄' , rdC, dspN)
plotshape(shwSC and C.sCC == 5 , '', shpD, locB, noC, 0, '₅' , rdC, dspN)
plotshape(shwSC and C.sCC == 6 , '', shpD, locB, noC, 0, '₆' , rdC, dspN)
plotshape(shwSC and C.sCC == 7 , '', shpD, locB, noC, 0, '₇' , rdC, dspN)
plotshape(shwSC and C.sCC == 8 , '', shpD, locB, noC, 0, '₈' , rdC, dspN)
plotshape(shwSC and C.sCC == 9 , '', shpD, locB, noC, 0, '₉' , rdC, dspN)
plotshape(shwSC and C.sCC == 10, '', shpD, locB, noC, 0, '₁₀', rdC, dspN)
plotshape(shwSC and C.sCC == 11, '', shpD, locB, noC, 0, '₁₁', rdC, dspN)
plotshape(shwSC and C.sCC == 12, '', shpD, locB, noC, 0, '₁₂', rdC, dspN)
plotshape(noShw and not cmpltd and ssC and C.sCC == C.sCC[1] and C.sCC == 12 and s13, '', shpD, locB,
noC, 0, '₊', rdC, dspN)
//plotshape(shwSC and C.sCC == 13, '', shpD, locB, noC, 0, '₁₃', rdC, dspN)
plotshape(noShw and ssC and C.sCC != C.sCC[1] and C.sCC == 13, 'Completed Bearish Exhaustions', shpD,
locA, color.new(#910000, 25), 0, 'E', whC, not dspN, pltS)
if C.sCC == 1
C.sCLt := b.l
C.sCHt := b.h
if ssC
C.sCHt := math.max(b.h, C.sCHt)
C.sCLt := math.min(b.l, C.sCLt)
if b.h == C.sCHt
C.sCL := b.l
if b.l == C.sCLt
C.sCH := b.h
//-----------------------------------------------------------------------------}
// Trade Setups
//-----------------------------------------------------------------------------{
plotshape(bSR > 0 and bSR[1] == 0 ? bSR : na, 'Overall Bearish Trend Mark', shpD, location.absolute, noC, 0,
'⇩', rdC, not dspN, size = size.small, display=display.none)
plotshape(sSS > 0 and sSS[1] == 0 ? sSS : na, 'Overall Bullish Trend Mark', shpU, location.absolute, noC, 0, '⇧',
gnC, not dspN, size = size.small, display=display.none)
sQC = (sBl9 > sB13) and (sB13 > sBp9) and (sBp9 > bBl9)
sPFO = tso == 'Momentum' ? S.sSC == 9 or sC8 : tso == 'Exhaustion' ? C.sCC[5] == 13 : S.sSC == 9 and sQC
ssPF := if sPFO
true
else
if sPFc
false
else
ssPF[1]
sPFc := ssPF and b.c < b.c[4] and b.c[1] > b.c[5]
sTT = 'Short Trade Setup' + sTR + '\n Signal : Completed ' + tso + ' plus Bearish Price Flip\n' +
' Stop : ' + sST +
'\n Target : ' + str.tostring(tso == 'Exhaustion' ? sCT : sSS, format.mintick)
if war and sTrd and b.o < b.c and S.sSC == 2 and not lTrd
if war and sTrd and b.o < b.c and ((sSD[1] != 0 and b.c > sSD[1]) or (sCD[1] != 0 and b.c > sCD[1]))
bQC = (bBl9 > bB13) and (bB13 > bBp9) and (bBp9 > sBl9)
bPFO = tso == 'Momentum' ? S.bSC == 9 or bC8 : tso == 'Exhaustion' ? C.bCC[5] == 13 : S.bSC == 9 and bQC
sbPF := if bPFO
true
else
if bPFc
false
else
sbPF[1]
bPFc := sbPF and b.c > b.c[4] and b.c[1] < b.c[5]
[bTR, bST] = if tso == 'Exhaustion'
if bCD == 0
[' - Risky', str.tostring(b.l, format.mintick)]
else
['', str.tostring(bCD, format.mintick)]
else
if bSD == 0
[' - Risky', str.tostring(b.l, format.mintick)]
else
['', str.tostring(bSD, format.mintick)]
lTT = 'Long Trade Setup' + bTR + '\n Signal : Completed ' + tso + ' plus Bullish Price Flip\n' +
' Stop : ' + bST +
'\n Target : ' + str.tostring(tso == 'Exhaustion' ? bCT : bSR, format.mintick)
if war and lTrd and b.o > b.c and S.bSC == 2 and not sTrd
if war and lTrd and b.o > b.c and (b.c < bSD[1] or b.c < bCD[1])
//-----------------------------------------------------------------------------}
// Alerts
//-----------------------------------------------------------------------------{
//-----------------------------------------------------------------------------}