Simple System by LEO 2@free - FX - Pro
Simple System by LEO 2@free - FX - Pro
0
at [Link]
// © leandrolopezf1920
//@version=5
indicator("Simple System by LEO 2", overlay = true, max_lines_count = 500,
max_labels_count = 500, max_boxes_count = 500, max_bars_back = 1000)
//------------------------------------------------------------------------------
// === Range Detector ===
//------------------------------------------------------------------------------
//Style
upCss = input(#089981, 'Broken Upward', group = 'Style')
dnCss = input(#f23645, 'Broken Downward', group = 'Style')
unbrokenCss = input(#2157f3, 'Unbroken', group = 'Style')
//-----------------------------------------------------------------------------}
//Detect and highlight ranges
//-----------------------------------------------------------------------------{
//Ranges drawings
var box bx = na
var line lvl = na
//Extensions
var float max2 = na
var float min2 = na
var os = 0
color detect_css = na
else if count == 0
bx.set_right(n)
lvl.set_x2(n)
//Set color
if close > bx.get_top()
bx.set_bgcolor([Link](#ff5252, 100))
lvl.set_color(upCss)
os := 1
else if close < bx.get_bottom()
bx.set_bgcolor([Link](#ff5252, 100))
lvl.set_color(dnCss)
os := -1
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Range detection bgcolor
bgcolor(detect_css)
//-----------------------------------------------------------------------------}
//-----------------------------------------------------------------------------}
//INPUTS
cooldownPeriod = [Link](10,title="Cooldown Period", minval=0, group =
"Settings")
lbLeft = 20
lbRight = 20
//FUNCTIONS
lineStyle(s) =>
if s == 'Solid'
line.style_solid
else if s == 'Dotted'
line.style_dotted
else
line.style_dashed
//VARS
var int bullSignalIndex = 0
var int bearSignalIndex = 0
//CALCULATIONS
pLow = [Link](low, lbLeft, lbRight)
pHigh = [Link](high, lbLeft, lbRight)
lp = [Link](low, lbLeft)
hp = [Link](high, lbLeft)
bullishSFP = low < pLowVal and close > pLowVal and open > pLowVal and low == lp and
lowestClose >= pLowVal
bearishSFP = high > pHighVal and close < pHighVal and open < pHighVal and high ==
hp and highestClose <= pHighVal
bullCond = bullishSFP[3] and (close > pLowVal) and (close[1] > pLowVal[1]) and
(close[2] > pLowVal[2]) and bar_index >= bullSignalIndex + cooldownPeriod
bearCond = bearishSFP[3] and (close < pHighVal) and (close[1] < pHighVal[1]) and
(close[2] < pHighVal[2]) and bar_index >= bearSignalIndex + cooldownPeriod
//Check Swing H/L Stopper
var int swingLowCounter = 0
var int swingHighCounter = 0
var bool isSwingLowCheck = false
var bool isSwingHighCheck = false
var bool stopPrintingLow = false
var bool stopPrintingHigh = false
if bearCond
bearSignalIndex := bar_index
bearLine := [Link](prevHighIndex, pHighVal, bar_index-3, pHighVal,
color=bearColor, width=bearWidth, style=lineStyle(bearStyle))
if [Link](swingHighArr) >= 3
[Link]([Link](swingHighArr))
[Link]([Link](swingHighTextArr))
if [Link](swingLowArr) >= 3
[Link]([Link](swingLowArr))
[Link]([Link](swingLowTextArr))
//PLOTS
plotshape(bullCond, text='Sweep', color=bullColor, textcolor=bullColor,
location=[Link], offset = -3)
plotshape(bearCond, text='Sweep', color=bearColor, textcolor=bearColor,
location=[Link], offset = -3)
//ALERTS
alertcondition(bullishSFP, title='Bullish Sweep', message='{{ticker}} Bullish
Sweep, Price:{{close}}')
alertcondition(bearishSFP, title='Bearish Sweep', message='{{ticker}} Bearish
Sweep, Price:{{close}}')
//------------------------------------------------------------------------------
// === Zig Zag Channels ===
//------------------------------------------------------------------------------
length1 = input(100)
extend = input(true,'Extend To Last Bar')
show_ext = input(true,'Show Extremities')
show_labels = input(true,'Show Labels')
//Style
//------------------------------------------------------------------------------
upper = [Link](src1,length1)
lower = [Link](src1,length1)
os1 := src1[length1] > upper ? 0 : src1[length1] < lower ? 1 : os1[1]
//------------------------------------------------------------------------------
btm_n = [Link](btm,n,0)
top_n = [Link](top,n,0)
len = [Link](btm_n - top_n)
if btm
max_diff_up = 0.
max_diff_dn = 0.
valbtm := low[length1]
for i = 0 to len-1
point = low[length1] + i/(len-1)*(valtop - low[length1])
max_diff_up := [Link]([Link](src1[length1+i],open[length1+i]) -
point,max_diff_up)
max_diff_dn := [Link](point -
[Link](src1[length1+i],open[length1+i]),max_diff_dn)
[Link](n[len+length1],valtop,n[length1],low[length1],color=midcol)
if show_ext
[Link](n[len+length1],valtop+max_diff_up,n[length1],low[length1]+max_diff_up
,color=upcol,style=line.style_dotted)
[Link](n[len+length1],valtop-max_diff_dn,n[length1],low[length1]-
max_diff_dn
,color=dncol,style=line.style_dotted)
if show_labels
[Link](n[length1],low[length1],[Link](low[length1],'#.####'),color=#000000
00
,style=label.style_label_up,textcolor=dncol,textalign=text.align_left,siz
e=[Link])
if top
max_diff_up = 0.
max_diff_dn = 0.
valtop := high[length1]
for i = 0 to len-1
point = high[length1] + i/(len-1)*(valbtm - high[length1])
max_diff_up := [Link]([Link](src1[length1+i],open[length1+i]) -
point,max_diff_up)
max_diff_dn := [Link](point -
[Link](src1[length1+i],open[length1+i]),max_diff_dn)
[Link](n[len+length1],valbtm,n[length1],high[length1],color=midcol)
if show_ext
[Link](n[len+length1],valbtm+max_diff_up,n[length1],high[length1]+max_diff_up
,color=upcol,style=line.style_dotted)
[Link](n[len+length1],valbtm-max_diff_dn,n[length1],high[length1]-
max_diff_dn
,color=dncol,style=line.style_dotted)
if show_labels
[Link](n[length1],high[length1],[Link](high[length1],'#.####'),color=#0000
0000
,style=label.style_label_down,textcolor=upcol,textalign=text.align_left,s
ize=[Link])
if os1 == 1
x1 := btm_n-length1
y1 := valbtm
for i = 0 to n-btm_n+length1-1
point = src1 + i/(n-btm_n+length1-1)*(valbtm - src1)
max_diff_up := [Link]([Link](src1[i],open[i]) - point,max_diff_up)
max_diff_dn := [Link](point - [Link](src1[i],open[i]),max_diff_dn)
else
x1 := top_n-length1
y1 := valtop
for i = 0 to n-top_n+length1-1
point = src1 + i/(n-top_n+length1-1)*(valtop - src1)
max_diff_up := [Link]([Link](src1[i],open[i]) - point,max_diff_up)
max_diff_dn := [Link](point - [Link](src1[i],open[i]),max_diff_dn)
[Link]([Link](x1,y1,n,src1,color=midcol,extend=[Link])[1])
if show_ext
[Link]([Link](x1,y1+max_diff_up,n,src1+max_diff_up
,color=upcol,style=line.style_dotted,extend=[Link])[1])
[Link]([Link](x1,y1-max_diff_dn,n,src1-max_diff_dn
,color=dncol,style=line.style_dotted,extend=[Link])[1])
//------------------------------------------------------------------------------
plot(btm ? low[length1] : top ? high[length1] : na,'Circles'
,color = btm ? dncol : upcol
,style=plot.style_circles
,offset=-length1)
//-----------------------------------------------------------------------------}
//--------------//
C_DownTrend = true
C_UpTrend = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = [Link](trendRule1, "Detect Trend Based On",
options=[trendRule1, trendRule2, "No detection"])
if trendRule == trendRule1
priceAvg = [Link](close, 50)
C_DownTrend := close < priceAvg
C_UpTrend := close > priceAvg
if trendRule == trendRule2
sma200 = [Link](close, 200)
sma50 = [Link](close, 50)
C_DownTrend := close < sma50 and sma50 < sma200
C_UpTrend := close > sma50 and sma50 > sma200
C_EngulfingBullishNumberOfCandles = 2
C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1]
and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1]
or open < close[1] )
alertcondition(C_EngulfingBullish, title = "New pattern detected", message = "New
Engulfing – Bullish pattern detected")
if C_EngulfingBullish
var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend,
there will most likely be a reversal pattern. To distinguish the first day, this
candlestick pattern uses a small body, followed by a day where the candle body
fully overtakes the body from the day before, and closes in the trend’s opposite
direction. Although similar to the outside reversal chart pattern, it is not
essential for this pattern to completely overtake the range (high to low), rather
only the open and the close."
[Link](bar_index, patternLabelPosLow, text="BE", style=label.style_label_up,
color = label_color_bullish, textcolor=[Link], tooltip = ttBullishEngulfing)
C_EngulfingBearishNumberOfCandles = 2
C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1]
and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1]
or open > close[1] )
alertcondition(C_EngulfingBearish, title = "New pattern detected", message = "New
Engulfing – Bearish pattern detected")
if C_EngulfingBearish
var ttBearishEngulfing = "Engulfing\nAt the end of a given uptrend, a reversal
pattern will most likely appear. During the first day, this candlestick pattern
uses a small body. It is then followed by a day where the candle body fully
overtakes the body from the day before it and closes in the trend’s opposite
direction. Although similar to the outside reversal chart pattern, it is not
essential for this pattern to fully overtake the range (high to low), rather only
the open and the close."
[Link](bar_index, patternLabelPosHigh, text="BE",
style=label.style_label_down, color = label_color_bearish, textcolor=[Link],
tooltip = ttBearishEngulfing)
//-----------------------------------------------------------------------------}
//SUPPORT AND RESISTANCE MTF
//-----------------------------------------------------------------------------{
const bool DEBUG = false
const int timeframeCount = 3
const float touchATR = 1.0 / 30.0
const float retestATR = 1.0 / 30.0
const float labelOffsetY = 1.5
const int labelOffsetsXIndex = 30
const int maxPivotsBackSR = 15
const int retestLabelEveryXBars = 3
const int maxTraverse = 250 // Affects bar history limit. Default value 250.
const int maxRetestLabels = 100
const int maxSupports = 3
const int maxResistances = 3
const int debug_maxPivotLabels = 25
atr1 = [Link](30)
createRSLabel () =>
[Link](na, na, "", style = label.style_none, textcolor = textColor)
type customPoint
int t
float price
type RSInfo
bool isBroken = na
int brokenTime = na
string RSType = na
float price = na
line line = na
box box = na
label priceLabel = na
customPoint[] points = na
label[] debugPoints = na
label breakLabel = na
label[] retestLabels = na
line breakLine = na
box breakBox = na
curTR = [Link](true)
lowPivot = [Link](low, pivotRange, pivotRange)
highPivot = [Link](high, pivotRange, pivotRange)
pivotTime = time[pivotRange]
newRSInfoF
[Link] := [Link]<label>(0)
[Link] := [Link]<label>(0)
[Link] := [Link]<customPoint>(0)
if enableZones
[Link] := createRSBox(RSType == "Resistance" ? resistanceColor :
supportColor, xloc.bar_time)
moveRSInfoBox([Link], startTime, [Link], endTime)
box.set_extend([Link], expandLines ? [Link] : [Link])
box.set_text([Link], histText)
else
[Link] := [Link]([Link])
moveLine([Link], startTime, [Link], endTime)
line.set_extend([Link], expandLines ? [Link] : [Link])
[Link] := [Link]([Link])
label.set_text([Link], histText)
label.set_xloc([Link], (startTime + endTime) / 2, xloc.bar_time)
if not na([Link])
[Link] := [Link]([Link])
newRS
if [Link]() > 0
for i = 0 to [Link]() - 1
[Link]([Link](i))
if [Link]() > 0
for i = 0 to [Link]() - 1
[Link]([Link](i))
[Link]([Link])
[Link]([Link])
[Link]([Link])
type timeframeInfo
int index = na
string timeframeStr = na
bool isEnabled = false
RSInfo[] resistances = na
RSInfo[] supports = na
float[] highPivots = na
float[] highTRs = na
int[] highTimes = na
float[] lowPivots = na
float[] lowTRs = na
int[] lowTimes = na
[Link] := [Link]<RSInfo>(debug_lastXResistances)
[Link] := [Link]<RSInfo>(debug_lastXSupports)
[Link] := [Link]<float>()
[Link] := [Link]<float>()
[Link] := [Link]<int>()
[Link] := [Link]<float>()
[Link] := [Link]<float>()
[Link] := [Link]<int>()
newTFInfo
doValuesTouch (float value1, float value2, float tr, float customATRRatio) =>
if [Link](value1 - value2) <= tr * customATRRatio
true
else
false
index = pivotsCount - i - 1
occurances = 0
invalidValue = false
pivotValue1 = [Link](index)
if [Link]() > 0
for a = 0 to [Link]() - 1
if doValuesTouch(pivotValue1, [Link](a),
[Link](index))
invalidValue := true
break
if invalidValue
continue
for j = 0 to pivotsCount - 1
if j >= maxTraverse
break
index2 = pivotsCount - j - 1
pivotValue2 = [Link](index2)
if doValuesTouch(pivotValue1, pivotValue2, [Link](index))
occurances += 1
if not na(latestRSF)
break
if not na(latestRSF)
cnt = 0
if pivotsCount > 0
for i = 0 to pivotsCount - 1
if i >= maxTraverse
break
index = pivotsCount - i - 1
pivotValue = [Link](index)
if doValuesTouch(pivotValue, [Link], [Link](index))
labelTime = [Link](index)
[Link]([Link](labelTime, pivotValue))
cnt += 1
if cnt == strength
break
curIndex = 0
float foundBreakLevel = na
int foundBreakTime = na
float foundBreakTR = na
while true
if curIndex >= maxTraverse
break
isBarBreak = [Link] == "Resistance" ? (close[curIndex + 1] <=
[Link] and close[curIndex] > [Link]) : (close[curIndex + 1] >=
[Link] and close[curIndex] < [Link])
if isBarBreak
isTrueBreakout = true
if avoidFalseBreaks
shortTerm = 2
longTerm = 15
shortSum = 0.0
longSum = 0.0
for i = 0 to shortTerm
shortSum += volume[curIndex + i]
for i = 0 to longTerm
longSum += volume[curIndex + i]
curIndex += 1
if time[curIndex] <= [Link]([Link]() - 1).t
break
[foundBreakLevel, foundBreakTime, foundBreakTR]
curIndex = 0
lastRetestIndex = -999
int[] retestTimes = [Link]<int>()
float[] retestLevels = [Link]<float>()
float[] retestTRs = [Link]<float>()
while true
if curIndex >= maxTraverse
break
if [Link]() == maxRetestLabels
break
if [Link] and time[curIndex] >= [Link]
curIndex += 1
continue
tr = high[curIndex] - low[curIndex]
isRetest = ([Link] == "Resistance" ? (doValuesTouch([Link],
close[curIndex], tr, retestATR) or doValuesTouch([Link], high[curIndex], tr,
retestATR)) : (doValuesTouch([Link], close[curIndex], tr, retestATR) or
doValuesTouch([Link], low[curIndex], tr, retestATR)))
if isRetest and curIndex - lastRetestIndex >= retestLabelEveryXBars
[Link]([Link] == "Resistance" ? high[curIndex] :
low[curIndex])
[Link](time[curIndex])
[Link](high[curIndex] - low[curIndex])
lastRetestIndex := curIndex
curIndex += 1
if time[curIndex] <= [Link]([Link]() - 1).t
break
[retestLevels, retestTimes, retestTRs]
if not na(foundBreakLevel)
if showBreaks
if na([Link])
[Link] := createBreakLabel([Link])
label.set_xy([Link], foundBreakTime, foundBreakLevel +
([Link] == "Resistance" ? (-foundBreakTR / labelOffsetY) : foundBreakTR /
labelOffsetY))
if expandLines
if na([Link]) and enableZones == false
[Link] := createRSLine([Link])
if not enableZones
line.set_extend([Link], [Link])
else
box.set_extend([Link], [Link])
if showRetests
[retestLevels, retestTimes, retestTRs] = getRetests(RSInfoF)
if expandLines
if not enableZones
line.set_extend([Link], (na(foundBreakTime)) ? [Link] :
[Link])
else
box.set_extend([Link], (na(foundBreakTime)) ? [Link] :
[Link])
else
if not enableZones
line.set_extend([Link], na(foundBreakTime) ? [Link] :
[Link])
else
box.set_extend([Link], na(foundBreakTime) ? [Link] :
[Link])
if not enableZones
label.set_text([Link], enableZones ? "" : labelTitle)
label.set_y([Link], [Link])
else
box.set_text([Link], ([Link] and expandLines) ? "" :
labelTitle)
box.set_text([Link], labelTitle)
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link] := lowPivots
[Link] := highPivots
[Link] := lowTimes
[Link] := highTimes
[Link] := lowTRs
[Link] := highTRs
if [Link]() > 0
for j = 0 to [Link]() - 1
RSInfo RSInfoF = [Link](j)
if not na(RSInfoF)
if debug_enabledHistory
if checkIfArrHasRS(oldRSList, RSInfoF) == false
[Link](RSInfoF)
oldRetestsCount += [Link]()
oldBreaksCount += [Link] ? 1 : 0
derenderRSInfo(RSInfoF)
if [Link]() > 0
for j = 0 to [Link]() - 1
RSInfo RSInfoF = [Link](j)
if not na(RSInfoF)
if debug_enabledHistory
if checkIfArrHasRS(history, RSInfoF) == false
[Link](RSInfoF)
oldRetestsCount += [Link]()
oldBreaksCount += [Link] ? 1 : 0
derenderRSInfo(RSInfoF)
[Link]()
[Link]()
[oldRetestsCount, oldBreaksCount]
if count > 0
for j = 0 to count - 1
foundRS = findLatestNthRS(timeframeInfoF, RSType, pivots, times, trs, j
+ 1)
if not na(foundRS)
notDuplicate = true
for a = 0 to [Link]() - 1
aInfo = [Link](a)
if na(aInfo) or [Link] == false
continue
otherTimeframeArray = (RSType == "Resistance" ?
[Link] : [Link])
if [Link]() > 0
for b = 0 to [Link]() - 1
if checkIfRSAreSame(foundRS,
[Link](b))
notDuplicate := false
break
if notDuplicate == false
break
if notDuplicate or not debug_removeDuplicateRS
[Link](foundRS)
if [Link]() > 0
for j = 0 to [Link]() - 1
curRS = [Link](j)
if not na(curRS)
handleRSInfo(timeframeInfoF, curRS, j, RSType)
curRetestsCount += [Link]()
curBreaksCount += [Link] ? 1 : 0
[curRetestsCount, curBreaksCount]
if not na(lowPivot)
[Link](lowPivot)
[Link](pivotTime)
[Link](curTR[pivotRange])
if [Link]() > maxPivotsAllowed
[Link](0)
[Link](0)
[Link](0)
if not na(highPivot)
[Link](highPivot)
[Link](pivotTime)
[Link](curTR[pivotRange])
if [Link]() > maxPivotsAllowed
[Link](0)
[Link](0)
[Link](0)
//plot(nz(na,[Link](0).[Link]() > 0 ?
[Link](0).[Link]([Link](0).[Link]() - 1) :
0), color = [Link], title = "High Pivots")
//plot(nz(na,[Link](0).[Link]() > 0 ?
[Link](0).[Link]([Link](0).[Link]() - 1) :
0), color = [Link], title = "Low Pivots")
int enabledTimeframeCount = 0
for i = 0 to timeframeCount - 1
timeframeInfo curInfo = [Link](i)
if [Link]
enabledTimeframeCount += 1
int oldRetestsCount = 0
int curRetestsCount = 0
int oldBreaksCount = 0
int curBreaksCount = 0
for i = 0 to timeframeCount - 1
timeframeInfo curInfo = [Link](i)
if not [Link]
continue
if debug_enabledHistory
historyIndexesToDelete = [Link]<int>(0)
if [Link]() > 0
for i = 0 to [Link]() - 1
if checkIfArrHasRS(curRSList, [Link](i))
[Link](i)
if [Link]() > 0
for i = 0 to [Link]() - 1
deleteIndex =
[Link]([Link]() - i - 1)
safeDeleteRSInfo([Link](deleteIndex))
[Link](deleteIndex)
if [Link]() > 0
for i = 0 to [Link]() - 1
curRS = [Link](i)
if checkIfArrHasRS(curRSList, curRS) == false
[Link](histRSInfo(curRS))
if [Link]() > debug_maxHistoryRecords
safeDeleteRSInfo([Link](0))
[Link](0)
if [Link]() > 0
for i = 0 to [Link]() - 1
safeDeleteRSInfo([Link](i))
[Link]()
[Link]()
if DEBUG
[Link]("History Size : " + [Link]([Link]()))
[Link]("Label Count : " + [Link]([Link]()))
[Link]("Line Count : " + [Link]([Link]()))
[Link]("Box Count : " + [Link]([Link]()))
initRun := false

![min2 := ma - atr
//Set new box and level
bx := box.new(n[length3], ma + atr, n, ma - atr, na](/p?url=https%3A%2F%2Fscreenshots.scribd.com%2FScribd%2F252_100_85%2F326%2F751036734%2F2.jpeg&__src=https%3A%2F%2Fwww.scribd.com%2Fdocument%2F751036734%2FSimple-System-by-LEO-2-free-fx-pro&__type=image)




![max_diff_up := math.max(math.max(src1[length1+i],open[length1+i]) -
point,max_diff_up)
max_diff_dn := math.m](/p?url=https%3A%2F%2Fscreenshots.scribd.com%2FScribd%2F252_100_85%2F326%2F751036734%2F7.jpeg&__src=https%3A%2F%2Fwww.scribd.com%2Fdocument%2F751036734%2FSimple-System-by-LEO-2-free-fx-pro&__type=image)

![and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1]
or open < close[1] )
alertcondition(C_Eng](/p?url=https%3A%2F%2Fscreenshots.scribd.com%2FScribd%2F252_100_85%2F326%2F751036734%2F9.jpeg&__src=https%3A%2F%2Fwww.scribd.com%2Fdocument%2F751036734%2FSimple-System-by-LEO-2-free-fx-pro&__type=image)
