Untitled

 avatar
user_6299896
plain_text
7 months ago
48 kB
6
Indexable
Never
//@version=5
indicator("3 Phase", overlay = false)

//volume_ok for usdcad 700, minimum volume to generate candle pattern 
//avgvol for usdcad is below 800, to be in inSession avgvol needs to be under a certain low volume
//ampl for usdcad is 2, if box height is very small, make ampl higher, if box size is quite big, lower ampl
//minimum for lackvol for usdcad is 3000
//minimum for sduvol for usdcad is 1000
//minimum for news for usdcad is 3000
//minimum for volume patterns (cpt1b - cpt5b) for usdcad is 1000
//usdchf 57M volume, 1y , 4.74M, 1M, 0.96
//usdcad 60M volume, 1y, 4.82M, 1M, 1
//audusd 69M volume, 1y, 5.30M, 1M, 1.12
//eurusd 78M, volume, 1y, 5.69M, 1M, 1.24
//usdjpy 101M volume, 1y, 7.30M, 1M, 1.6
//gbpusd 118M volume, 1y, 7.43M, 1M, 1.7
//usdcad 0.0094 
//eurusd 0.0087 
//gbpusd 0.0119
//audusd 0.0079
//usdjpy 1.2700 
//usdchf 0.0077


currentSymbol = syminfo.tickerid
usdCadSymbol = "FX:USDCAD"
eurUsdSymbol = "FX:EURUSD"
usdJpySymbol = "FX:USDJPY"
usdChfSymbol = "FX:USDCHF"
audUsdSymbol = "FX:AUDUSD"
gbpUsdSymbol = "FX:GBPUSD"
usdcad = currentSymbol == usdCadSymbol
eurusd = currentSymbol == eurUsdSymbol
usdjpy = currentSymbol == usdJpySymbol
usdchf = currentSymbol == usdChfSymbol
audusd = currentSymbol == audUsdSymbol
gbpusd = currentSymbol == gbpUsdSymbol

var float dcur = 1
var float pipm = 1

if usdchf == true
    dcur:=0.96
    pipm:=0.82
if usdcad == true
    dcur:=1.00
if audusd == true
    dcur:=1.12
    pipm:=0.84
if eurusd == true
    dcur:=1.24
if usdjpy == true
    dcur:=1.60
    pipm:=90
if gbpusd == true
    dcur:=1.70
    pipm:=1.27

//Definitions

bl_ok = input(false)
enableall = input(false) and (usdcad or usdchf or eurusd or usdjpy or gbpusd or audusd)

volume_ok = volume>(input(700))*dcur
sizze = size.small

box_ok = input(false) or enableall

keylevels_ok = input(false) or enableall
kld_ok = input(false) or enableall
adj = input(0.0001)*pipm
dis = input(40)
day = 86400000

fvg_ok = input(false) or enableall
fvg_det = input(false) or enableall
lookback = input(400)
sens = input(0.0010)

ob_ok = input(false) or enableall
len = input(10)
lookback2 = input(2000)
borline = input(0.0004)
sborline = input(0.0016)

news_ok = input(false) or enableall

risvol_ok = input(false) or enableall
falvol_ok = input(false) or enableall
dist = input(50)
ampl = input(2)

sudIntr_ok = input(false) or enableall

lackvol_ok = input(false) or enableall
sudvol_ok = input(false) or enableall

candlepat_ok = input(false) or enableall
cptper = input(0.85)

voldif_ok = input(false) or enableall
multp=input(5)
color_candles = input(false) or enableall

cp_ok         = input(false) or enableall

bl = input(0.26)
mcs = input(0.67)
pmval = input(0.0)

b61_ok        = cp_ok,        b51_ok        = cp_ok,        b41_ok        = cp_ok,        b31_ok        = cp_ok
r61_ok        = cp_ok,        r51_ok        = cp_ok,        r41_ok        = cp_ok,        r31_ok        = cp_ok
b62_ok        = cp_ok,        b52_ok        = cp_ok,        b42_ok        = cp_ok,        b32_ok        = cp_ok
r62_ok        = cp_ok,        r52_ok        = cp_ok,        r42_ok        = cp_ok,        r32_ok        = cp_ok
b63_ok        = cp_ok,        b53_ok        = cp_ok,        b43_ok        = cp_ok,        b21_ok        = cp_ok
r63_ok        = cp_ok,        r53_ok        = cp_ok,        r43_ok        = cp_ok,        r21_ok        = cp_ok
b64_ok        = cp_ok,        b54_ok        = cp_ok,        b44_ok        = cp_ok
r64_ok        = cp_ok,        r54_ok        = cp_ok,        r44_ok        = cp_ok
b65_ok        = cp_ok,        b55_ok        = cp_ok
r65_ok        = cp_ok,        r55_ok        = cp_ok
b66_ok        = cp_ok
r66_ok        = cp_ok
bhc_ok        = cp_ok
rhc_ok        = cp_ok
tws_ok        = cp_ok
tbs_ok        = cp_ok

//2nd Definitions
c1=close,c2=close[1],c3=close[2],o1=open,o2=open[1],o3=open[2],h1=high,h2=high[1],h3=high[2],l1=low,l2=low[1],l3=low[2]
c4=close[3],c5=close[4],c6=close[5],o4=open[3],o5=open[4],o6=open[5],h4=high[3],h5=high[4],h6=high[5],l4=low[3],l5=low[4],l6=low[5]
vol = volume
avgvol = (volume + volume[1]+ volume[2])/3
atr=ta.atr(14)
atr2=ta.atr(7)
atr3=ta.atr(2)
inSession = ((atr<0.0007*pipm or atr2<0.0007*pipm or atr3<0.0007*pipm) and avgvol<800*dcur) and ((time >= timestamp(year, month, dayofmonth, 12, 0)) or (time <= timestamp(year, month, dayofmonth, 3, 00)))

//Boxes
var float low_val = 0.0
var float high_val = 0.0

startTime = 0
startTime := inSession and not inSession[1] ? time : startTime[1]
endTime = 0
endTime := not inSession and inSession[1] ? time : endTime[1]
if inSession and not inSession[1]
    low_val := low
    high_val := high
if inSession and startTime < timestamp(year, month, dayofmonth, 18, 0) and startTime > (timestamp(year, month, dayofmonth, 12, 00)) and time > timestamp(year, 8, 20, 0, 0)
    if low < low_val
        low_val := low
        low_val
    if high > high_val
        high_val := high
        high_val

//checks if below/above middle line of box
var bool belowLine_b = na
var bool belowLine_r = na
if bl_ok
    belowLine_b := (c1<((high_val + low_val) / 2))
    belowLine_r := (c1>((high_val + low_val) / 2)) 
else
    belowLine_b := true
    belowLine_r := true
boxsize = high_val - low_val

//Key Levels
var float prevhih2 = na
var float prevlol2 = na
var float prevtop2 = na
var float prevbot2 = na
var box res21 = na
var box sup21 = na
var color impcolor = na
var bool shouldPlot6 = na
var bool shouldPlot7 = na
var float hih2 = na
var float lol2 = na
var float top2 = na
var float bot2 = na

bounce_conditions_b(_level) =>
    conb = low < _level+adj*2 and low > _level-adj*2 and kld_ok and (c4>_level and c3>_level and c2>_level and c1>_level) and vol>1000*dcur and belowLine_b
bounce_conditions_r(_level) =>
    conr = high > _level-adj*2 and high < _level+adj*2 and kld_ok and (c4<_level and c3<_level and c2<_level and c1<_level) and vol>1000 and belowLine_r

