declare upper; #declare once_per_bar; input OpenTime = 0700; input OpenTradeTime = 930; input DurationHours = 2; input CloseTime = 1130; input ExitPositionTime = 1200; input maxDurationHours = 2.5; def startCounter = SecondsFromTime(OpenTradeTime); def endCounter = SecondsTillTime(CloseTime); def exitCounter = SecondsTillTime(ExitPositionTime); def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0; def alertPeriodStart = if alertPeriod == 1 and alertPeriod[1] == 0 then 1 else 0; def exitPeriod = if startCounter >= 0 and exitCounter < 0 then 1 else 0; def exitPeriodStart = if exitPeriod == 1 and exitPeriod[1] == 0 then 1 else 0; input startOffset = 5; input endOffset = 2; input ShowRAF = yes; AddVerticalLine(alertPeriodStart, "TradeTime", Color.GREEN); AddVerticalLine(ExitPeriodStart, "ExitTime", Color.RED); #HPMRs input alertsOn = no; input showBorderOnCloud = yes; def hour = Floor(SecondsTillTime(0) / -3600); def pdLow = low(period = AggregationPeriod.HOUR); def pdHigh = high(period = AggregationPeriod.HOUR); def state = {default init, run}; def low0; def high0; def low1; def high1; def low2; def high2; def low3; def high3; def low4; def high4; def low5; def high5; def low6; def high6; def low7; def high7; def low8; def high8; def low9; def high9; def low10; def high10; def low11; def high11; def low12; def high12; def low13; def high13; def low14; def high14; def low15; def high15; def low16; def high16; def low17; def high17; def low18; def high18; def low19; def high19; def low20; def high20; def low21; def high21; def low22; def high22; def low23; def high23; switch (state[1]) { case init: if (GetSymbol() == "/CL:XNYM") or (GetSymbol() == "/QM:XNYM") then { low0=0.1092214412; high0=0.2225342840; low1=0.1458544542; high1=0.2930849397; low2=0.2130149813; high2=0.3600619418; low3=0.2800520701; high3=0.4425633146; low4=0.3060541948; high4=0.4967150360; low5=0.2506950010; high5=0.4450301898; low6=0.2317476218; high6=0.4140985321; low7=0.2292348728; high7=0.4303035887; low8=0.2833828909; high8=0.5468461168; low9=0.4565818008; high9=0.6611105069; low10=0.4494611459; high10=0.7274619310; low11=0.3987936373; high11=0.6115140551; low12=0.3005600058; high12=0.5348246096; low13=0.3013787418; high13=0.4798811007; low14=0.3187560023; high14=0.5401416355; low15=0.1750705217; high15=0.3222523130; low16=0.1211191587; high16=0.2810855657; low17=double.NaN; high17=double.NaN; low18=0.1962110963; high18=0.4477583693; low19=0.1385941073; high19=0.2664828158; low20=0.1811399776; high20=0.3760907917; low21=0.1820727644; high21=0.3699272356; low22=0.1392177888; high22=0.2737593104; low23=0.1227612532; high23=0.2479364212; } else if (GetSymbol() == "/ES:XCME") or (GetSymbol() == "/MES:XCME") then { low0=4.4555137724; high0=8.5906400738; low1=5.9478448950; high1=11.5175397204; low2=7.7822857523; high2=13.5100219400; low3=10.4002472277; high3=16.2497527723; low4=9.0428669725; high4=15.3763637967; low5=7.7280388971; high5=12.5796534106; low6=7.3550221215; high6=12.1526701862; low7=7.5113218646; high7=12.8156012123; low8=8.3864822333; high8=15.3058254590; low9=13.7508203092; high9=21.7414873831; low10=14.6003074020; high10=24.8606300980; low11=11.5700069347; high11=21.2761469115; low12=9.5964843865; high12=17.9535156135; low13=9.2735943752; high13=16.4842181248; low14=10.6698468450; high14=21.2403094050; low15=16.0511802697; high15=25.8937016201; low16=6.9956079791; high16=12.5122660366; low17=double.NaN; high17=double.NaN; low18=7.2084196164; high18=13.4761957682; low19=6.1118737372; high19=10.5842801089; low20=7.8625064753; high20=12.2596309293; low21=7.4742920400; high21=13.8872464215; low22=5.9284033610; high22=10.4408274082; low23=5.0998705635; high23=8.5693602058; } else if (GetSymbol() == “/HG:XCEC”) then { Low0=0.004355; High0=0.007990; Low1=0.009139; High1=0.013114; Low2=0.010408; High2=0.016491; Low3=0.012906; High3=0.019016; Low4=0.011476; High4=0.017277; Low5=0.008340; High5=0.012097; Low6=0.006849; High6=0.012211; Low7=0.009490; High7=0.014717; Low8=0.013090; High8=0.021079; Low9=0.016396; High9=0.02484; Low10=0.014881; High10=0.023785; Low11=0.012047; High11=0.018429; Low12=0.008734; High12=0.013919; Low13=0.006722; High13=0.009505; Low14=0.005989; High14=0.013419; Low15=0.006102; High15=0.011574; Low16=0.003704; High16=0.005870; low17=double.NaN; high17=double.NaN; Low18=0.006459; High18=0.011924; Low19=0.005013; High19=0.007939; Low20=0.007422; High20=0.012969; Low21=0.012374; High21=0.019679; Low22=0.007495; High22=0.012528; Low23=0.005935; High23=0.010018; } else if (GetSymbol() == "/GC:XCEC") or (GetSymbol() == "/MGC:XCEC") then { low0=2.3615412586; high0=5.2092279721; low1=3.6503198558; high1=6.2611305258; low2=4.3510864927; high2=8.4889135073; low3=4.8231831289; high3=9.1614322557; low4=4.7498033985; high4=8.5394273707; low5=3.9815957451; high5=6.6999427164; low6=3.9170768537; high6=6.5180376501; low7=4.5458552871; high7=7.8556831745; low8=8.0073107254; high8=13.4973046592; low9=8.7484469693; high9=13.4115530307; low10=8.9215627877; high10=14.6507449046; low11=6.6657601179; high11=10.5819321898; low12=4.8149158614; high12=7.6127764463; low13=4.1022894228; high13=7.2315688449; low14=3.6631132208; high14=8.1924423347; low15=3.4606305256; high15=6.7787395532; low16=2.0164169386; high16=4.5554580614; low17=double.NaN; high17=double.NaN; low18=3.2022242984; high18=6.7516218554; low19=2.4998445235; high19=5.5678477842; low20=3.6990544524; high20=6.5332532399; low21=4.7461164806; high21=8.8138835194; low22=3.2945394653; high22=6.1793066885; low23=2.3411764975; high23=5.8465158102; } else if (GetSymbol() == "/NQ:XCME") or (GetSymbol() == "/MNQ:XCME") then { low0=16.6000632356; high0=32.3614752260; low1=21.0598238845; high1=43.4517145770; low2=28.2494036789; high2=49.6505963211; low3=35.2863073327; high3=59.8406157442; low4=30.5918973037; high4=54.7504103886; low5=27.5646527748; high5=48.1391933791; low6=27.8168041730; high6=47.5562727501; low7=30.3623395929; high7=53.6876604071; low8=32.3303613564; high8=55.5234847975; low9=69.0911434615; high9=108.0212596393; low10=67.1240273889; high10=112.3798485801; low11=53.3458663008; high11=95.1156721607; low12=46.1882884293; high12=80.9155577246; low13=43.1759978863; high13=73.0680966018; low14=46.3707934079; high14=86.8024349385; low15=61.3907491028; high15=101.2667312122; low16=24.2426546514; high16=51.3164004667; low17=double.NaN; high17=double.NaN; low18=26.1500543801; high18=53.3422533122; low19=21.6882600884; high19=37.7848168347; low20=28.0418786550; high20=46.2658136527; low21=29.2562002612; high21=49.2361074311; low22=22.7829529053; high22=38.4901240178; low23=18.7999090599; high23=34.2923986324; } else if (GetSymbol() == "/RTY:XCME") or (GetSymbol() == "/M2K:XCME") then { low0=2.8877471063; high0=5.4445605860; low1=3.7495878279; high1=7.1473352490; low2=4.8877066598; high2=8.6738318017; low3=6.9299564962; high3=10.5592742730; low4=5.7955222322; high4=10.5490931524; low5=4.9079630255; high5=8.2443446668; low6=4.8062570250; high6=8.2445122058; low7=5.1746672404; high7=8.9776404519; low8=6.2045877507; high8=11.3538737877; low9=12.4456671849; high9=18.2881789690; low10=12.0250159164; high10=18.7499840836; low11=8.7064327598; high11=14.5181826248; low12=7.4126658210; high12=11.9919495636; low13=6.3219044185; high13=10.7174656603; low14=7.0354886422; high14=13.0164798617; low15=8.7041398977; high15=14.8407419921; low16=4.5028945125; high16=7.6845070624; low17=double.NaN; high17=double.NaN; low18=4.5496349261; high18=9.2488266124; low19=3.7799257125; high19=6.6600742875; low20=4.9460060136; high20=8.1001478326; low21=4.7634004428; high21=8.8858303264; low22=3.7419924150; high22=6.9318537388; low23=3.1898721783; high23=5.6255124371; } else if (GetSymbol() == "/YM:XCBT") or (GetSymbol() == "/MYM:XCBT") then { low0=38.7356153612; high0=75.0951538696; low1=51.4426857035; high1=99.6496219888; low2=68.2011612564; high2=118.8911464359; low3=93.9203545403; high3=146.9411839212; low4=80.8288858740; high4=139.5403448952; low5=67.3316988880; high5=109.0375318813; low6=63.4785003027; high6=106.1676535435; low7=65.8934842524; high7=112.2295926707; low8=76.4429892593; high8=142.7262415099; low9=134.4044797808; high9=200.9955202192; low10=131.3392335166; high10=220.2076414834; low11=100.0699043830; high11=179.0531725401; low12=77.0116378283; high12=150.5575929409; low13=76.6764211223; high13=136.2212166729; low14=89.3368548135; high14=174.7891294385; low15=131.8404148800; high15=213.5454118917; low16=59.0952197868; high16=99.2984810006; low17=double.NaN; high17=double.NaN; low18=63.7953524568; high18=112.6046475432; low19=54.4755257068; high19=94.2475512162; low20=68.3398211391; high20=107.0294096301; low21=64.6334807654; high21=121.5511346192; low22=50.4856046713; high22=92.1759337902; low23=44.3116547078; high23=74.7037299075; } else if (GetSymbol() == "/ZB:XCBT") then { low0=0.1021184572; high0=0.1688739092; low1=0.1230355770; high1=0.2154259615; low2=0.2021925213; high2=0.3369296161; low3=0.2587416550; high3=0.3725083450; low4=0.2155522003; high4=0.3253131844; low5=0.1832686495; high5=0.2739428890; low6=0.1851779770; high6=0.2662643306; low7=0.2065519799; high7=0.3254136690; low8=0.3416135363; high8=0.5387159211; low9=0.3410697712; high9=0.5450736396; low10=0.3210504115; high10=0.5260649731; low11=0.2643912050; high11=0.4259934104; low12=0.2177677937; high12=0.3418475909; low13=0.1989376142; high13=0.3738970314; low14=0.2120428088; high14=0.4241876600; low15=0.2055580333; high15=0.3451309431; low16=0.1661256475; high16=0.2611204463; low17=double.NaN; high17=double.NaN; low18=0.1433058418; high18=0.2389056966; low19=0.1085950523; high19=0.2096301386; low20=0.1681384595; high20=0.2712699374; low21=0.1442749517; high21=0.2744750483; low22=0.1019996649; high22=0.2128858313; low23=0.1078847506; high23=0.1786537110; } else { low0= double.NaN; high0= double.NaN; low1= double.NaN; high1= double.NaN; low2= double.NaN; high2= double.NaN; low3= double.NaN; high3= double.NaN; low4= double.NaN; high4= double.NaN; low5= double.NaN; high5= double.NaN; low6= double.NaN; high6= double.NaN; low7= double.NaN; high7= double.NaN; low8= double.NaN; high8= double.NaN; low9= double.NaN; high9= double.NaN; low10= double.NaN; high10= double.NaN; low11= double.NaN; high11= double.NaN; low12= double.NaN; high12= double.NaN; low13= double.NaN; high13= double.NaN; low14= double.NaN; high14= double.NaN; low15= double.NaN; high15= double.NaN; low16= double.NaN; high16= double.NaN; low17= double.NaN; high17= double.NaN; low18= double.NaN; high18= double.NaN; low19= double.NaN; high19= double.NaN; low20= double.NaN; high20= double.NaN; low21= double.NaN; high21= double.NaN; low22= double.NaN; high22= double.NaN; low23= double.NaN; high23= double.NaN; } state = if barnumber()>2 then state.run else state.init; case run: low0=low0[1]; low1=low1[1]; low2=low2[1]; low3=low3[1]; low4=low4[1]; low5=low5[1]; low6=low6[1]; low7=low7[1]; low8=low8[1]; low9=low9[1]; low10=low10[1]; low11=low11[1]; low12=low12[1]; low13=low13[1]; low14=low14[1]; low15=low15[1]; low16=low16[1]; low17=low17[1]; low18=low18[1]; low19=low19[1]; low20=low20[1]; low21=low21[1]; low22=low22[1]; low23=low23[1]; high0=high0[1]; high1=high1[1]; high2=high2[1]; high3=high3[1]; high4=high4[1]; high5=high5[1]; high6=high6[1]; high7=high7[1]; high8=high8[1]; high9=high9[1]; high10=high10[1]; high11=high11[1]; high12=high12[1]; high13=high13[1]; high14=high14[1]; high15=high15[1]; high16=high16[1]; high17=high17[1]; high18=high18[1]; high19=high19[1]; high20=high20[1]; high21=high21[1]; high22=high22[1]; high23=high23[1]; state=state.run; } def xhigh = if (hour == 0) then (pdLow + high0) else if (hour == 1) then (pdLow + high1) else if (hour == 2) then (pdLow + high2) else if (hour == 3) then (pdLow + high3) else if (hour == 4) then (pdLow + high4) else if (hour == 5) then (pdLow + high5) else if (hour == 6) then (pdLow + high6) else if (hour == 7) then (pdLow + high7) else if (hour == 8) then (pdLow + high8) else if (hour == 9) then (pdLow + high9) else if (hour == 10) then (pdLow + high10) else if (hour == 11) then (pdLow + high11) else if (hour == 12) then (pdLow + high12) else if (hour == 13) then (pdLow + high13) else if (hour == 14) then (pdLow + high14) else if (hour == 15) then (pdLow + high15) else if (hour == 16) then (pdLow + high16) else if (hour == 17) then (pdLow + high17) else if (hour == 18) then (pdLow + high18) else if (hour == 19) then (pdLow + high19) else if (hour == 20) then (pdLow + high20) else if (hour == 21) then (pdLow + high21) else if (hour == 22) then (pdLow + high22) else if (hour == 23) then (pdLow + high23) else Double.NaN; def mhigh = if (hour == 0) then (pdLow + (high0 + low0) / 2)else if (hour == 1) then (pdLow + (high1 + low1) / 2)else if (hour == 2) then (pdLow + (high2 + low2) / 2)else if (hour == 3) then (pdLow + (high3 + low3) / 2)else if (hour == 4) then (pdLow + (high4 + low4) / 2)else if (hour == 5) then (pdLow + (high5 + low5) / 2)else if (hour == 6) then (pdLow + (high6 + low6) / 2)else if (hour == 7) then (pdLow + (high7 + low7) / 2)else if (hour == 8) then (pdLow + (high8 + low8) / 2)else if (hour == 9) then (pdLow + (high9 + low9) / 2)else if (hour == 10) then (pdLow + (high10 + low10) / 2)else if (hour == 11) then (pdLow + (high11 + low11) / 2)else if (hour == 12) then (pdLow + (high12 + low12) / 2)else if (hour == 13) then (pdLow + (high13 + low13) / 2)else if (hour == 14) then (pdLow + (high14 + low14) / 2)else if (hour == 15) then (pdLow + (high15 + low15) / 2)else if (hour == 16) then (pdLow + (high16 + low16) / 2)else if (hour == 17) then (pdLow + (high17 + low17) / 2)else if (hour == 18) then (pdLow + (high18 + low18) / 2)else if (hour == 19) then (pdLow + (high19 + low19) / 2)else if (hour == 20) then (pdLow + (high20 + low20) / 2)else if (hour == 21) then (pdLow + (high21 + low21) / 2)else if (hour == 22) then (pdLow + (high22 + low22) / 2)else if (hour == 23) then (pdLow + (high23 + low23) / 2)else Double.NaN; plot nhigh = if (hour == 0) then (pdLow + low0) else if (hour == 1) then (pdLow + low1) else if (hour == 2) then (pdLow + low2) else if (hour == 3) then (pdLow + low3) else if (hour == 4) then (pdLow + low4) else if (hour == 5) then (pdLow + low5) else if (hour == 6) then (pdLow + low6) else if (hour == 7) then (pdLow + low7) else if (hour == 8) then (pdLow + low8) else if (hour == 9) then (pdLow + low9) else if (hour == 10) then (pdLow + low10) else if (hour == 11) then (pdLow + low11) else if (hour == 12) then (pdLow + low12) else if (hour == 13) then (pdLow + low13) else if (hour == 14) then (pdLow + low14) else if (hour == 15) then (pdLow + low15) else if (hour == 16) then (pdLow + low16) else if (hour == 17) then (pdLow + low17) else if (hour == 18) then (pdLow + low18) else if (hour == 19) then (pdLow + low19) else if (hour == 20) then (pdLow + low20) else if (hour == 21) then (pdLow + low21) else if (hour == 22) then (pdLow + low22) else if (hour == 23) then (pdLow + low23) else Double.NaN; def xlow = if (hour == 0) then (pdHigh - high0) else if (hour == 1) then (pdHigh - high1) else if (hour == 2) then (pdHigh - high2) else if (hour == 3) then (pdHigh - high3) else if (hour == 4) then (pdHigh - high4) else if (hour == 5) then (pdHigh - high5) else if (hour == 6) then (pdHigh - high6) else if (hour == 7) then (pdHigh - high7) else if (hour == 8) then (pdHigh - high8) else if (hour == 9) then (pdHigh - high9) else if (hour == 10) then (pdHigh - high10) else if (hour == 11) then (pdHigh - high11) else if (hour == 12) then (pdHigh - high12) else if (hour == 13) then (pdHigh - high13) else if (hour == 14) then (pdHigh - high14) else if (hour == 15) then (pdHigh - high15) else if (hour == 16) then (pdHigh - high16) else if (hour == 17) then (pdHigh - high17) else if (hour == 18) then (pdHigh - high18) else if (hour == 19) then (pdHigh - high19) else if (hour == 20) then (pdHigh - high20) else if (hour == 21) then (pdHigh - high21) else if (hour == 22) then (pdHigh - high22) else if (hour == 23) then (pdHigh - high23) else Double.NaN; def mlow = if (hour == 0) then (pdHigh - (high0 + low0) / 2)else if (hour == 1) then (pdHigh - (high1 + low1) / 2)else if (hour == 2) then (pdHigh - (high2 + low2) / 2)else if (hour == 3) then (pdHigh - (high3 + low3) / 2)else if (hour == 4) then (pdHigh - (high4 + low4) / 2)else if (hour == 5) then (pdHigh - (high5 + low5) / 2)else if (hour == 6) then (pdHigh - (high6 + low6) / 2)else if (hour == 7) then (pdHigh - (high7 + low7) / 2)else if (hour == 8) then (pdHigh - (high8 + low8) / 2)else if (hour == 9) then (pdHigh - (high9 + low9) / 2)else if (hour == 10) then (pdHigh - (high10 + low10) / 2)else if (hour == 11) then (pdHigh - (high11 + low11) / 2)else if (hour == 12) then (pdHigh - (high12 + low12) / 2)else if (hour == 13) then (pdHigh - (high13 + low13) / 2)else if (hour == 14) then (pdHigh - (high14 + low14) / 2)else if (hour == 15) then (pdHigh - (high15 + low15) / 2)else if (hour == 16) then (pdHigh - (high16 + low16) / 2)else if (hour == 17) then (pdHigh - (high17 + low17) / 2)else if (hour == 18) then (pdHigh - (high18 + low18) / 2)else if (hour == 19) then (pdHigh - (high19 + low19) / 2)else if (hour == 20) then (pdHigh - (high20 + low20) / 2)else if (hour == 21) then (pdHigh - (high21 + low21) / 2)else if (hour == 22) then (pdHigh - (high22 + low22) / 2)else if (hour == 23) then (pdHigh - (high23 + low23) / 2)else Double.NaN; plot nlow = if (hour == 0) then (pdHigh - low0) else if (hour == 1) then (pdHigh - low1) else if (hour == 2) then (pdHigh - low2) else if (hour == 3) then (pdHigh - low3) else if (hour == 4) then (pdHigh - low4) else if (hour == 5) then (pdHigh - low5) else if (hour == 6) then (pdHigh - low6) else if (hour == 7) then (pdHigh - low7) else if (hour == 8) then (pdHigh - low8) else if (hour == 9) then (pdHigh - low9) else if (hour == 10) then (pdHigh - low10) else if (hour == 11) then (pdHigh - low11) else if (hour == 12) then (pdHigh - low12) else if (hour == 13) then (pdHigh - low13) else if (hour == 14) then (pdHigh - low14) else if (hour == 15) then (pdHigh - low15) else if (hour == 16) then (pdHigh - low16) else if (hour == 17) then (pdHigh - low17) else if (hour == 18) then (pdHigh - low18) else if (hour == 19) then (pdHigh - low19) else if (hour == 20) then (pdHigh - low20) else if (hour == 21) then (pdHigh - low21) else if (hour == 22) then (pdHigh - low22) else if (hour == 23) then (pdHigh - low23) else Double.NaN; nlow.SetPaintingStrategy(PaintingStrategy.LINE); nlow.SetDefaultColor(Color.GRAY); nlow.SetStyle(Curve.SHORT_DASH); nhigh.SetPaintingStrategy(PaintingStrategy.LINE); nhigh.SetDefaultColor(Color.GRAY); nhigh.SetStyle(Curve.SHORT_DASH); AddCloud(mhigh, xhigh, Color.LIGHT_RED, Color.LIGHT_RED, showBorderOnCloud); AddCloud(mlow, xlow, Color.LIGHT_GREEN, Color.LIGHT_GREEN, showBorderOnCloud); Alert(alertsOn and low <= mlow, "HPMR Long Entry Trigger", Alert.ONCE, Sound.Ring); Alert(alertsOn and high >= mhigh, "HPMR Short Entry Trigger", Alert.ONCE, Sound.Ring); #VWAP/VSCORE declare hide_on_daily; input price = close; def vpanchorTimeEST = OpenTime; def vpatStartTime = if SecondsFromTime(vpanchorTimeEST) >= 0 and SecondsFromTime(vpanchorTimeEST)[1] < 0 or (SecondsFromTime(vpanchorTimeEST) >= 0 and SecondsFromTime(vpanchorTimeEST)[1] >= 0 and GetDay() != GetDay()[1]) then 1 else 0; DefineGlobalColor("Point Of Control", Color.WHITE); DefineGlobalColor("Value Area High", Color.PINK); DefineGlobalColor("Value Area Low", Color.LIME); profile vp = VolumeProfile("startNewProfile" = vpatStartTime, "onExpansion" = no, "pricePerRow" = TickSize()); plot VPOC = vp.GetPointOfControl(); plot VAHigh = vp.GetHighestValueArea(); plot VALow = vp.GetLowestValueArea(); VPOC.SetLineWeight(3); VPOC.SetDefaultColor(GlobalColor("Point Of Control")); VPOC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); VAHigh.SetDefaultColor(GlobalColor("Value Area High")); VALow.SetDefaultColor(GlobalColor("Value Area Low")); def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1 + startOffset] == 1 and beforeStart[startOffset] == 0) or (isRollover[startOffset] and beforeStart[startOffset] == 0) then 1 else 0; def lastBarOfDay = if (afterEnd[-1 - endOffset] == 1 and afterEnd[endOffset] == 0) or (isRollover[-1 - endOffset] and firstBarOfDay[-1 - endOffset]) then 1 else 0; def dVPOC = VPOC; def dVAH = VAHigh; def dVAL = VALow; # ST_VScoreBands_Intraday # (c) 2019 Simpler Trading, LLC # 04/23/20 # By Eric Purdy declare hide_on_daily; #input price = close; def anchorTimeEST = OpenTime; def atStartTime = if SecondsFromTime(anchorTimeEST) >= 0 and SecondsFromTime(anchorTimeEST)[1] < 0 or (SecondsFromTime(anchorTimeEST) >= 0 and SecondsFromTime(anchorTimeEST)[1] >= 0 and GetDay() != GetDay()[1]) then 1 else 0; def beyondStartTime = if SecondsFromTime(anchorTimeEST) > 0 then 1 else 0; def VWP = if atStartTime then (price) * volume else VWP[1] + (price * volume); def VS = if atStartTime then volume else VS[1] + volume; plot VWAP = VWP / VS; def vwapSQR = if atStartTime then Sqr(price - VWAP) * volume else vwapSQR[1] + Sqr(price - VWAP) * volume; def VWAPSD = Sqrt(vwapSQR / VS); plot PlusOne = VWAP + VWAPSD * 1; plot MinusOne = VWAP - VWAPSD * 1; plot PlusTwo = VWAP + VWAPSD * 2; plot MinusTwo = VWAP - VWAPSD * 2; plot PlusThree = VWAP + VWAPSD * 3; plot MinusThree = VWAP - VWAPSD * 3; plot PlusFour = VWAP + VWAPSD * 4; plot MinusFour = VWAP - VWAPSD * 4; VWAP.SetDefaultColor(Color.WHITE); PlusOne.SetDefaultColor(Color.GRAY); MinusOne.SetDefaultColor(Color.GRAY); PlusTwo.SetDefaultColor(Color.DARK_RED); MinusTwo.SetDefaultColor(Color.DARK_GREEN); PlusThree.SetDefaultColor(Color.RED); MinusThree.SetDefaultColor(Color.GREEN); PlusFour.SetDefaultColor(Color.WHITE); MinusFour.SetDefaultColor(Color.WHITE); VWAP.SetLineWeight(2); PlusOne.SetLineWeight(2); MinusOne.SetLineWeight(2); PlusTwo.SetLineWeight(2); MinusTwo.SetLineWeight(2); PlusThree.SetLineWeight(2); MinusThree.SetLineWeight(2); PlusFour.SetLineWeight(2); MinusFour.SetLineWeight(2); VWAP.HideBubble(); PlusOne.HideBubble(); MinusOne.HideBubble(); PlusTwo.HideBubble(); MinusTwo.HideBubble(); PlusThree.HideBubble(); MinusThree.HideBubble(); #PlusFour.hideBubble(); #MinusFour.hideBubble(); VWAP.HideTitle(); PlusOne.HideTitle(); MinusOne.HideTitle(); PlusTwo.HideTitle(); MinusTwo.HideTitle(); PlusThree.HideTitle(); MinusThree.HideTitle(); #PlusFour.hideTitle(); #MinusFour.hideTitle(); #AddVerticalLine(atStartTime, "", Color.MAGENTA); #AssignPriceColor(if puptrendCount == 1 then Color.GREEN # else if pdowntrendCount ==1 then Color.RED # else Color.BLUE); def Ppluszero = if high >= VWAP then 1 else 0; def Pplusone = if high >= PlusOne then 1 else 0; def Pplustwo = if high >= PlusTwo then 1 else 0; def Pplusthree = if high >= PlusThree then 1 else 0; def Pminuszero = if low <= VWAP then 1 else 0; def Pminusone = if low <= MinusOne then 1 else 0; def Pminustwo = if low <= MinusTwo then 1 else 0; def Pminusthree = if low <= MinusThree then 1 else 0; #EMA TRENDS input ShowWaveTrendLabel = yes; input ShowActionLabel = yes; #plot ema1a = ExpAverage (high, 34); #plot ema2a = ExpAverage (close, 34); #plot ema3a = ExpAverage (low, 34); #plot ema4a = ExpAverage (close, 5); #plot ema5a = ExpAverage (close, 8); #plot ema6a = ExpAverage (close, 13); #ema1a.SetDefaultColor(Color.YELLOW); #ema1a.SetLineWeight(2); #ema2a.SetDefaultColor(Color.YELLOW); #ema2a.SetLineWeight(2); #ema3a.SetDefaultColor(Color.YELLOW); #ema3a.SetLineWeight(2); #ema4a.SetDefaultColor(Color.ORANGE); #ema4a.SetLineWeight(2); #ema5a.SetDefaultColor(Color.PINK); #ema5a.SetLineWeight(2); #ema6a.SetDefaultColor(Color.PLUM); #ema6a.SetLineWeight(2); #ema1a.HideBubble(); #ema2a.HideBubble(); #ema3a.HideBubble(); #ema4a.HideBubble(); #ema5a.HideBubble(); #ema6a.HideBubble(); DefineGlobalColor("Bullish", Color.GREEN); DefineGlobalColor("Sideways", Color.YELLOW); DefineGlobalColor("Bearish", Color.RED); def EMA34High = ExpAverage (high, 34); #was ema1_34 def EMA34Close = ExpAverage (close, 34); #ema2_34 def EMA34Low = ExpAverage (low, 34); # was ema3_34AddLabel(ShowWaveTrendLabel, "Wave", if IsBullishWave then GlobalColor("Bullish") else if IsBearishWave then GlobalColor("Bearish") else GlobalColor("Sideways")); def EMA8 = ExpAverage(close, 8); #JT Changed var name from EMA1 to EMA8 def EMA21 = ExpAverage(close, 21); #JT Changed var name from EMA2 to EMA21 def EMA13 = ExpAverage (close, 13); #def bullish = (EMA8 > EMA13) and (EMA13 > EMA21); #def bearish = (EMA8 < EMA13) and (EMA13 < EMA21); def WaveState = {default SW, Bullish, Bearish}; #SW = sideways WaveState = if (EMA8 > EMA13) and (EMA13 > EMA21) #and (EMA21 > EMA34High) then WaveState.Bullish else if (EMA8 < EMA13) and (EMA13 < EMA21) #and (EMA21 < EMA34Low) then WaveState.Bearish else WaveState.SW; def IsBullishWave = WaveState == WaveState.Bullish; def IsBearishWave = WaveState == WaveState.Bearish; def IsSidewaysWave = WaveState == WaveState.SW; #adding a blank label after as a spacer AddLabel(yes, " ", Color.BLACK); def EMA34H1 = ExpAverage (high(period = AggregationPeriod.FIFTEEN_MIN), 34); def EMA34H2 = ExpAverage (high(period = AggregationPeriod.THIRTY_MIN), 34); def EMA34H3 = ExpAverage (high(period = AggregationPeriod.HOUR), 34); def EMA34H4 = ExpAverage (high(period = AggregationPeriod.TWO_HOURS), 34); def EMA34H5 = ExpAverage (high(period = AggregationPeriod.FOUR_HOURS), 34); def EMA34L1 = ExpAverage (low(period = AggregationPeriod.FIFTEEN_MIN), 34); def EMA34L2 = ExpAverage (low(period = AggregationPeriod.THIRTY_MIN), 34); def EMA34L3 = ExpAverage (low(period = AggregationPeriod.HOUR), 34); def EMA34L4 = ExpAverage (low(period = AggregationPeriod.TWO_HOURS), 34); def EMA34L5 = ExpAverage (low(period = AggregationPeriod.FOUR_HOURS), 34); def EMA8C1 = ExpAverage (close(period = AggregationPeriod.FIFTEEN_MIN), 8); def EMA8C2 = ExpAverage (close(period = AggregationPeriod.THIRTY_MIN), 8); def EMA8C3 = ExpAverage (close(period = AggregationPeriod.HOUR), 8); def EMA8C4 = ExpAverage (close(period = AggregationPeriod.TWO_HOURS), 8); def EMA8C5 = ExpAverage (close(period = AggregationPeriod.FOUR_HOURS), 8); def EMA13C1 = ExpAverage (close(period = AggregationPeriod.FIFTEEN_MIN), 13); def EMA13C2 = ExpAverage (close(period = AggregationPeriod.THIRTY_MIN), 13); def EMA13C3 = ExpAverage (close(period = AggregationPeriod.HOUR), 13); def EMA13C4 = ExpAverage (close(period = AggregationPeriod.TWO_HOURS), 13); def EMA13C5 = ExpAverage (close(period = AggregationPeriod.FOUR_HOURS), 13); def EMA21C1 = ExpAverage (close(period = AggregationPeriod.FIFTEEN_MIN), 21); def EMA21C2 = ExpAverage (close(period = AggregationPeriod.THIRTY_MIN), 21); def EMA21C3 = ExpAverage (close(period = AggregationPeriod.HOUR), 21); def EMA21C4 = ExpAverage (close(period = AggregationPeriod.TWO_HOURS), 21); def EMA21C5 = ExpAverage (close(period = AggregationPeriod.FOUR_HOURS), 21); def WaveState1 = {default SW, Bullish, Bearish}; #SW = sideways WaveState1 = if (EMA8C1 > EMA13C1) and (EMA13C1 > EMA21C1) #and (EMA21C1 > EMA34H1) then WaveState1.Bullish else if (EMA8C1 < EMA13C1) and (EMA13C1 < EMA21C1) #and (EMA21C1 < EMA34L1) then WaveState1.Bearish else WaveState1.SW; def IsBullishWave1 = WaveState1 == WaveState1.Bullish; def IsBearishWave1 = WaveState1 == WaveState1.Bearish; def IsSidewaysWave1 = WaveState1 == WaveState1.SW; def WaveState2 = {default SW, Bullish, Bearish}; #SW = sideways WaveState2 = if (EMA8C2 > EMA13C2) and (EMA13C2 > EMA21C2) #and (EMA21C2 > EMA34H2) then WaveState2.Bullish else if (EMA8C2 < EMA13C2) and (EMA13C2 < EMA21C2) #and (EMA21C2 < EMA34L2) then WaveState2.Bearish else WaveState2.SW; def IsBullishWave2 = WaveState2 == WaveState2.Bullish; def IsBearishWave2 = WaveState2 == WaveState2.Bearish; def IsSidewaysWave2 = WaveState2 == WaveState2.SW; def WaveState3 = {default SW, Bullish, Bearish}; #SW = sideways WaveState3 = if (EMA8C3 > EMA13C3) and (EMA13C3 > EMA21C3) #and (EMA21C3 > EMA34H3) then WaveState3.Bullish else if (EMA8C3 < EMA13C3) and (EMA13C3 < EMA21C3) #and (EMA21C3 < EMA34L3) then WaveState3.Bearish else WaveState3.SW; def IsBullishWave3 = WaveState3 == WaveState3.Bullish; def IsBearishWave3 = WaveState3 == WaveState3.Bearish; def IsSidewaysWave3 = WaveState3 == WaveState3.SW; def WaveState4 = {default SW, Bullish, Bearish}; #SW = sideways WaveState4 = if (EMA8C4 > EMA13C4) and (EMA13C4 > EMA21C4) #and (EMA21C4 > EMA34H4) then WaveState4.Bullish else if (EMA8C4 < EMA13C4) and (EMA13C4 < EMA21C4) #and (EMA21C4 < EMA34L4) then WaveState4.Bearish else WaveState4.SW; def IsBullishWave4 = WaveState4 == WaveState4.Bullish; def IsBearishWave4 = WaveState4 == WaveState4.Bearish; def IsSidewaysWave4 = WaveState4 == WaveState4.SW; def WaveState5 = {default SW, Bullish, Bearish}; #SW = sideways WaveState5 = if (EMA8C5 > EMA13C5) and (EMA13C5 > EMA21C5) #and (EMA21C5 > EMA34H5) then WaveState5.Bullish else if (EMA8C5 < EMA13C5) and (EMA13C5 < EMA21C5) #and (EMA21C5 < EMA34L5) then WaveState5.Bearish else WaveState5.SW; def IsBullishWave5 = WaveState5 == WaveState5.Bullish; def IsBearishWave5 = WaveState5 == WaveState5.Bearish; def IsSidewaysWave5 = WaveState5 == WaveState5.SW; # # RAF OSCILLATOR input OverboughtOversold = 1.2; input GenerateAlerts = No; input AlertRequiresAim = Yes; def CountChg; rec SC; def maxHigh = Highest(high, 10); def minLow = Lowest(low, 10); def k1v = Max(-100, Min(100, (StochasticFull(KPeriod = 5, slowing_period = 3, averageType = AverageType.EXPONENTIAL))) - 50) / 50.01; def k2v = Max(-100, Min(100, (StochasticFull(KPeriod = 8, slowing_period = 5, averageType = AverageType.EXPONENTIAL))) - 50) / 50.01; def k3v = Max(-100, Min(100, (StochasticFull(KPeriod = 17, slowing_period = 5, averageType = AverageType.EXPONENTIAL))) - 50) / 50.01; def ZeroLine = 0; def Overbought = OverboughtOversold ; def Oversold = -OverboughtOversold ; if k2v > 0 Then { CountChg = if k1v <= k2v and k1v[1] > k2v[1] and k2v[1] > 0 then -1 else 0; SC = CompoundValue(1, Min (0, SC[1]) + CountChg, 0); } else { CountChg = if k1v >= k2v and k1v[1] < k2v[1] and k2v[1] <= 0 then 1 else 0; SC = CompoundValue (1, Max (0, SC[1]) + CountChg, 0); } DefineGlobalColor ("Ready Buy", CreateColor(0, 120, 0)); DefineGlobalColor ("Aim Buy", Color.GREEN); DefineGlobalColor ("Ready Sell", CreateColor(120, 0, 0)); DefineGlobalColor ("Aim Sell", Color.RED); rec f2 = CompoundValue(1, if IsNaN(0.5 * (Log((1 + k2v) / (1 - k2v)) + f2[1])) then f2[1] else 0.5 * (Log((1 + k2v) / (1 - k2v)) + f2[1]), 0); rec f3 = CompoundValue(1, if IsNaN(0.5 * (Log((1 + k3v) / (1 - k3v)) + f3[1])) then f3[1] else 0.5 * (Log((1 + k3v) / (1 - k3v)) + f3[1]), 0); rec value = CompoundValue(1, if maxHigh - minLow == 0 then 0 else 0.66 * ((close - minLow) / (maxHigh - minLow) - 0.5) + 0.67 * value[1], 0); def truncValue = if value > 0.99 then 0.999 else if value < -0.99 then -0.999 else value; rec f = CompoundValue(1, if IsNaN(0.5 * (Log((1 + truncValue) / (1 - truncValue)) + f[1])) then f[1] else 0.5 * (Log((1 + truncValue) / (1 - truncValue)) + f[1]), 0); def MModBuy = if (Sign (f2 - f2[1]) > Sign (f2[1] - f2[2])) and !IsNaN(close) then 1 else 0; def MMajorBuy = if (Sign (f3 - f3[1]) > Sign (f3[1] - f3[2])) and !IsNaN(close) then 1 else 0; def MModSell = if (Sign (f2 - f2[1]) < Sign (f2[1] - f2[2])) and !IsNaN(close) then 1 else 0; def MMajorSell = if (Sign (f3 - f3[1]) < Sign (f3[1] - f3[2])) and !IsNaN(close) then 1 else 0; def RB = if k2v < 0 and k1v >= k2v and k1v[1] < k2v[1] and SC == 1 and (MModBuy ==1 or MMajorBuy ==1) then 1 else 0; def RAB = if k2v < 0 and k1v >= k2v and k1v[1] < k2v[1] and SC > 1 and (MModBuy ==1 or MMajorBuy ==1) then 1 else 0; def RS = if k2v > 0 and k1v <= k2v and k1v[1] > k2v[1] and SC == -1 and (MModSell ==1 or MMajorSell ==1) then 1 else 0; def RAS = if k2v > 0 and k1v <= k2v and k1v[1] > k2v[1] and SC < -1 and (MModSell ==1 or MMajorSell ==1) then 1 else 0; def RAF = if RB then 1 else if RAB then 2 else if RS then 3 else if RAS then 4 else 0; AddLabel(ShowRAF, if RAF == 1 then "RB" else if RAF == 2 then "RAB" else if RAF == 3 then "RS" else if RAF == 4 then "RAS" else "0" #RAF , color.white); #CONDITIONS def dbuySW = if alertPeriod == 1 and close > MinusTwo and low[1] < MinusTwo and low[1] < mlow and (IsBullishWave4 or IsSidewaysWave4) and (IsBullishWave5 or IsSidewaysWave5) and (RB == 1 or RAB == 1) and high < nhigh #and EMA8 PlusTwo and high[1] > mhigh and (IsBearishWave4 or IsSidewaysWave4) and (IsBearishWave5 or IsSidewaysWave5) and (RS == 1 or RAS == 1) and low > nlow #and EMA8>EMA34Low then 1 else 0; Alert (dsellSW==1,"SellSW",Alert.Bar,Sound.Ring); def dbuyTrend = if alertPeriod == 1 and low > MinusTwo and close < MinusOne and IsBullishWave5 and IsBullishWave4 and ( #RB == 1 or RAB == 1) and high < nhigh #and IsBullishWave3 #and EMA8 PlusOne and IsBearishWave5 and IsBearishWave4 and ( #RS == 1 or RAS == 1) and low > nlow #and IsBearishWave3 #and EMA8>EMA34Low then 1 else 0; Alert (dsellTrend==1,"SellTrend",Alert.Bar,Sound.Ring); def dbuySuperTrend = if alertPeriod == 1 and low > MinusOne and close < VWAP and IsBullishWave5 and IsBullishWave4 and IsBullishWave3 and IsBullishWave2 and ( # RB == 1 or RAB == 1) and high < nhigh #and EMA8 VWAP and IsBearishWave5 and IsBearishWave4 and IsBearishWave3 and IsBearishWave2 and (RS == 1 or RAS == 1) and low > nlow #and EMA8>EMA34Low then 1 else 0; Alert (dsellSuperTrend==1,"SellSuperTrend",Alert.Bar,Sound.Ring); #ORDERS AddOrder(OrderType.BUY_TO_OPEN, dbuySW == 1, open[-1], 2, Color.GREEN, Color.GREEN, "B-SW"); AddOrder(OrderType.BUY_TO_OPEN, dbuyTrend == 1, open[-1], 2, Color.GREEN, Color.GREEN, "B-Trend"); AddOrder(OrderType.BUY_TO_OPEN, dbuySuperTrend == 1, open[-1], 2, Color.GREEN, Color.GREEN, "B-Su-Trend"); AddOrder(OrderType.SELL_TO_CLOSE, Pplusone == 1 , open[-1], 1, Color.YELLOW, Color.YELLOW, "TP-Pplusone"); AddOrder(OrderType.SELL_TO_CLOSE, high >mhigh , open[-1], 1, Color.YELLOW, Color.YELLOW, "TP-high >mhigh"); AddOrder(OrderType.SELL_TO_CLOSE, RAS == 1 , open[-1], 1, Color.YELLOW, Color.YELLOW, "STOP-RAS"); AddOrder(OrderType.SELL_TO_CLOSE, close < MinusTwo , open[-1], 1, Color.YELLOW, Color.YELLOW, "STOP-close < MinusTwo"); AddOrder(OrderType.SELL_TO_CLOSE, close PlusTwo , open[-1], 1, Color.YELLOW, Color.YELLOW, "STOP-close > PlusTwo"); AddOrder(OrderType.BUY_TO_CLOSE, close >xhigh , open[-1], 1, Color.YELLOW, Color.YELLOW, "STOP-close >xhigh"); AddOrder(OrderType.BUY_TO_CLOSE, exitPeriod == 1, open[-1], 1, Color.YELLOW, Color.YELLOW, “CLOSE-exitPeriod”); #AddLabel(yes, "start " + startCounter, Color.WHITE); #AddLabel(yes, "end " + endCounter, Color.WHITE); #AddLabel(yes, "exit " + exitCounter, Color.WHITE); AddLabel(yes, "alertP " + alertPeriod, Color.WHITE); AddLabel(yes, "exitP " + exitPeriod, Color.WHITE); #AddLabel(yes, dVAH, Color.WHITE); #AddLabel(yes, dVPOC, Color.WHITE); #AddLabel(yes, dVAL, Color.WHITE);