Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.

0
at https://mozilla.org/MPL/2.0/
// © IljaZ

//@version=5
indicator("SA2 Setup", overlay = true)

BigBarfactor = input.float(1)
CXfactor = input.float(1.8)
veryBigBarfactor = input.float(2)
hugeBigBarfactor = input.float(3)

//---Intrabar Strength
BarRange = high - low
IBS = (close - low) / BarRange * 100

//--- Average Bar Range


BarRangeAverage = ta.sma(BarRange, 8)

//--- Bar Direction ---.


// Classify bars based on their direction into only two
// categories,either BL (+1) or BR (-1)

isBL = close > open and IBS >= 50 or close == open and IBS > 50 or close < open and
IBS > 50
isBR = close < open and IBS <= 50 or close == open and IBS < 50 or close > open and
IBS < 50

//---Inside Bar
isInsidebar = high <= high[1] and low >= low[1]

//For outside bar


BLHHdist = high - high[1]
BLLLdist = low - low[1]

BRLLdist = low[1] - low


BRHHdist = high[1] - high
//---Outside Bar
isOB = high > high[1] and low < low[1] or high > high[1] and low == low[1] or high
== high[1] and low < low[1]

//---Breakouts
// Use minimum number of rules to define a breakout:
// 1. A BO is when H (BL case) of a bar goes 1 tick above the
// H of the prior bar
// 2. The bar cannot be an outside bar
isBLBO = high > high[1] and low >= low[1]
isBRBO = low < low[1] and high <= high [1]

//CX bar
isBLCX = BLHHdist > (BLLLdist * CXfactor) and isBL and isBL[1] and isBLBO and not
isInsidebar[1] and not isOB
isBRCX = BRLLdist > (BRHHdist * CXfactor) and isBR and isBR[1] and isBRBO and not
isInsidebar[1] and not isOB

isBigBar = BarRange > (BarRangeAverage * BigBarfactor)


isveryBigBar = BarRange > (BarRangeAverage * veryBigBarfactor)
ishugeBigBar = BarRange > (BarRangeAverage * hugeBigBarfactor)

BLIBS = IBS >= 69


BRIBS = IBS <= 31

//BLsetup = isBigBar and isBL and isBLBO and BLIBS and not isInsidebar
//BRsetup = isBigBar and isBR and isBRBO and BRIBS and not isInsidebar
BOBLsetup = isBLBO and isBL and BLIBS and isBigBar and not isInsidebar
BOBRsetup = isBRBO and isBR and BRIBS and isBigBar and not isInsidebar
BLsetup = BOBLsetup and not BOBLsetup[1]
BRsetup = BOBRsetup and not BOBRsetup[1]

FTBLsetup = isBLBO and isBL and BLsetup[1]


FTBRsetup = isBRBO and isBR and BRsetup[1]

setupcolor = (BLsetup) ? color.rgb(3, 182, 66) : (BRsetup) ? #981b21 : na


barcolor(setupcolor)
FTsetupcolor = (FTBLsetup) ? color.rgb(164, 255, 90) : (FTBRsetup) ? #fa757b : na
barcolor(FTsetupcolor)

CXColor = (isBLCX) ? color.rgb(3, 30, 127) : (isBRCX) ? #4e0017 : na


barcolor(CXColor)

plotcandle(open, high, low, close, bordercolor = isveryBigBar? color.rgb(200, 180,


1) : na, color = color.new(color.blue, 100), wickcolor = isveryBigBar?
color.rgb(200, 180, 1) : na)
plotcandle(open, high, low, close, bordercolor = ishugeBigBar? color.rgb(170, 0, 0)
: na, color = color.new(color.blue, 100), wickcolor = ishugeBigBar? color.rgb(170,
0, 0) : na)

//plotcandle(open, high, low, close, bordercolor = BLsetup or BRsetup? color.yellow


: na, color = color.new(color.blue, 100), wickcolor = BLsetup or BRsetup?
color.yellow : na)

plot(IBS, "IBS", display = display.data_window)


plot(BarRange, "Bar Range", display = display.data_window)
plot(BarRangeAverage, "ABR", display = display.data_window)

//MA line for profit taking x0.5 and x1 ABR from close

BLprofitx1 = close + BarRangeAverage


BRprofitx1 = close - BarRangeAverage
BLprofitx05 = close + (BarRangeAverage/2)
BRprofitx05 = close - (BarRangeAverage/2)

// FTBLsetup? color.green : na
// FTBLsetup? -> is checking if FTBLsetup is true
// if it is true, then do color.green
// if it is NOT true, then do na (nothing)

//You can continue asking for other conditions, like:


// cond1? do1 : cond2? do2 : cond3? do3 : na

plot(BLprofitx1, "BL x1", color = FTBLsetup? color.green : na,


style=plot.style_cross, linewidth = 3)
plot(BRprofitx1, "BR x1", color = FTBRsetup? color.red : na,
style=plot.style_cross, linewidth = 3)
plot(BLprofitx05, "BL x0.5", color = FTBLsetup? color.rgb(76, 175, 112, 45) : na,
style = plot.style_cross, linewidth = 3)
plot(BRprofitx05, "BR x0.5", color = FTBRsetup? color.rgb(255, 82, 82, 43) : na,
style = plot.style_cross, linewidth = 3)

You might also like