if keylevels_ok
    hih2 := ta.pivothigh(high, dis, dis)
    lol2 := ta.pivotlow(low, dis, dis)
    top2 := ta.valuewhen(hih2, high[dis], 0)
    bot2 := ta.valuewhen(lol2, low[dis], 0)
    if bar_index == 0
        prevtop2 := top2
    if bar_index == 0
        prevbot2 := bot2
    prevbot2 := bot2
    prevtop2 := top2

    if kld_ok
        var int max_lookback = 500
        bounce_detected_w = false
        bounce_detected_m = false
        bounce_detected_s = false
        for i = 0 to max_lookback
            if not na(top2[i]) and bounce_conditions_b(top2[i]) 
                bounce_detected_w := true
            if not na(bot2[i]) and bounce_conditions_b(bot2[i])
                bounce_detected_w := true

        var int barsSincePattern6 = 0
        shouldPlot6 := bounce_detected_w and (barsSincePattern6 >= 7 or na(barsSincePattern6))
        barsSincePattern6 := shouldPlot6 ? 0 : barsSincePattern6 + 1

        var int max_lookback_r = 500
        bounce_detected_r_w = false
        bounce_detected_r_m = false
        bounce_detected_r_s = false
        for i = 0 to max_lookback_r
            if not na(top2[i]) and bounce_conditions_r(top2[i])
                bounce_detected_r_w := true
            if not na(bot2[i]) and bounce_conditions_r(bot2[i])
                bounce_detected_r_w := true

        var int barsSincePattern7 = 0
        shouldPlot7 := bounce_detected_r_w and (barsSincePattern7 >= 7 or na(barsSincePattern7))
        barsSincePattern7 := shouldPlot7 ? 0 : barsSincePattern7 + 1

//Volume Divergence rising
var bool risvol = na
var bool risvol1 = na
var bool risvol2 = na
var bool risvol3 = na
var bool risvol4 = na
var bool red = na
var bool green = na
if risvol_ok
    risvol1 := vol > ta.highest(vol[1], dist)
    for V = 10 to dist
        for tes = 1 to 10
            risvol4 := (vol[V] > vol[V+tes])
        for am = 1 to (V-1)
            risvol2 := (vol > vol[V-am])
            risvol3 := risvol3 or (vol[V-am] < (0.34 * vol[V]))
    risvol := risvol1 and risvol2 and risvol3 and risvol4 and not risvol[1] and not risvol[2] and not risvol[2] and not risvol[3] and not risvol[4] and not risvol[5] and not risvol[6] and not risvol[7] and not risvol[8] and not risvol[9] and not risvol[10]
    red := risvol and close<open[2] and belowLine_r
    green := risvol and close>open[2] and belowLine_b

//Volume falling
var bool redr = na
var bool greenr = na
if falvol_ok
    falvol1 = vol*ampl < ta.highest(vol, 15)
    falvol = falvol1 and falvol_ok and (time == timestamp(year, month, dayofmonth, 0, 30) or time == timestamp(year, month, dayofmonth, 7, 0) or time == timestamp(year, month, dayofmonth, 13, 0))
    redr := falvol and close>(((high_val + low_val)/2)+boxsize*ampl)
    greenr := falvol and close<(((high_val + low_val)/2)-boxsize*ampl)

//fvg
var bool shouldPlot8 = na
var bool shouldPlot9 = na
bounce_conditions_bb(_level) =>
    conbb = low < _level and fvg_det
bounce_conditions_bb2(_level) =>
    conbb = low > _level and fvg_det

bounce_conditions_rr(_level) =>
    conrr = high > _level and fvg_det
bounce_conditions_rr2(_level) =>
    conrr = high < _level and fvg_det

if fvg_ok
    fvg1 = (c2-o2>sens*pipm) or (o2-c2>sens*pipm)
    fvg2 = (h3<l1) or (l3>h1) 
    fvg = fvg1 and fvg2
    var int density = na
    if (last_bar_index-bar_index)>300
        density:=90
    if (last_bar_index-bar_index)>200 and (last_bar_index-bar_index)<300
        density:=70
    if (last_bar_index-bar_index)>100 and (last_bar_index-bar_index)<200
        density:=50
    if (last_bar_index-bar_index)<100
        density:=30

    cond_b = fvg[0] and close[1]>open[1] and bar_index>last_bar_index-lookback and l1-h3>0.0002*pipm
    cond_r = fvg[0] and open[1]>close[1] and bar_index>last_bar_index-lookback and l3-h1>0.0002*pipm
    
    var int max_lookbackk = lookback
    bounce_det = false
    for i = 0 to max_lookbackk
        if not na(low[i]) and bounce_conditions_bb(low[i]) and cond_b[i] and not na(high[2+i]) and bounce_conditions_bb2(high[2+i])
            bounce_det := true
    var int barsSincePattern8 = 0
    shouldPlot8 := bounce_det and (barsSincePattern8 >= 5 or na(barsSincePattern8))
    barsSincePattern8 := shouldPlot8 ? 0 : barsSincePattern8 + 1

    bounce_det2 = false
    for i = 0 to max_lookbackk
        if not na(high[i]) and bounce_conditions_rr(high[i]) and cond_r[i] and not na(low[2+i]) and bounce_conditions_rr2(low[2+i])
            bounce_det2 := true
    var int barsSincePattern9 = 0
    shouldPlot9 := bounce_det2 and (barsSincePattern9 >= 5 or na(barsSincePattern9))
    barsSincePattern9 := shouldPlot9 ? 0 : barsSincePattern9 + 1

//Order Blocks
bounce_conditions_rr3(_level) =>
    conr = high > _level
bounce_conditions_rr4(_level) =>
    conr = high < _level
bounce_conditions_bb3(_level) =>
    conb = low < _level
bounce_conditions_bb4(_level) =>
    conb = low > _level

var bool shouldPlot10 = na
var bool shouldPlot11 = na

if ob_ok
    left_highest = ta.highest(vol[len+1], len)
    right_highest = ta.highest(vol, len)
    volhi = vol[len] > left_highest and vol[len] > right_highest
    hi = high[len] == ta.pivothigh(len,len)
    lo = low[len] == ta.pivotlow(len,len)

    var int density2 = na
    if (last_bar_index-bar_index)>300
        density2:=90
    if (last_bar_index-bar_index)>200 and (last_bar_index-bar_index)<300
        density2:=70
    if (last_bar_index-bar_index)>100 and (last_bar_index-bar_index)<200
        density2:=50
    if (last_bar_index-bar_index)<100
        density2:=30

    var float bobsize = na
    if close[len]-low[len]<borline
        bobsize := high[len]
    else
        bobsize := close[len]
    var float robsize = na
    if high[len]-close[len]<borline
        robsize := low[len]
    else
        robsize := close[len]
    var float bbobsize = na
    if close[len]-low[len]>sborline
        bbobsize := (close[len]+low[len])/2
    else
        bbobsize := low[len]
    var float rrobsize = na
    if high[len]-close[len]>sborline
        rrobsize := (high[len]+close[len])/2
    else
        rrobsize := high[len]

    barr=900000
    cond_b2 = lo and volhi and bar_index>last_bar_index-lookback2
    cond_r2 = hi and volhi and bar_index>last_bar_index-lookback2
    var box bob = na
    var box rob = na

    var int max_lookback2 = lookback2
    bounce_det3 = false
    for i = 0 to max_lookback2
        if not na(bobsize[i]) and bounce_conditions_bb3(bobsize[i]) and cond_b2[i] and bounce_conditions_bb4(bbobsize[i]) and not na(bbobsize[i]) and not (close[i]<bbobsize[i]) and (close[5]>close)
            bounce_det3 := true

    bounce_det4 = false
    for i = 0 to max_lookback2
        if not na(robsize[i]) and bounce_conditions_rr3(robsize[i]) and cond_r2[i] and bounce_conditions_rr4(rrobsize[i]) and not na(rrobsize[i]) and not (close[i]>robsize[i]) and (close[5]<close)
            bounce_det4 := true

    var int barsSincePattern10 = 0
    shouldPlot10 := bounce_det3 and (barsSincePattern10 >= 10 or na(barsSincePattern10))
    barsSincePattern10 := shouldPlot10 ? 0 : barsSincePattern10 + 1
    var int barsSincePattern11 = 0
    shouldPlot11 := bounce_det4 and (barsSincePattern11 >= 10 or na(barsSincePattern11))
    barsSincePattern11 := shouldPlot11 ? 0 : barsSincePattern11 + 1

