Machine Learning KNN Based With Support and Resistance
Machine Learning KNN Based With Support and Resistance
0 at
https://mozilla.org/MPL/2.0/
// © capissimo
//@version=5
indicator('Machine Learning: kNN-based Strategy', 'ML-kNN', true,
max_labels_count=300, format=format.price, precision=2)
//-- Inputs
//-- Constants
//-- Variable
// Result data
var array<int> predictions = array.new_int(0)
var float prediction = 0.0
var array<int> bars = array.new<int>(1, 0) // array used as a container
for inter-bar variables
// Signals
var int signal = CLEAR
//-- Functions
//-- Logic
// TOADD or TOTRYOUT:
// ta.cmo(close, LongWindow), ta.cmo(close, ShortWinow)
// ta.mfi(close, LongWindow), ta.mfi(close, ShortWinow)
// ta.mom(close, LongWindow), ta.mom(close, ShortWinow)
// Ucomment the followng statement (if barstate.islast) and tab everything below
// between BOBlock and EOBlock marks to see just the recent several signals
gradually
// showing up, rather than all the preceding signals
//if barstate.islast
//==BOBlock
// Core logic of the algorithm
int size = array.size(directions)
float maxdist = -999.0
// Loop through the training arrays, getting distances and corresponding
directions.
for i=0 to size-1
// Calculate the euclidean distance of current point to all historic points,
// here the metric used might as well be a manhattan distance or any other.
float d = math.sqrt(math.pow(f1 - array.get(feature1, i), 2) + math.pow(f2 -
array.get(feature2, i), 2))
if d > maxdist
maxdist := d
if array.size(predictions) >= k
array.shift(predictions)
array.push(predictions, array.get(directions, i))
//==EOBlock
bool filter = Filter ? ta.atr(10) > ta.atr(40) : true // filter out by volatility
or ex. ta.atr(1) > ta.atr(10)...
// Now that we got a prediction for the next market move, we need to make use of
this prediction and
// trade it. The returns then will show if everything works as predicted.
// Over here is a simple long/short interpretation of the prediction,
// but of course one could also use the quality of the prediction (+5 or +1) in
some sort of way,
// ex. for position sizing.
//-- Visuals
//-- Notification
// var start_lt = 0.
// var long_trades = 0.
// var start_st = 0.
// var short_trades = 0.
// if startLongTrade
// start_lt := ohlc4
// if endLongTrade
// long_trades := (open - start_lt) * lot_size
// if startShortTrade
// start_st := ohlc4
// if endShortTrade
// short_trades := (start_st - open) * lot_size
//------------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------{
srMR = input.float(2, 'Support Resistance Margin', minval = .1, maxval = 10, step
= .1, group = srGR)
mnGR = 'Manupulations'
mnSH = input.bool(true, 'Manupulation Zones', group = mnGR)
mnMR = input.float(1.3, 'Manupulation Margin', minval = .1, maxval = 10, step
= .1, group = mnGR)
mnSZC = input(color.new(#2962ff, 73), 'Manupulation Zones, Support', inline =
'LQ', group = mnGR)
mnRZC = input(color.new(#ff9800, 73), 'Resistance', inline = 'LQ', group = mnGR)
sigGR = 'Signals'
srFBT = 'Filters the breakouts that failed to continue beyond a level'
srFBO = input.bool(true, 'Avoid False Breakouts', group = sigGR, tooltip = srFBT)
othGR = 'Others'
swSH = input.string('None', "Swing Levels", options=['Auto', 'Small', 'Normal',
'Large', 'None'], inline = 'sw', group = othGR)
swHC = input(color.new(#f23645, 33), 'H', inline = 'sw', group = othGR)
swLC = input(color.new(#089981, 33), 'L', inline = 'sw', group = othGR)
//-----------------------------------------------------------------------------}
// User Defined Types
//-----------------------------------------------------------------------------{
type bar
float o = open
float h = high
float l = low
float c = close
float v = volume
int i = bar_index
type pivotPoint
int x
int x1
float h
float h1
float l
float l1
bool hx
bool lx
type SnR
box bx
box lq
line ln
bool b
bool t
bool r
bool l
float m
//-----------------------------------------------------------------------------}
// Variables
//-----------------------------------------------------------------------------{
bar b = bar.new()
var SnR lR = SnR.new(box(na), box(na), line(na), false, false, false, false, na)
var SnR lS = SnR.new(box(na), box(na), line(na), false, false, false, false, na)
var SnR lRt = SnR.new(box(na), box(na), line(na), false, false, false, false, na)
var SnR lSt = SnR.new(box(na), box(na), line(na), false, false, false, false, na)
//-----------------------------------------------------------------------------}
// General Calculations
//-----------------------------------------------------------------------------{
ch_m = if timeframe.isintraday
timeframe.multiplier
else if timeframe.isdaily
1440
else if timeframe.isweekly
10080
else if timeframe.ismonthly
10080 * 30
atr = ta.atr(17)
isLLS = math.abs(b.l - math.min(b.o, b.c)) >= 1.618 * atr
isLUS = math.abs(b.h - math.max(b.o, b.c)) >= 1.618 * atr
//-----------------------------------------------------------------------------}
// Functions/Methods
//-----------------------------------------------------------------------------{
f_getSize(_s) =>
switch _s
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
=> size.auto
//-----------------------------------------------------------------------------}
// Calculations
//-----------------------------------------------------------------------------{
if not na(pp_h)
pp.h1 := pp.h
pp.h := pp_h
pp.x1 := pp.x
pp.x := b.i[srLN]
pp.hx := false
if R.size() > 1
lR := R.get(0)
lRt := R.get(1)
R.unshift(
SnR.new(
box.new(pp.x, pp.h, b.i, pp.h * (1 - ((pHST - pLST) /
pHST) * .17 * srMR), border_color = color(na), bgcolor = srRZC),
box.new(na, na, na, na, bgcolor = color(na), border_color
= color(na)),
line.new(pp.x, pp.h, b.i, pp.h, color = srRLC, width =
srMR <= .5 ? 2 : 3),
false, false, false, false, (pHST - pLST) / pHST))
lS.t := false
else
lRt.bx.set_right(b.i)
lRt.ln.set_x2(b.i)
lS.t := false
if swSH != 'None'
StS = pp.x - pp.x1
tradedVolume = f_getTradedVolume(StS, srLN)
swH = pp.h > pp.h1 ? "Higher High" : pp.h < pp.h1 ? "Lower High" : na
rTT = 'Swing High (' + swH + ') : ' + str.tostring(pp.h, format.mintick) +
(mss == -1 and pp.h < pp.h1 ? '\n *Counter-Trend Move' : '') +
'\n -Price Change : ↑ %' + str.tostring((pp.h - pp.l) * 100 / pp.l ,
'#.##') +
(nz(b.v) ? '\n -Traded Volume : ' + str.tostring(tradedVolume,
format.volume) + ' (' + str.tostring(StS - 1) + ' bars)' +
'\n *Average Volume/Bar : ' + str.tostring(tradedVolume / (StS -
1), format.volume) : '')
label.new(pp.x, pp.h, '◈', color = color(na), style =
label.style_label_down, textcolor = swHC, size = f_getSize(swSH), tooltip = rTT)
alert('New ' + swH + (mss == -1 and pp.h < pp.h1 ? ' (counter-trend
move)' : '') + ' formed\n' + syminfo.ticker + ' price (' + str.tostring(b.c,
format.mintick) + '), timeframe ' + timeframe.period)
if b.c[1] > pp.h and b.c > pp.h and not pp.hx
pp.hx := true
mss := 1
if not na(pp_l)
pp.l1 := pp.l
pp.l := pp_l
pp.x1 := pp.x
pp.x := b.i[srLN]
pp.lx := false
if S.size() > 2
lS := S.get(0)
lSt := S.get(1)
S.unshift(
SnR.new(
box.new(pp.x, pp.l * (1 + ((pHST - pLST) / pHST) * .17 *
srMR), b.i, pp.l, border_color = color(na), bgcolor = srSZC),
box.new(na, na, na, na, bgcolor = color(na), border_color
= color(na)),
line.new(pp.x, pp.l, b.i, pp.l, color = srSLC, width =
srMR <= .5 ? 2 : 3),
false, false, false, false, (pHST - pLST) / pHST))
lR.t := false
else
lSt.bx.set_right(b.i)
lSt.ln.set_x2(b.i)
lR.t := false
if swSH != 'None'
StS = pp.x - pp.x1
tradedVolume = f_getTradedVolume(StS, srLN)
swL = pp.l < pp.l1 ? "Lower Low" : pp.l > pp.l1 ? "Higher Low" : na
sTT = 'Swing Low (' + swL + ') : ' + str.tostring(pp.l, format.mintick) +
(mss == 1 and pp.l > pp.l1 ? '\n *Counter-Trend Move' : '') +
'\n -Price Change : ↓ %' + str.tostring((pp.h - pp.l) * 100 / pp.h ,
'#.##') +
(nz(b.v) ? '\n -Traded Volume : ' + str.tostring(tradedVolume,
format.volume) + ' (' + str.tostring(StS - 1) + ' bars)' +
'\n *Average Volume/Bar : ' + str.tostring(tradedVolume / (StS -
1), format.volume) : '')
label.new(pp.x, pp.l, '◈', color = color(na), style = label.style_label_up,
textcolor = swLC, size = f_getSize(swSH), tooltip = sTT)
alert('New ' + swL + (mss == 1 and pp.l > pp.l1 ? ' (counter-trend move)' :
'') + ' formed\n' + syminfo.ticker + ' price (' + str.tostring(b.c, format.mintick)
+ '), timeframe ' + timeframe.period)
if b.c[1] < pp.l and b.c < pp.l and not pp.lx
pp.lx := true
mss := -1
if R.size() > 0
lR := R.get(0)
if srFBO and b.c[1] > lR.bx.get_top() * (1 + lR.m * .17) and not lR.b
lR.bx.set_right(b.i[1])
lR.ln.set_x2(b.i[1])
lR.b := true
lR.r := false
if srBS != 'None'
alert('Bullish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.c[1] > lR.bx.get_top() and not lR.b and not srFBO
lR.bx.set_right(b.i[1])
lR.ln.set_x2(b.i[1])
lR.b := true
lR.r := false
S.unshift(
SnR.new(
box.new(b.i[1], lR.bx.get_top(), b.i + 1, lR.bx.get_bottom(),
border_color = color(na), bgcolor = srSZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lR.bx.get_bottom(), b.i + 1, lR.bx.get_bottom(),
color = srSLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lR.m))
//R.remove(0)
if srBS != 'None'
alert('Bullish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if lS.b and b.o[1] < lR.bx.get_top() and b.h[1] > lR.bx.get_bottom() and
b.c[1] < lR.bx.get_bottom() and not lR.r and b.i[1] != lR.bx.get_left()
label.new(b.i[1], b.h[1] * (1 + lR.m * .017), 'R', color = srRDC, style =
label.style_label_down , textcolor = srRTC, size = f_getSize(srRS), tooltip = 'Re-
test of Resistance Zone' + vST[1] )
lR.r := true //
lR.bx.set_right(b.i)
lR.ln.set_x2(b.i)
if srRS != 'None'
alert('Re-test of resistance zone detected\n' + syminfo.ticker + '
price (' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.h[1] > lR.bx.get_bottom() and b.c[1] < lR.bx.get_top() and b.c <
lR.bx.get_top() and not lR.t and not lR.r and not lR.b and not lS.b and b.i[1] !=
lR.bx.get_left()
label.new(b.i[1], b.h[1] * (1 + lR.m * .017), 'T', color = srTDC, style =
label.style_label_down , textcolor = srTTC, size = f_getSize(srTS), tooltip = 'Test
of Resistance Zone' + vST[1] )
lR.t := true
lR.bx.set_right(b.i)
lR.ln.set_x2(b.i)
if srTS != 'None'
alert('Test of resistance zone detected\n' + syminfo.ticker + ' price
(' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period,
alert.freq_once_per_bar_close)
else if b.h > lR.bx.get_bottom() * (1 - lR.m * .17) and not lR.b //and
lR.bx.get_top() != lS.bx.get_top()
if b.h > lR.bx.get_bottom()
lR.bx.set_right(b.i)
lR.ln.set_x2(b.i)
if mnSH
if b.h > lR.bx.get_top() and b.c <= lR.bx.get_top() * (1 + lR.m * .17 *
mnMR) and not lR.l and b.i == lR.bx.get_right()
if lR.lq.get_right() + srLN > b.i
lR.lq.set_right(b.i + 1)
lR.lq.set_top(math.min(math.max(b.h, lR.lq.get_top()),
lR.bx.get_top() * (1 + lR.m * .17 * mnMR)))
else
lR.lq.set_lefttop(b.i[1], math.min(b.h, lR.bx.get_top() * (1 + lR.m
* .17 * mnMR)))
lR.lq.set_rightbottom(b.i + 1, lR.bx.get_top())
lR.lq.set_bgcolor(mnRZC)
lR.l := true
else if b.h > lR.bx.get_top() and b.c <= lR.bx.get_top() * (1 + lR.m * .17
* mnMR) and lR.l and b.i == lR.bx.get_right()
lR.lq.set_right(b.i + 1)
lR.lq.set_top(math.min(math.max(b.h,lR.lq.get_top()), lR.bx.get_top() *
(1 + lR.m * .17 * mnMR)))
else if lR.l and (b.c >= lR.bx.get_top() * (1 + lR.m * .17 * mnMR) or b.c <
lR.bx.get_bottom())
lR.l := false
if lR.bx.get_top() != lRt.bx.get_top()
if srFBO and b.c[1] > lRt.bx.get_top() * (1 + lRt.m * .17) and not lRt.b
lRt.bx.set_right(b.i[1])
lRt.ln.set_x2(b.i[1])
lRt.b := true
lRt.r := false
S.unshift(
SnR.new(
box.new(b.i[1], lRt.bx.get_top(), b.i + 1, lRt.bx.get_bottom(),
border_color = color(na), bgcolor = srSZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lRt.bx.get_bottom(), b.i + 1,
lRt.bx.get_bottom(), color = srSLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lRt.m))
//R.remove(1)
if srBS != 'None'
alert('Bullish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.c[1] > lRt.bx.get_top() and not lRt.b and not srFBO
lRt.bx.set_right(b.i[1])
lRt.ln.set_x2(b.i[1])
lRt.b := true
lRt.r := false
S.unshift(
SnR.new(
box.new(b.i[1], lRt.bx.get_top(), b.i + 1, lRt.bx.get_bottom(),
border_color = color(na), bgcolor = srSZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lRt.bx.get_bottom(), b.i + 1,
lRt.bx.get_bottom(), color = srSLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lRt.m))
//R.remove(1)
if srBS != 'None'
alert('Bullish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
if srRS != 'None'
alert('Re-test of resistance zone detected\n' + syminfo.ticker + '
price (' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.h[1] > lRt.bx.get_bottom() and b.c[1] < lRt.bx.get_top() and b.c
< lRt.bx.get_top() and not lRt.t and not lRt.b and not lSt.b and b.i[1] !=
lRt.bx.get_left()
label.new(b.i[1], b.h[1] * (1 + lRt.m * .017), 'T', color = srTDC,
style = label.style_label_down , textcolor = srTTC, size = f_getSize(srTS), tooltip
= 'Test of Resistance Zone' + vST[1] )
lRt.t := true
lRt.bx.set_right(b.i)
lRt.ln.set_x2(b.i)
if srTS != 'None'
alert('Test of resistance zone detected\n' + syminfo.ticker + '
price (' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period,
alert.freq_once_per_bar_close)
if mnSH
if b.h > lRt.bx.get_top() and b.c <= lRt.bx.get_top() * (1 + lRt.m
* .17 * mnMR) and not lRt.l and b.i == lRt.bx.get_right()
if lRt.lq.get_right() + srLN > b.i
lRt.lq.set_right(b.i + 1)
lRt.lq.set_top(math.min(math.max(b.h, lRt.lq.get_top()),
lRt.bx.get_top() * (1 + lRt.m * .17 * mnMR)))
else
lRt.lq.set_lefttop(b.i[1], math.min(b.h, lRt.bx.get_top() * (1
+ lRt.m * .17 * mnMR)))
lRt.lq.set_rightbottom(b.i + 1, lRt.bx.get_top())
lRt.lq.set_bgcolor(mnRZC)
lRt.l := true
if S.size() > 1
lS := S.get(0)
if srFBO and b.c[1] < lS.bx.get_bottom() * (1 - lS.m * .17) and not lS.b
lS.bx.set_right(b.i[1])
lS.ln.set_x2(b.i[1])
lS.b := true
lS.r := false
R.unshift(
SnR.new(
box.new(b.i[1], lS.bx.get_top(), b.i + 1, lS.bx.get_bottom(),
border_color = color(na), bgcolor = srRZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lS.bx.get_top(), b.i + 1, lS.bx.get_top(), color =
srRLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lS.m))
//S.remove(0)
if srBS != 'None'
alert('Bearish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
R.unshift(
SnR.new(
box.new(b.i[1], lS.bx.get_top(), b.i + 1, lS.bx.get_bottom(),
border_color = color(na), bgcolor = srRZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lS.bx.get_top(), b.i + 1, lS.bx.get_top(), color =
srRLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lS.m))
//S.remove(0)
if srBS != 'None'
alert('Bearish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if lR.b and b.o[1] > lS.bx.get_bottom() and b.l[1] < lS.bx.get_top() and
b.c[1] > lS.bx.get_top() and not lS.r and b.i[1] != lS.bx.get_left()
label.new(b.i[1], b.l[1] * (1 - lS.m * .017), 'R', color = srRUC, style =
label.style_label_up , textcolor = srRTC, size = f_getSize(srRS), tooltip = 'Re-
test of Support Zone' + vST[1] )
lS.r := true //
lS.bx.set_right(b.i)
lS.ln.set_x2(b.i)
if srRS != 'None'
alert('Re-test of support zone detected\n' + syminfo.ticker + ' price
(' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.l[1] < lS.bx.get_top() and b.c[1] > lS.bx.get_bottom() and b.c >
lS.bx.get_bottom() and not lS.t and not lS.b and not lR.b and b.i[1] !=
lS.bx.get_left()
label.new(b.i[1], b.l[1] * (1 - lS.m * .017), 'T', color = srTUC, style =
label.style_label_up , textcolor = srTTC, size = f_getSize(srTS), tooltip = 'Test
of Support Zone' + vST[1] )
lS.t := true
lS.bx.set_right(b.i)
lS.ln.set_x2(b.i)
if srTS != 'None'
alert('Test of support zone detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period,
alert.freq_once_per_bar_close)
else if b.l < lS.bx.get_top() * (1 + lS.m * .17) and not lS.b //and
lS.bx.get_bottom() != lR.bx.get_bottom()
if b.l < lS.bx.get_top()
lS.bx.set_right(b.i)
lS.ln.set_x2(b.i)
if mnSH
if b.l < lS.bx.get_bottom() and b.c >= lS.bx.get_bottom() * (1 - lS.m * .17
* mnMR) and not lS.l and b.i == lS.bx.get_right()
if lS.lq.get_right() + srLN > b.i
lS.lq.set_right(b.i + 1)
lS.lq.set_bottom(math.max(math.min(b.l, lS.lq.get_bottom()),
lS.bx.get_bottom() * (1 - lS.m * .17 * mnMR)))
else
lS.lq.set_lefttop(b.i[1], lS.bx.get_bottom())
lS.lq.set_rightbottom(b.i + 1, math.max(b.l, lS.bx.get_bottom() *
(1 - lS.m * .17 * mnMR)))
lS.lq.set_bgcolor(mnSZC)
lS.l := true
if lS.bx.get_bottom() != lSt.bx.get_bottom()
R.unshift(
SnR.new(
box.new(b.i[1], lSt.bx.get_top(), b.i + 1, lSt.bx.get_bottom(),
border_color = color(na), bgcolor = srRZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lSt.bx.get_top(), b.i + 1, lSt.bx.get_top(),
color = srRLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lSt.m))
//S.remove(1)
if srBS != 'None'
alert('Bearish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.c[1] < lSt.bx.get_bottom() and not lSt.b and not srFBO //and
b.i[1] != lR.bx.get_left()
lSt.bx.set_right(b.i[1])
lSt.ln.set_x2(b.i[1])
lSt.b := true
lSt.r := false
R.unshift(
SnR.new(
box.new(b.i[1], lSt.bx.get_top(), b.i + 1, lSt.bx.get_bottom(),
border_color = color(na), bgcolor = srRZC),
box.new(na, na, na, na, bgcolor = color(na), border_color =
color(na)),
line.new(b.i[1], lSt.bx.get_top(), b.i + 1, lSt.bx.get_top(),
color = srRLC, width = srMR <= .5 ? 2 : 3),
false, false, false, false, lSt.m))
//S.remove(1)
if srBS != 'None'
alert('Bearish breakout detected\n' + syminfo.ticker + ' price (' +
str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
if srRS != 'None'
alert('Re-test of support zone detected\n' + syminfo.ticker + '
price (' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period)
else if b.l[1] < lSt.bx.get_top() and b.c[1] > lSt.bx.get_bottom() and b.c
> lSt.bx.get_bottom() and not lSt.t and not lSt.b and not lRt.b and b.i[1] !=
lSt.bx.get_left()
label.new(b.i[1], b.l[1] * (1 - lSt.m * .017), 'T', color = srTUC,
style = label.style_label_up , textcolor = srTTC, size = f_getSize(srTS), tooltip =
'Test of Support Zone' + vST[1] )
lSt.t := true
lSt.bx.set_right(b.i)
lSt.ln.set_x2(b.i)
if srTS != 'None'
alert('Test of support zone detected\n' + syminfo.ticker + ' price
(' + str.tostring(b.c, format.mintick) + '), timeframe ' + timeframe.period,
alert.freq_once_per_bar_close)
if mnSH
if b.l < lSt.bx.get_bottom() and b.c >= lSt.bx.get_bottom() * (1 -
lSt.m * .17 * mnMR) and not lSt.l and b.i == lSt.bx.get_right()
if lSt.lq.get_right() + srLN > b.i
lSt.lq.set_right(b.i + 1)
lSt.lq.set_bottom(math.max(math.min(b.l, lSt.lq.get_bottom()),
lSt.bx.get_bottom() * (1 - lSt.m * .17 * mnMR)))
else
lSt.lq.set_lefttop(b.i[1], lSt.bx.get_bottom())
lSt.lq.set_rightbottom(b.i + 1, math.max(b.l,
lSt.bx.get_bottom() * (1 - lSt.m * .17 * mnMR)))
lSt.lq.set_bgcolor(mnSZC)
lSt.l := true
//-----------------------------------------------------------------------------}