shouldPlot62 = shouldPlot6 and vol>1500*dcur and c1-l1>0.0008*pipm and vol<3000
shouldPlot63 = shouldPlot6 and vol>3000*dcur and c1-l1>0.0012*pipm
shouldPlot61 = shouldPlot6 and not shouldPlot62 and not shouldPlot63
shouldPlot72 = shouldPlot7 and vol>1500*dcur and h1-c1>0.0008*pipm and vol<3000
shouldPlot73 = shouldPlot7 and vol>3000*dcur and h1-c1>0.0012*pipm
shouldPlot71 = shouldPlot7 and not shouldPlot72 and not shouldPlot73
shouldPlot81 = shouldPlot8 and vol<1500*dcur
shouldPlot82 = shouldPlot8 and vol>1500*dcur
shouldPlot83 = shouldPlot8 and vol>1500*dcur and ((o1-l1>(h1-l1)*0.5 and c1>o1) or (c1-l1>(h1-l1)*0.5 and o1>c1))
shouldPlot91 = shouldPlot9 and vol<1500*dcur
shouldPlot92 = shouldPlot9 and vol>1500*dcur
shouldPlot93 = shouldPlot9 and vol>1500*dcur and ((h1-c1>(h1-l1)*0.5 and c1>o1) or (h1-o1>(h1-l1)*0.5 and o1>c1))
shouldPlot101 = shouldPlot10 and vol<1500*dcur
shouldPlot103 = shouldPlot10 and vol>1500*dcur and ((o1-l1>(h1-l1)*0.5 and c1>o1) or (c1-l1>(h1-l1)*0.5 and o1>c1))
shouldPlot102 = shouldPlot10 and vol>1500*dcur and not shouldPlot103
shouldPlot111 = shouldPlot11 and vol<1500*dcur
shouldPlot113 = shouldPlot11 and vol>1500*dcur and ((h1-c1>(h1-l1)*0.5 and c1>o1) or (h1-o1>(h1-l1)*0.5 and o1>c1))
shouldPlot112 = shouldPlot11 and vol>1500*dcur and not shouldPlot113

//Sudden Lack of Volume
var bool lackvol1b = na
var bool lackvol2b = na
var bool lackvol3b = na
var bool lackvol1 = na
var bool lackvol2 = na
var bool lackvol3 = na

if lackvol_ok
    lackvol1b := c1>o1 and ((vol[1]*0.80)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_r
    lackvol2b := c1>o1 and ((vol[1]*0.75)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_r
    lackvol3b := c1>o1 and ((vol[1]*0.67)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_r
    lackvol1 := o1>c1 and ((vol[1]*0.80)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_b
    lackvol2 := o1>c1 and ((vol[1]*0.75)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_b
    lackvol3 := o1>c1 and ((vol[1]*0.67)>vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and lackvol_ok and vol[1]>3000*dcur and belowLine_b
//Sudden Volume
var bool sudvol1b = na
var bool sudvol2b = na
var bool sudvol3b = na
var bool sudvol1 = na
var bool sudvol2 = na
var bool sudvol3 = na

if sudvol_ok
    sudvol1b := c1>o1 and ((vol[1]*1.4)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_b
    sudvol2b := c1>o1 and ((vol[1]*1.7)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_b
    sudvol3b := c1>o1 and ((vol[1]*2.0)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_b
    sudvol1 := o1>c1 and ((vol[1]*1.4)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_r
    sudvol2 := o1>c1 and ((vol[1]*1.7)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_r
    sudvol3 := o1>c1 and ((vol[1]*2.0)<vol) and not ((time >= timestamp(year, month, dayofmonth, 12, 0))) and sudvol_ok and vol[1]>1000*dcur and belowLine_r
si_lo_ab = location.abovebar
si_lo_bb = location.belowbar


//Sudden interest
var bool sig1b = na
var bool sig1r = na
if sudIntr_ok
    sig1b := (c1-o1)>atr*1.5 and belowLine_b 
    sig1r := (o1-c1)>atr*1.5 and belowLine_r

//News
var bool news = na
if news_ok
    news := (vol>3000*dcur) and (h1-l1>0.0025*pipm) and (vol[1]<vol*0.5) and news_ok


//Volume Patterns
var bool cpt1b = na
var bool cpt2b = na
var bool cpt3b = na
var bool cpt4b = na
var bool cpt5b = na
var bool cpt1r = na
var bool cpt2r = na
var bool cpt3r = na
var bool cpt4r = na
var bool cpt5r = na

if candlepat_ok
    cpt1b1 = vol[2]>1000*dcur and c3>o3
    cpt1b2 = vol[1]<vol[2]*cptper and c2<o2
    cpt1b3 = vol>vol[2] and c1>o1
    cpt1b := cpt1b1 and cpt1b2 and cpt1b3 and belowLine_b
    cpt1r1 = vol[2]>1000*dcur and c3<o3
    cpt1r2 = vol[1]<vol[2]*cptper and c2>o2
    cpt1r3 = vol>vol[2] and c1<o1
    cpt1r := cpt1r1 and cpt1r2 and cpt1r3 and belowLine_r
    cpt2b1 = vol[3]>1000*dcur and c4>o4
    cpt2b2 = vol[2]<vol[3]*cptper and c3<o3
    cpt2b3 = vol[1]<vol[3]*cptper and c2<o2
    cpt2b4 = vol>vol[3] and c1>o1
    cpt2b := cpt2b1 and cpt2b2 and cpt2b3 and cpt2b4 and belowLine_b
    cpt2r1 = vol[3]>1000*dcur and c4<o4
    cpt2r2 = vol[2]<vol[3]*cptper and c3>o3
    cpt2r3 = vol[1]<vol[3]*cptper and c2>o2
    cpt2r4 = vol>vol[3] and c1<o1
    cpt2r := cpt2r1 and cpt2r2 and cpt2r3 and cpt2r4 and belowLine_r
    cpt3b1 = vol[4]>1000*dcur and c5>o5
    cpt3b2 = vol[3]<vol[4]*cptper and c4<o4
    cpt3b3 = vol[2]<vol[4]*cptper and c3<o3
    cpt3b4 = vol[1]<vol[4]*cptper and c2<o2
    cpt3b5 = vol>vol[4] and c1>o1
    cpt3b := cpt3b1 and cpt3b2 and cpt3b3 and cpt3b4 and cpt3b5 and belowLine_b
    cpt3r1 = vol[4]>1000*dcur and c5<o5
    cpt3r2 = vol[3]<vol[4]*cptper and c4>o4
    cpt3r3 = vol[2]<vol[4]*cptper and c3>o3
    cpt3r4 = vol[1]<vol[4]*cptper and c2>o2
    cpt3r5 = vol>vol[4] and c1<o1
    cpt3r := cpt3r1 and cpt3r2 and cpt3r3 and cpt3r4 and cpt3r5 and belowLine_r
    cpt4b0 = vol[2]>vol[3]
    cpt4b1 = c3<o3 
    cpt4b2 = vol[1]>vol[2] and c2<o2
    cpt4b3 = vol>vol[1] and c1>o1
    cpt4b4 = (time >= timestamp(year, month, dayofmonth, 0, 30) and time <= timestamp(year, month, dayofmonth, 3, 15)) or (time >= timestamp(year, month, dayofmonth, 6, 0) and time <= timestamp(year, month, dayofmonth, 10, 15))
    cpt4b := cpt4b1 and cpt4b2 and cpt4b3 and cpt4b4 and cpt4b0 and belowLine_b
    cpt4r0 = vol[2]>vol[3]
    cpt4r1 = c3>o3 
    cpt4r2 = vol[1]>vol[2] and c2>o2
    cpt4r3 = vol>vol[1] and c1<o1
    cpt4r4 = (time >= timestamp(year, month, dayofmonth, 0, 30) and time <= timestamp(year, month, dayofmonth, 3, 15)) or (time >= timestamp(year, month, dayofmonth, 6, 0) and time <= timestamp(year, month, dayofmonth, 10, 15))
    cpt4r := cpt4r1 and cpt4r2 and cpt4r3 and cpt4r4 and cpt4r0 and belowLine_r
    cpt5b1 = c4<o4
    cpt5b2 = (vol[2]>vol[3]*1.34 or vol[2]>vol[1]*1.34)and c3>o3
    cpt5b3 = c2<o2
    cpt5b4 = (vol>vol[3]*1.34 or vol>vol[1]*1.34) and vol>vol[2] and c1>o1 and vol>1000*dcur and (vol[1]+vol[3]<vol+vol[2])
    cpt5b := cpt5b1 and cpt5b2 and cpt5b3 and cpt5b4 and belowLine_b
    cpt5r1 = c4>o4
    cpt5r2 = (vol[2]>vol[3]*1.34 or vol[2]>vol[1]*1.34) and c3<o3
    cpt5r3 = c2>o2
    cpt5r4 = (vol>vol[3]*1.34 or vol>vol[1]*1.34) and vol>vol[2] and c1<o1 and vol>1000*dcur and (vol[1]+vol[3]<vol+vol[2])
    cpt5r := cpt5r1 and cpt5r2 and cpt5r3 and cpt5r4 and belowLine_r

//Volume Differences
var bool vob1s = na
var bool vor1s = na
var bool vob1m = na
var bool vor1m = na
var bool vob1w = na
var bool vor1w = na
if voldif_ok
    vo1b = c1>o1 ? vol : 0
    vo1r = o1>c1 ? vol : 0
    vo2b = c2>o2 ? vol[1] : 0
    vo2r = o2>c2 ? vol[1] : 0
    vo3b = c3>o3 ? vol[2] : 0
    vo3r = o3>c3 ? vol[2] : 0
    vo4b = c4>o4 ? vol[3] : 0
    vo4r = o4>c4 ? vol[3] : 0
    vo5b = c5>o5 ? vol[4] : 0
    vo5r = o5>c5 ? vol[4] : 0
    vo6b = c6>o6 ? vol[5] : 0
    vo6r = o6>c6 ? vol[5] : 0
    vo7b = close[6]>open[6] ? vol[6] : 0
    vo7r = open[6]>close[6] ? vol[6] : 0
    vo8b = close[7]>open[7] ? vol[7] : 0
    vo8r = open[7]>close[7] ? vol[7] : 0
    vo9b = close[8]>open[8] ? vol[8] : 0
    vo9r = open[8]>close[8] ? vol[8] : 0
    vo10b = close[9]>open[9] ? vol[9] : 0
    vo10r = open[9]>close[9] ? vol[9] : 0
    vo11b = close[10]>open[10] ? vol[10] : 0
    vo11r = open[10]>close[10] ? vol[10] : 0
    vo12b = close[11]>open[11] ? vol[11] : 0
    vo12r = open[11]>close[11] ? vol[11] : 0
    vo13b = close[12]>open[12] ? vol[12] : 0
    vo13r = open[12]>close[12] ? vol[12] : 0
    vo14b = close[13]>open[13] ? vol[13] : 0
    vo14r = open[13]>close[13] ? vol[13] : 0

    vobb = vo1b+vo2b+vo3b+vo4b+vo5b+vo6b+vo7b+vo8b+vo9b+vo10b+vo11b+vo12b+vo13b+vo14b
    vorr = vo1r+vo2r+vo3r+vo4r+vo5r+vo6r+vo7r+vo8r+vo9r+vo10r+vo11r+vo12r+vo13r+vo14r

    difb = (vorr-vobb)
    vob = vorr>vobb and voldif_ok and belowLine_b and ((difb+difb[1])*multp<(difb[2]+difb[3]))
    var int barsSincePattern2 = 0
    vob1 = vob and (barsSincePattern2 >= 5 or na(barsSincePattern2))
    barsSincePattern2 := vob1 ? 0 : barsSincePattern2 + 1

    difr = (vobb-vorr)
    vor = vobb>vorr and voldif_ok and belowLine_r and ((difr+difr[1])*multp<(difr[2]+difr[3]))
    var int barsSincePattern3 = 0
    vor1 = vor and (barsSincePattern3 >= 5 or na(barsSincePattern3))
    barsSincePattern3 := vor1 ? 0 : barsSincePattern3 + 1

    if vob1 and vol>2400*dcur
        vob1s:=true
    else
        vob1s:=false
    if vob1 and vol>900*dcur and vol<2400*dcur
        vob1m:=true
    else
        vob1m:=false
    if vob1 and vol<900*dcur
        vob1w:=true
    else
        vob1w:=false
    if vor1 and vol>2400*dcur
        vor1s:=true
    else
        vor1s:=false
    if vor1 and vol>900*dcur and vol<2400*dcur
        vor1m:=true
    else
        vor1m:=false
    if vor1 and vol<900*dcur
        vor1w:=true
    else
        vor1w:=false

//Color candles
var float dif2 = na

if color_candles
    vo1b = c1>o1 ? vol : 0
    vo1r = o1>c1 ? vol : 0
    vo2b = c2>o2 ? vol[1] : 0
    vo2r = o2>c2 ? vol[1] : 0
    vo3b = c3>o3 ? vol[2] : 0
    vo3r = o3>c3 ? vol[2] : 0
    vo4b = c4>o4 ? vol[3] : 0
    vo4r = o4>c4 ? vol[3] : 0
    vo5b = c5>o5 ? vol[4] : 0
    vo5r = o5>c5 ? vol[4] : 0
    vo6b = c6>o6 ? vol[5] : 0
    vo6r = o6>c6 ? vol[5] : 0
    vo7b = close[6]>open[6] ? vol[6] : 0
    vo7r = open[6]>close[6] ? vol[6] : 0
    vo8b = close[7]>open[7] ? vol[7] : 0
    vo8r = open[7]>close[7] ? vol[7] : 0
    vo9b = close[8]>open[8] ? vol[8] : 0
    vo9r = open[8]>close[8] ? vol[8] : 0
    vo10b = close[9]>open[9] ? vol[9] : 0
    vo10r = open[9]>close[9] ? vol[9] : 0
    vo11b = close[10]>open[10] ? vol[10] : 0
    vo11r = open[10]>close[10] ? vol[10] : 0
    vo12b = close[11]>open[11] ? vol[11] : 0
    vo12r = open[11]>close[11] ? vol[11] : 0
    vo13b = close[12]>open[12] ? vol[12] : 0
    vo13r = open[12]>close[12] ? vol[12] : 0
    vo14b = close[13]>open[13] ? vol[13] : 0
    vo14r = open[13]>close[13] ? vol[13] : 0
    vobb1 = (vo1b+vo2b+vo3b+vo4b+vo5b+vo6b+vo7b+vo8b+vo9b+vo10b+vo11b+vo12b+vo13b+vo14b)/14
    vorr1 = (vo1r+vo2r+vo3r+vo4r+vo5r+vo6r+vo7r+vo8r+vo9r+vo10r+vo11r+vo12r+vo13r+vo14r)/14
    dif1 = vobb1-vorr1
    dif2 := (dif1+dif1[1]+dif1[2]+dif1[3]+dif1[4]+dif1[5]+dif1[6])/7

//Candle Patterns
var bool b61 = na
var bool b62 = na
var bool b63 = na
var bool b64 = na
var bool b65 = na
var bool b66 = na
var bool b51 = na
var bool b52 = na
var bool b53 = na
var bool b54 = na
var bool b55 = na
var bool b41 = na
var bool b42 = na
var bool b43 = na
var bool b44 = na
var bool b31 = na
var bool b32 = na
var bool b21 = na
var bool bhc = na
var bool shouldPlot1 = na
var bool r61 = na
var bool r62 = na
var bool r63 = na
var bool r64 = na
var bool r65 = na
var bool r66 = na
var bool r51 = na
var bool r52 = na
var bool r53 = na
var bool r54 = na
var bool r55 = na
var bool r41 = na
var bool r42 = na
var bool r43 = na
var bool r44 = na
var bool r31 = na
var bool r32 = na
var bool r21 = na
var bool rhc = na
var bool shouldPlot = na

if cp_ok
    tws3 = (c3>o3) and ((c3-o3)>bl*atr)
    tws2 = (c2>o2) and ((c2-o2)>bl*atr) and (c2>=h3)
    tws1 = (c1>o1) and ((c1-o1)>bl*atr) and (c1>=h2)
    tws = tws1 and tws2 and tws3 and tws_ok and volume_ok and belowLine_b
    var int barsSincePattern1 = 0
    shouldPlot1 := tws and (barsSincePattern1 >= 5 or na(barsSincePattern1))
    barsSincePattern1 := shouldPlot1 ? 0 : barsSincePattern1 + 1
    tbs3 = (o3>c3) and ((o3-c3)>bl*atr)
    tbs2 = (o2>c2) and ((o2-c2)>bl*atr) and (c2<=l3)
    tbs1 = (o1>c1) and ((o1-c1)>bl*atr) and (c1<=l2)
    tbs = tbs1 and tbs2 and tbs3 and tbs_ok and volume_ok and belowLine_r
    var int barsSincePattern = 0
    shouldPlot := tbs and (barsSincePattern >= 5 or na(barsSincePattern))
    barsSincePattern := shouldPlot ? 0 : barsSincePattern + 1
    bhc1 = ((c1>=o1) and ((h1-o1)<((h1-l1)*0.382))) or ((o1>c1) and ((h1-c1)<((h1-l1)*0.382)) and (((h1-o1)>=(o1-c1)) or ((h1-c1)<(h1-l1)*0.25))) and (h1-l1)>atr
    bhc := bhc1 and volume_ok and bhc_ok and belowLine_b
    rhc1 = ((o1>=c1) and ((o1-l1)<((h1-l1)*0.382))) or ((c1>o1) and ((c1-l1)<((h1-l1)*0.382)) and (((o1-l1)>=(c1-o1)) or ((c1-l1)<(h1-l1)*0.25))) and (h1-l1)>atr
    rhc := rhc1 and volume_ok and rhc_ok and belowLine_r
    b616 = (o6>c6)
    b615 = (o5>c5)
    b614 = ((o6-c6)>(mcs*atr)and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o4-c4)>(bl*atr))and((o6-c6)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o5-c5)>(bl*atr))and((o6-c6)>(bl*atr)))
    b613 = ((c3-o3)>(bl*atr))
    b612 = ((c2-o2)>(bl*atr))
    b611 = (c1>o6-(o6-c6)*pmval)and(((c1-o1)>(c2-o2))or((c1-o1)>(c3-o3)))
    b61 := b616 and b615 and b614 and b613 and b612 and b611 and volume_ok and b61_ok and belowLine_b
    r616 = (c6>o6)
    r615 = (c5>o5)
    r614 = ((c6-o6)>(mcs*atr)and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c4-o4)>(bl*atr))and((c6-o6)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c5-o5)>(bl*atr))and((c6-o6)>(bl*atr)))
    r613 = ((o3-c3)>(bl*atr))
    r612 = ((o2-c2)>(bl*atr))
    r611 = (c1<o6+(c6-o6)*pmval)and(((o1-c1)>(o2-c2))or((o1-c1)>(o3-c3)))
    r61 := r616 and r615 and r614 and r613 and r612 and r611 and volume_ok and r61_ok and belowLine_r
    b626 = (o6>c6)
    b625 = (((o6-c6)>(mcs*atr))and((o5-c5)>(bl*atr))) or (((o5-c5)>(mcs*atr))and((o6-c6)>(bl*atr))) 
    b624 = (((c4-o4)<(bl*atr))and((c4-o4)>(0)))or(((o4-c4)<(bl*atr))and((o4-c4)>(0)))
    b623 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b622 = ((c2-o2)>(bl*atr))
    b621 = (c1>o6-(o6-c6)*pmval)and(((c1-o1)>(c2-o2)))
    b62 := b626 and b625 and b624 and b623 and b622 and b621 and volume_ok and b62_ok and belowLine_b
    r626 = (c6>o6)
    r625 = (((c6-o6)>(mcs*atr))and((c5-o5)>(bl*atr))) or (((c5-o5)>(mcs*atr))and((c6-o6)>(bl*atr))) 
    r624 = (((c4-o4)<(bl*atr))and((c4-o4)>(0)))or(((o4-c4)<(bl*atr))and((o4-c4)>(0)))
    r623 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r622 = ((o2-c2)>(bl*atr))
    r621 = (c1<o6+(c6-o6)*pmval)and(((o1-c1)>(o2-c2)))
    r62 := r626 and r625 and r624 and r623 and r622 and r621 and volume_ok and r62_ok and belowLine_r
    b636 = (o6>c6)
    b635 = (o5>c5)
    b634 = ((o6-c6)>(mcs*atr)and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o4-c4)>(bl*atr))and((o6-c6)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o5-c5)>(bl*atr))and((o6-c6)>(bl*atr)))
    b633 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b632 = ((c2-o2)>(bl*atr))
    b631 = (c1>o6-(o6-c6)*pmval)and(((c1-o1)>(c2-o2)))
    b63 := b636 and b635 and b634 and b633 and b632 and b631 and volume_ok and b63_ok and belowLine_b
    r636 = (c6>o6)
    r635 = (c5>o5)
    r634 = ((c6-o6)>(mcs*atr)and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c4-o4)>(bl*atr))and((c6-o6)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c5-o5)>(bl*atr))and((c6-o6)>(bl*atr)))
    r633 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r632 = ((o2-c2)>(bl*atr))
    r631 = (c1<o6+(c6-o6)*pmval)and(((o1-c1)>(o2-c2)))
    r63 := r636 and r635 and r634 and r633 and r632 and r631 and volume_ok and r63_ok and belowLine_r
    b646 = (o6>c6)
    b645 = (o5>c5)
    b644 = (o4>c4)
    b643 = ((o6-c6)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o6-c6)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o6-c6)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o6-c6)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr)))
    b642 = ((c2-o2)>(bl*atr))
    b641 = (c1>o6-(o6-c6)*pmval)and(((c1-o1)>(c2-o2)))
    b64 := b646 and b645 and b644 and b643 and b642 and b641 and volume_ok and b64_ok and belowLine_b
    r646 = (c6>o6)
    r645 = (c5>o5)
    r644 = (c4>o4)
    r643 = ((c6-o6)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c6-o6)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c6-o6)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c6-o6)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr)))
    r642 = ((o2-c2)>(bl*atr))
    r641 = (c1<o6+(c6-o6)*pmval)and(((o1-c1)>(o2-c2)))
    r64 := r646 and r645 and r644 and r643 and r642 and r641 and volume_ok and r64_ok and belowLine_r
    b656 = (o6>c6)
    b655 = (o5>c5)
    b654 = ((o6-c6)>(mcs*atr)and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o4-c4)>(bl*atr))and((o6-c6)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o5-c5)>(bl*atr))and((o6-c6)>(bl*atr)))
    b653 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b652 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b651 = (c1>o6-(o6-c6)*pmval)
    b65 := b656 and b655 and b654 and b653 and b652 and b651 and volume_ok and b65_ok and belowLine_b
    r656 = (c6>o6)
    r655 = (c5>o5)
    r654 = ((c6-o6)>(mcs*atr)and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c4-o4)>(bl*atr))and((c6-o6)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c5-o5)>(bl*atr))and((c6-o6)>(bl*atr)))
    r653 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r652 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r651 = (c1<o6+(c6-o6)*pmval)
    r65 := r656 and r655 and r654 and r653 and r652 and r651 and volume_ok and r65_ok and belowLine_r
    b666 = (o6>c6)
    b665 = (o5>c5)
    b664 = (o4>c4)
    b663 = ((o6-c6)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o6-c6)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o6-c6)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o6-c6)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr)))
    b662 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b661 = (c1>o6-(o6-c6)*pmval)
    b66 := b666 and b665 and b664 and b663 and b662 and b661 and volume_ok and b66_ok and belowLine_b
    r666 = (c6>o6)
    r665 = (c5>o5)
    r664 = (c4>o4)
    r663 = ((c6-o6)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c6-o6)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c6-o6)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c6-o6)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr)))
    r662 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r661 = (c1<o6+(c6-o6)*pmval)
    r66 := r666 and r665 and r664 and r663 and r662 and r661 and volume_ok and r66_ok and belowLine_r
    b515 = (o5>c5)
    b514 = (o4>c4)
    b513 = ((o5-c5)>(mcs*atr)and((o4-c4)>(bl*atr))and((o3-c3)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o5-c5)>(bl*atr))and((o4-c4)>(bl*atr)))
    b512 = ((c2-o2)>(bl*atr))
    b511 = (c1>o5-(o5-c5)*pmval)and((c1-o1)>(c2-o2))
    b51 :=  b515 and b514 and b513 and b512 and b511 and volume_ok and b51_ok and belowLine_b
    r515 = (c5>o5)
    r514 = (c4>o4)
    r513 = ((c5-o5)>(mcs*atr)and((c4-o4)>(bl*atr))and((c3-o3)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c5-o5)>(bl*atr))and((c4-o4)>(bl*atr)))
    r512 = ((o2-c2)>(bl*atr))
    r511 = (c1<o5+(c5-o5)*pmval)and((o1-c1)>(o2-c2))
    r51 :=  r515 and r514 and r513 and r512 and r511 and volume_ok and r51_ok and belowLine_r
    b525 = (o5>c5)
    b524 = (((o5-c5)>(mcs*atr))and((o4-c4)>(bl*atr))) or (((o4-c4)>(mcs*atr))and((o5-c5)>(bl*atr))) 
    b523 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b522 = ((c2-o2)>(bl*atr))
    b521 = (c1>o5-(o5-c5)*pmval)and((c1-o1)>(c2-o2))
    b52 :=  b525 and b524 and b523 and b522 and b521 and volume_ok and b52_ok and belowLine_b
    r525 = (c5>o5)
    r524 = (((c4-o4)>(mcs*atr))and((c5-o5)>(bl*atr))) or (((c4-o4)>(mcs*atr))and((c5-o5)>(bl*atr))) 
    r523 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r522 = ((o2-c2)>(bl*atr))
    r521 = (c1<o5+(c5-o5)*pmval)and(((o1-c1)>(o2-c2)))
    r52 :=  r525 and r524 and r523 and r522 and r521 and volume_ok and r52_ok and belowLine_r
    b535 = (o5>c5)
    b534 = (((o5-c5)>(mcs*atr))and((o4-c4)>(bl*atr))) or (((o4-c4)>(mcs*atr))and((o5-c5)>(bl*atr))) 
    b533 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b532 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b531 = (c1>o5-(o5-c5)*pmval)
    b53 :=  b535 and b534 and b533 and b532 and b531 and volume_ok and b53_ok and belowLine_b
    r535 = (c5>o5)
    r534 = (((c4-o4)>(mcs*atr))and((c5-o5)>(bl*atr))) or (((c5-o5)>(mcs*atr))and((c4-o4)>(bl*atr))) 
    r533 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r532 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r531 = (c1<o5+(c5-o5)*pmval)
    r53 :=  r535 and r534 and r533 and r532 and r531 and volume_ok and r53_ok and belowLine_r
    b545 = (o5>c5)
    b544 = (o4>c4)
    b543 = ((o5-c5)>(mcs*atr)and((o4-c4)>(bl*atr))and((o3-c3)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o5-c5)>(bl*atr))and((o4-c4)>(bl*atr)))
    b542 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b541 = (c1>o5-(o5-c5)*pmval)
    b54 :=  b545 and b544 and b543 and b542 and b541 and volume_ok and b54_ok and belowLine_b
    r545 = (c5>o5)
    r544 = (c4>o4)
    r543 = ((c5-o5)>(mcs*atr)and((c4-o4)>(bl*atr))and((c3-o3)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c5-o5)>(bl*atr))and((c4-o4)>(bl*atr)))
    r542 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r541 = (c1<o5+(c5-o5)*pmval)
    r54 :=  r545 and r544 and r543 and r542 and r541 and volume_ok and r54_ok and belowLine_r
    b555 = (o5>c5)
    b554 = (o4>c4)
    b553 = (o3>c3)
    b552 = ((o2-c2)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o5-c5)>(mcs*atr)and((o3-c3)>(bl*atr))and((o4-c4)>(bl*atr))and((o2-c2)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o2-c2)>(bl*atr))and((o5-c5)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o2-c2)>(bl*atr))and((o4-c4)>(bl*atr))and((o5-c5)>(bl*atr)))
    b551 = (c1>o5-(o5-c5)*pmval)
    b55 :=  b555 and b554 and b553 and b552 and b551 and volume_ok and b55_ok and belowLine_b
    r555 = (c5>o5)
    r554 = (c4>o4)
    r553 = (c3>o3)
    r552 = ((c2-o2)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c5-o5)>(mcs*atr)and((c3-o3)>(bl*atr))and((c4-o4)>(bl*atr))and((c2-o2)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c2-o2)>(bl*atr))and((c5-o5)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c2-o2)>(bl*atr))and((c4-o4)>(bl*atr))and((c5-o5)>(bl*atr)))
    r551 = (c1<o5+(c5-o5)*pmval)
    r55 :=  r555 and r554 and r553 and r552 and r551 and volume_ok and r55_ok and belowLine_r
    b414 = (o4>c4)
    b413 = (((o3-c3)>(mcs*atr))and((o4-c4)>(bl*atr))) or (((o4-c4)>(mcs*atr))and((o3-c3)>(bl*atr))) 
    b412 = ((c2-o2)>(bl*atr))
    b411 = (c1>o4-(o4-c4)*pmval)and((c1-o1)>(c2-o2))
    b41 :=  b414 and b413 and b412 and b411 and volume_ok and b41_ok and belowLine_b
    r414 = (c4>o4)
    r413 = (((c4-o4)>(mcs*atr))and((c3-o3)>(bl*atr))) or (((c4-o4)>(mcs*atr))and((c3-o3)>(bl*atr))) 
    r412 = ((o2-c2)>(bl*atr))
    r411 = (c1<o4+(c4-o4)*pmval)and((o1-c1)>(o2-c2))
    r41 :=  r414 and r413 and r412 and r411 and volume_ok and r41_ok and belowLine_r
    b424 = ((o4-c4)>(mcs*atr))
    b423 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    b422 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b421 = (c1>o4-(o4-c4)*pmval)
    b42 :=  b424 and b423 and b422 and b421 and volume_ok and b42_ok and belowLine_b
    r424 = ((c4-o4)>(mcs*atr))
    r423 = (((c3-o3)<(bl*atr))and((c3-o3)>(0)))or(((o3-c3)<(bl*atr))and((o3-c3)>(0)))
    r422 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r421 = (c1<o4+(c4-o4)*pmval)
    r42 :=  r424 and r423 and r422 and r421 and volume_ok and r42_ok and belowLine_r
    b434 = (o4>c4)
    b433 = (((o3-c3)>(mcs*atr))and((o4-c4)>(bl*atr))) or (((o4-c4)>(mcs*atr))and((o3-c3)>(bl*atr))) 
    b432 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    b431 = (c1>o4-(o4-c4)*pmval)
    b43 :=  b434 and b433 and b432 and b431 and volume_ok and b43_ok and belowLine_b
    r434 = (c4>o4)
    r433 = (((c4-o4)>(mcs*atr))and((c3-o3)>(bl*atr))) or (((c4-o4)>(mcs*atr))and((c3-o3)>(bl*atr))) 
    r432 = (((c2-o2)<(bl*atr))and((c2-o2)>(0)))or(((o2-c2)<(bl*atr))and((o2-c2)>(0)))
    r431 = (c1<o4+(c4-o4)*pmval)
    r43 :=  r434 and r433 and r432 and r431 and volume_ok and r43_ok and belowLine_r
    b444 = (o4>c4)
    b443 = (o3>c3)
    b442 = ((o2-c2)>(mcs*atr)and((o4-c4)>(bl*atr))and((o3-c3)>(bl*atr))) or ((o3-c3)>(mcs*atr)and((o4-c4)>(bl*atr))and((o2-c2)>(bl*atr))) or ((o4-c4)>(mcs*atr)and((o3-c3)>(bl*atr))and((o2-c2)>(bl*atr)))
    b441 = (c1>o4-(o4-c4)*pmval)
    b44 :=  b444 and b443 and b442 and b441 and volume_ok and b44_ok and belowLine_b
    r444 = (c4>o4)
    r443 = (c3>o3)
    r442 = ((c2-o2)>(mcs*atr)and((c4-o4)>(bl*atr))and((c3-o3)>(bl*atr))) or ((c3-o3)>(mcs*atr)and((c4-o4)>(bl*atr))and((c2-o2)>(bl*atr))) or ((c4-o4)>(mcs*atr)and((c3-o3)>(bl*atr))and((c2-o2)>(bl*atr)))
    r441 = (c1<o4+(c4-o4)*pmval)
    r44 :=  r444 and r443 and r442 and r441 and volume_ok and r44_ok and belowLine_r
    b313 = (o3>c3)
    b312 = (((o3-c3)>(mcs*atr))and((o2-c2)>(bl*atr))) or (((o2-c2)>(mcs*atr))and((o3-c3)>(bl*atr))) 
    b311 = (c1>o3-(o3-c3)*pmval)
    b31 :=  b313 and b312 and b311 and volume_ok and b31_ok and belowLine_b
    r313 = (c3>o3)
    r312 = (((c3-o3)>(mcs*atr))and((c2-o2)>(bl*atr))) or (((c2-o2)>(mcs*atr))and((c3-o3)>(bl*atr))) 
    r311 = (c1<o3+(c3-o3)*pmval)
    r31 := r313 and r312 and r311 and volume_ok and r31_ok and belowLine_r
    b323 = ((o3-c3)>(mcs*atr))
    b322 = ((o2>c2)and((o2-c2)<(bl*atr))) or ((c2>o2)and((c2-o2)<(bl*atr)))
    b321 = (c1>o3-(o3-c3)*pmval)
    b32 :=  b323 and b322 and b321 and volume_ok and b32_ok and belowLine_b
    r323 = ((c3-o3)>(mcs*atr))
    r322 = ((c2>o2)and((c2-o2)<(bl*atr))) or ((c2<o2)and((o2-c2)<(bl*atr)))
    r321 = (c1<o3+(c3-o3)*pmval)
    r32 :=  r323 and r322 and r321 and volume_ok and r32_ok and belowLine_r
    b212 = ((o2-c2)>atr) and (((h2-o2)<((o2-c2)/2))or((h2-o2)<((c2-l2)/2))) 
    b211 = (c1>o2-(o2-c2)*pmval) and (((h1-c1)<((c1-o1)/2))or((h1-c1)<((o1-l1)/2))) 
    b21 :=  b212 and b211 and volume_ok and b21_ok and belowLine_b
    r212 = ((c2-o2)>atr) and (((o2-l2)<((c2-o2)/2))or((o2-l2)<((h2-c2)/2))) 
    r211 = (c1<o2+(c2-o2)*pmval) and (((c1-l1)<((o1-c1)/2))or((c1-l1)<((h1-o1)/2))) 
    r21 :=  r212 and r211 and volume_ok and r21_ok and belowLine_r

var float wt1 = 0
var float wt2 = 0
var float wt3 = 0
var float wt4 = 0
var float wt51 = 0
var float wt61 = 0
var float wt71 = 0
var float wt81 = 0
var float wt52 = 0
var float wt62 = 0
var float wt72 = 0
var float wt82 = 0
var float wt53 = 0
var float wt63 = 0
var float wt73 = 0
var float wt83 = 0
var float wt9 = 0
var float wt10 = 0
var float wt11 = 0
var float wt12 = 0
var float wt131 = 0
var float wt141 = 0
var float wt132 = 0
var float wt142 = 0
var float wt133 = 0
var float wt143 = 0
var float wt15 = 0
var float wt16 = 0
var float wt17 = 0
var float wt18 = 0
var float wt19 = 0
var float wt20 = 0
var float wt21 = 0
var float wt22 = 0
var float wt231 = 0
var float wt241 = 0
var float wt251 = 0
var float wt261 = 0
var float wt232 = 0
var float wt242 = 0
var float wt252 = 0
var float wt262 = 0
var float wt233 = 0
var float wt243 = 0
var float wt253 = 0
var float wt263 = 0
var float wt271 = 0
var float wt272 = 0
var float wt273 = 0
var float wt281 = 0
var float wt282 = 0
var float wt283 = 0

volris_wt = 1.0
volfal_wt = 0.5
intr_wt = 0.6
sudv1_wt = 0.5
sudv2_wt = 0.6
sudv3_wt = 0.7
lacv1_wt = 0.5
lacv2_wt = 0.6
lacv3_wt = 0.7
volpat_wt = 0.7
voldif1_wt = 0.8
voldif2_wt = 0.9
voldif3_wt = 1.0
cancol_wt = 0.5
hc_wt = 0.5
bws_wt = 0.6
cp_wt = 0.7
kld1_wt = 0.5
kld2_wt = 0.6
kld3_wt = 0.7
fvgdet1_wt = 0.6
fvgdet2_wt = 0.7
fvgdet3_wt = 0.8
obdet1_wt = 0.6
obdet2_wt = 0.7
obdet3_wt = 0.8

if green[0] or green[1] or green[2]
	wt1 := volris_wt
else
	wt1 := 0
if red[0] or red[1] or red[2]
	wt2 := 0-volris_wt
else
	wt2 := 0
if greenr[0] or greenr[1] or greenr[2]
	wt3 := volfal_wt
else
	wt3 := 0
if redr[0] or redr[1] or redr[2]
	wt4 := 0-volfal_wt
else
	wt4 := 0
if (lackvol1)[0] or (lackvol1)[1] or (lackvol1)[2]
	wt51 := lacv1_wt
else
	wt51 := 0
if (lackvol1b)[0] or (lackvol1b)[1] or (lackvol1b)[2]
	wt61 := 0-lacv1_wt
else
	wt61 := 0
if (sudvol1b)[0] or (sudvol1b)[1] or (sudvol1b)[2]
	wt71 := sudv1_wt
else
	wt71 := 0
if (sudvol1)[0] or (sudvol1)[1] or (sudvol1)[2]
	wt81 := 0-sudv1_wt
else
	wt81 := 0
if (lackvol2)[0] or (lackvol2)[1] or (lackvol2)[2]
	wt52 := lacv2_wt
else
	wt52 := 0
if (lackvol2b)[0] or (lackvol2b)[1] or (lackvol2b)[2]
	wt62 := 0-lacv2_wt
else
	wt62 := 0
if (sudvol2b)[0] or (sudvol2b)[1] or (sudvol2b)[2]
	wt72 := sudv2_wt
else
	wt72 := 0
if (sudvol2)[0] or (sudvol2)[1] or (sudvol2)[2]
	wt82 := 0-sudv2_wt
else
	wt82 := 0
if (lackvol3)[0] or (lackvol3)[1] or (lackvol3)[2]
	wt53 := lacv3_wt
else
	wt53 := 0
if (lackvol3b)[0] or (lackvol3b)[1] or (lackvol3b)[2]
	wt63 := 0-lacv3_wt
else
	wt63 := 0
if (sudvol3b)[0] or (sudvol3b)[1] or (sudvol3b)[2]
	wt73 := sudv3_wt
else
	wt73 := 0
if (sudvol3)[0] or (sudvol3)[1] or (sudvol3)[2]
	wt83 := 0-sudv3_wt
else
	wt83 := 0
if sig1b[0] or sig1b[1] or sig1b[2]
	wt9 := intr_wt
else
	wt9 := 0
if sig1r[0] or sig1r[1] or sig1r[2] 
	wt10 := 0-intr_wt
else
	wt10 := 0
if (cpt1b or cpt2b or cpt3b or cpt4b or cpt5b)[0] or (cpt1b or cpt2b or cpt3b or cpt4b or cpt5b)[1] or (cpt1b or cpt2b or cpt3b or cpt4b or cpt5b)[2]
	wt11 := volpat_wt
else
	wt11 := 0
if (cpt1r or cpt2r or cpt3r or cpt4r or cpt5r)[0] or (cpt1r or cpt2r or cpt3r or cpt4r or cpt5r)[1] or (cpt1r or cpt2r or cpt3r or cpt4r or cpt5r)[2]
	wt12 := 0-volpat_wt
else
	wt12 := 0
if (vob1s)[0] or (vob1s)[1] or (vob1s)[2]
	wt131 := voldif3_wt
else
	wt131 := 0
if (vor1s)[0] or (vor1s)[1] or (vor1s)[2]
	wt141 := 0-voldif3_wt
else
	wt141 := 0
if (vob1m)[0] or (vob1m)[1] or (vob1m)[2]
	wt132 := voldif2_wt
else
	wt132 := 0
if (vor1m)[0] or (vor1m)[1] or (vor1m)[2]
	wt142 := 0-voldif2_wt
else
	wt142 := 0
if (vob1w)[0] or (vob1w)[1] or (vob1w)[2]
	wt133 := voldif1_wt
else
	wt133 := 0
if (vor1w)[0] or (vor1w)[1] or (vor1w)[2]
	wt143 := 0-voldif1_wt
else
	wt143 := 0
if (dif2>dif2[1] and dif2<0)[0] or (dif2>dif2[1] and dif2<0)[1] or (dif2>dif2[1] and dif2<0)[2]
	wt15 := cancol_wt
else
	wt15 := 0
if (dif2<dif2[1] and dif2>0)[0] or (dif2<dif2[1] and dif2>0)[1] or (dif2<dif2[1] and dif2>0)[2]
	wt16 := 0-cancol_wt
else
	wt16 := 0
if (b61 or b62 or b63 or b64 or b65 or b66 or b51 or b52 or b53 or b54 or b55 or b41 or b42 or b43 or b44 or b31 or b32 or b21)[0] or (b61 or b62 or b63 or b64 or b65 or b66 or b51 or b52 or b53 or b54 or b55 or b41 or b42 or b43 or b44 or b31 or b32 or b21)[1] or (b61 or b62 or b63 or b64 or b65 or b66 or b51 or b52 or b53 or b54 or b55 or b41 or b42 or b43 or b44 or b31 or b32 or b21)[2]
	wt17 := cp_wt
else
	wt17 := 0
if (r61 or r62 or r63 or r64 or r65 or r66 or r51 or r52 or r53 or r54 or r55 or r41 or r42 or r43 or r44 or r31 or r32 or r21)[0] or (r61 or r62 or r63 or r64 or r65 or r66 or r51 or r52 or r53 or r54 or r55 or r41 or r42 or r43 or r44 or r31 or r32 or r21)[1] or (r61 or r62 or r63 or r64 or r65 or r66 or r51 or r52 or r53 or r54 or r55 or r41 or r42 or r43 or r44 or r31 or r32 or r21)[2]
	wt18 := 0-cp_wt
else
	wt18 := 0
if bhc[0] or bhc[1] or bhc[2]
	wt19 := hc_wt
else
	wt19 := 0
if rhc[0] or rhc[1] or rhc[2]
	wt20 := 0-hc_wt
else
	wt20 := 0
if shouldPlot1[0] or shouldPlot1[1] or shouldPlot1[2]
	wt21 := bws_wt
else
	wt21 := 0
if shouldPlot[0] or shouldPlot[1] or shouldPlot[2]
	wt22 := 0-bws_wt
else
	wt22 := 0
if shouldPlot61[0] or shouldPlot61[1] or shouldPlot61[2]
	wt231 := kld1_wt
else
	wt231 := 0
if shouldPlot71[0] or shouldPlot71[1] or shouldPlot71[2]
	wt241 := 0-kld1_wt
else
	wt241 := 0
if shouldPlot81[0] or shouldPlot81[1] or shouldPlot81[2]
	wt251 := fvgdet1_wt
else
	wt251 := 0
if shouldPlot91[0] or shouldPlot91[1] or shouldPlot91[2]
	wt261 := 0-fvgdet1_wt
else
	wt261 := 0
if shouldPlot62[0] or shouldPlot62[1] or shouldPlot62[2]
	wt232 := kld2_wt
else
	wt232 := 0
if shouldPlot72[0] or shouldPlot72[1] or shouldPlot72[2]
	wt242 := 0-kld2_wt
else
	wt242 := 0
if shouldPlot82[0] or shouldPlot82[1] or shouldPlot82[2]
	wt252 := fvgdet2_wt
else
	wt252 := 0
if shouldPlot92[0] or shouldPlot92[1] or shouldPlot92[2]
	wt262 := 0-fvgdet2_wt
else
	wt262 := 0
if shouldPlot63[0] or shouldPlot63[1] or shouldPlot63[2]
	wt233 := kld3_wt
else
	wt233 := 0
if shouldPlot73[0] or shouldPlot73[1] or shouldPlot73[2]
	wt243 := 0-kld3_wt
else
	wt243 := 0
if shouldPlot83[0] or shouldPlot83[1] or shouldPlot83[2]
	wt253 := fvgdet3_wt
else
	wt253 := 0
if shouldPlot93[0] or shouldPlot93[1] or shouldPlot93[2]
	wt263 := 0-fvgdet3_wt
else
	wt263 := 0
if shouldPlot101[0] or shouldPlot101[1] or shouldPlot101[2]
	wt271 := obdet1_wt
else
	wt271 := 0
if shouldPlot111[0] or shouldPlot111[1] or shouldPlot111[2]
	wt281 := 0-obdet1_wt
else
	wt281 := 0
if shouldPlot102[0] or shouldPlot102[1] or shouldPlot102[2]
	wt272 := obdet2_wt
else
	wt272 := 0
if shouldPlot112[0] or shouldPlot112[1] or shouldPlot112[2]
	wt282 := 0-obdet2_wt
else
	wt282 := 0
if shouldPlot103[0] or shouldPlot103[1] or shouldPlot103[2]
	wt273 := obdet3_wt
else
	wt273 := 0
if shouldPlot113[0] or shouldPlot113[1] or shouldPlot113[2]
	wt283 := 0-obdet3_wt
else
	wt283 := 0

wt = wt271+wt272+wt273+wt281+wt282+wt283+wt231+wt241+wt251+wt261+wt232+wt242+wt252+wt262+wt233+wt243+wt253+wt263+wt131+wt141+wt132+wt142+wt133+wt143+wt51+wt61+wt71+wt81+wt52+wt62+wt72+wt82+wt53+wt63+wt73+wt83+wt1+wt2+wt3+wt4+wt9+wt10+wt11+wt12+wt15+wt16+wt17+wt18+wt19+wt20+wt21+wt22
plot((wt), color=color.new(#b71c1c, 0))
plot((0), color=color.new(#000000, 0))
plot((2), color=color.new(#000000, 0))
plot((-2), color=color.new(#000000, 0))