Can someone beautify this code?

sindhu19

New member
2019 Donor
This code is from someone on this forum sometime ago, i modify it to my liking with lack thereof my coding skills ;) for 5 min chart.
However, I am more to a scalper mode recently and using 1-2 mins more often.
I would like the code to automatically recognize the time for example,
5 min = 78 bars
3 min = 130 bars
2 min = 195 bars
1 min = 390 bars

Can this be done by our master coder here?
Thank you.

Code:
declare lower;
declare hide_on_daily;

input ValueData = {
default "Volume",
        "Range",
        "Volume per Range",
        "Trades",
        "Trades per Range",
        "Volume per Trades"};
def Value;
def Range = if High - Low == 0 then TickSize() else High - Low;
switch (ValueData) {
case "Volume":
    Value = Volume;
case "Range":
    Value = Range;
case "Volume per Range":
    Value = Volume / Range;
case "Trades":
    Value = Tick_Count;
case "Trades per Range":
    Value = Tick_Count / Range;
case "Volume per Trades":
    Value = Volume / Tick_Count;}

input OpenTime = 930;
def DSTSpringForwardOpenTime = OpenTime - 100;
input CloseBarTime = 1600;
#hint DSTSpringForwardDate: If viewing futures with extended-hours trading sessions, enter "20200309" for 2020 or "20210315" for 2021. Otherwise enter "99999999".
input DSTSpringForwardDate = 20200309;
rec BarCounter = if SecondsTillTime(OpenTime) == 0 and GetYYYYMMDD() != DSTSpringForwardDate then 1 else if SecondsTillTime(DSTSpringForwardOpenTime) == 0 and GetYYYYMMDD() == DSTSpringForwardDate then 1 else BarCounter[1] + 1;

def Bar1  = if BarCounter == 1  then Value else 0;
def Bar2  = if BarCounter == 2  then Value else 0;
def Bar3  = if BarCounter == 3  then Value else 0;
def Bar4  = if BarCounter == 4  then Value else 0;
def Bar5  = if BarCounter == 5  then Value else 0;
def Bar6  = if BarCounter == 6  then Value else 0;
def Bar7  = if BarCounter == 7  then Value else 0;
def Bar8  = if BarCounter == 8  then Value else 0;
def Bar9  = if BarCounter == 9  then Value else 0;
def Bar10 = if BarCounter == 10 then Value else 0;
def Bar11 = if BarCounter == 11 then Value else 0;
def Bar12 = if BarCounter == 12 then Value else 0;
def Bar13 = if BarCounter == 13 then Value else 0;
def Bar14 = if BarCounter == 14 then Value else 0;
def Bar15 = if BarCounter == 15 then Value else 0;
def Bar16 = if BarCounter == 16 then Value else 0;
def Bar17 = if BarCounter == 17 then Value else 0;
def Bar18 = if BarCounter == 18 then Value else 0;
def Bar19 = if BarCounter == 19 then Value else 0;
def Bar20 = if BarCounter == 20 then Value else 0;
def Bar21 = if BarCounter == 21 then Value else 0;
def Bar22 = if BarCounter == 22 then Value else 0;
def Bar23 = if BarCounter == 23 then Value else 0;
def Bar24 = if BarCounter == 24 then Value else 0;
def Bar25 = if BarCounter == 25 then Value else 0;
def Bar26 = if BarCounter == 26 then Value else 0;
def Bar27 = if BarCounter == 27 then Value else 0;
def Bar28 = if BarCounter == 28 then Value else 0;
def Bar29 = if BarCounter == 29 then Value else 0;
def Bar30 = if BarCounter == 30 then Value else 0;
def Bar31 = if BarCounter == 31 then Value else 0;
def Bar32 = if BarCounter == 32 then Value else 0;
def Bar33 = if BarCounter == 33 then Value else 0;
def Bar34 = if BarCounter == 34 then Value else 0;
def Bar35 = if BarCounter == 35 then Value else 0;
def Bar36 = if BarCounter == 36 then Value else 0;
def Bar37 = if BarCounter == 37 then Value else 0;
def Bar38 = if BarCounter == 38 then Value else 0;
def Bar39 = if BarCounter == 39 then Value else 0;
def Bar40 = if BarCounter == 40 then Value else 0;
def Bar41 = if BarCounter == 41 then Value else 0;
def Bar42 = if BarCounter == 42 then Value else 0;
def Bar43 = if BarCounter == 43 then Value else 0;
def Bar44 = if BarCounter == 44 then Value else 0;
def Bar45 = if BarCounter == 45 then Value else 0;
def Bar46 = if BarCounter == 46 then Value else 0;
def Bar47 = if BarCounter == 47 then Value else 0;
def Bar48 = if BarCounter == 48 then Value else 0;
def Bar49 = if BarCounter == 49 then Value else 0;
def Bar50 = if BarCounter == 50 then Value else 0;
def Bar51 = if BarCounter == 51 then Value else 0;
def Bar52 = if BarCounter == 52 then Value else 0;
def Bar53 = if BarCounter == 53 then Value else 0;
def Bar54 = if BarCounter == 54 then Value else 0;
def Bar55 = if BarCounter == 55 then Value else 0;
def Bar56 = if BarCounter == 56 then Value else 0;
def Bar57 = if BarCounter == 57 then Value else 0;
def Bar58 = if BarCounter == 58 then Value else 0;
def Bar59 = if BarCounter == 59 then Value else 0;
def Bar60 = if BarCounter == 60 then Value else 0;
def Bar61 = if BarCounter == 61 then Value else 0;
def Bar62 = if BarCounter == 62 then Value else 0;
def Bar63 = if BarCounter == 63 then Value else 0;
def Bar64 = if BarCounter == 64 then Value else 0;
def Bar65 = if BarCounter == 65 then Value else 0;
def Bar66 = if BarCounter == 66 then Value else 0;
def Bar67 = if BarCounter == 67 then Value else 0;
def Bar68 = if BarCounter == 68 then Value else 0;
def Bar69 = if BarCounter == 69 then Value else 0;
def Bar70 = if BarCounter == 70 then Value else 0;
def Bar71 = if BarCounter == 71 then Value else 0;
def Bar72 = if BarCounter == 72 then Value else 0;
def Bar73 = if BarCounter == 73 then Value else 0;
def Bar74 = if BarCounter == 74 then Value else 0;
def Bar75 = if BarCounter == 75 then Value else 0;
def Bar76 = if BarCounter == 76 then Value else 0;
def Bar77 = if BarCounter == 77 then Value else 0;
def Bar78 = if BarCounter == 78 then Value else 0;


rec DayCounter = if SecondsTillTime(OpenTime) == 0 then 1 else 0;

def AvgBar1  = TotalSum(Bar1)  / TotalSum(DayCounter);
def AvgBar2  = TotalSum(Bar2)  / TotalSum(DayCounter);
def AvgBar3  = TotalSum(Bar3)  / TotalSum(DayCounter);
def AvgBar4  = TotalSum(Bar4)  / TotalSum(DayCounter);
def AvgBar5  = TotalSum(Bar5)  / TotalSum(DayCounter);
def AvgBar6  = TotalSum(Bar6)  / TotalSum(DayCounter);
def AvgBar7  = TotalSum(Bar7)  / TotalSum(DayCounter);
def AvgBar8  = TotalSum(Bar8)  / TotalSum(DayCounter);
def AvgBar9  = TotalSum(Bar9)  / TotalSum(DayCounter);
def AvgBar10 = TotalSum(Bar10) / TotalSum(DayCounter);
def AvgBar11 = TotalSum(Bar11) / TotalSum(DayCounter);
def AvgBar12 = TotalSum(Bar12) / TotalSum(DayCounter);
def AvgBar13 = TotalSum(Bar13) / TotalSum(DayCounter);
def AvgBar14 = TotalSum(Bar14) / TotalSum(DayCounter);
def AvgBar15 = TotalSum(Bar15) / TotalSum(DayCounter);
def AvgBar16 = TotalSum(Bar16) / TotalSum(DayCounter);
def AvgBar17 = TotalSum(Bar17) / TotalSum(DayCounter);
def AvgBar18 = TotalSum(Bar18) / TotalSum(DayCounter);
def AvgBar19 = TotalSum(Bar19) / TotalSum(DayCounter);
def AvgBar20 = TotalSum(Bar20) / TotalSum(DayCounter);
def AvgBar21 = TotalSum(Bar21) / TotalSum(DayCounter);
def AvgBar22 = TotalSum(Bar22) / TotalSum(DayCounter);
def AvgBar23 = TotalSum(Bar23) / TotalSum(DayCounter);
def AvgBar24 = TotalSum(Bar24) / TotalSum(DayCounter);
def AvgBar25 = TotalSum(Bar25) / TotalSum(DayCounter);
def AvgBar26 = TotalSum(Bar26) / TotalSum(DayCounter);
def AvgBar27 = TotalSum(Bar27) / TotalSum(DayCounter);
def AvgBar28 = TotalSum(Bar28) / TotalSum(DayCounter);
def AvgBar29 = TotalSum(Bar29) / TotalSum(DayCounter);
def AvgBar30 = TotalSum(Bar30) / TotalSum(DayCounter);
def AvgBar31 = TotalSum(Bar31) / TotalSum(DayCounter);
def AvgBar32 = TotalSum(Bar32) / TotalSum(DayCounter);
def AvgBar33 = TotalSum(Bar33) / TotalSum(DayCounter);
def AvgBar34 = TotalSum(Bar34) / TotalSum(DayCounter);
def AvgBar35 = TotalSum(Bar35) / TotalSum(DayCounter);
def AvgBar36 = TotalSum(Bar36) / TotalSum(DayCounter);
def AvgBar37 = TotalSum(Bar37) / TotalSum(DayCounter);
def AvgBar38 = TotalSum(Bar38) / TotalSum(DayCounter);
def AvgBar39 = TotalSum(Bar39) / TotalSum(DayCounter);
def AvgBar40 = TotalSum(Bar40) / TotalSum(DayCounter);
def AvgBar41 = TotalSum(Bar41) / TotalSum(DayCounter);
def AvgBar42 = TotalSum(Bar42) / TotalSum(DayCounter);
def AvgBar43 = TotalSum(Bar43) / TotalSum(DayCounter);
def AvgBar44 = TotalSum(Bar44) / TotalSum(DayCounter);
def AvgBar45 = TotalSum(Bar45) / TotalSum(DayCounter);
def AvgBar46 = TotalSum(Bar46) / TotalSum(DayCounter);
def AvgBar47 = TotalSum(Bar47) / TotalSum(DayCounter);
def AvgBar48 = TotalSum(Bar48) / TotalSum(DayCounter);
def AvgBar49 = TotalSum(Bar49) / TotalSum(DayCounter);
def AvgBar50 = TotalSum(Bar50) / TotalSum(DayCounter);
def AvgBar51 = TotalSum(Bar51) / TotalSum(DayCounter);
def AvgBar52 = TotalSum(Bar52) / TotalSum(DayCounter);
def AvgBar53 = TotalSum(Bar53) / TotalSum(DayCounter);
def AvgBar54 = TotalSum(Bar54) / TotalSum(DayCounter);
def AvgBar55 = TotalSum(Bar55) / TotalSum(DayCounter);
def AvgBar56 = TotalSum(Bar56) / TotalSum(DayCounter);
def AvgBar57 = TotalSum(Bar57) / TotalSum(DayCounter);
def AvgBar58 = TotalSum(Bar58) / TotalSum(DayCounter);
def AvgBar59 = TotalSum(Bar59) / TotalSum(DayCounter);
def AvgBar60 = TotalSum(Bar60) / TotalSum(DayCounter);
def AvgBar61 = TotalSum(Bar61) / TotalSum(DayCounter);
def AvgBar62 = TotalSum(Bar62) / TotalSum(DayCounter);
def AvgBar63 = TotalSum(Bar63) / TotalSum(DayCounter);
def AvgBar64 = TotalSum(Bar64) / TotalSum(DayCounter);
def AvgBar65 = TotalSum(Bar65) / TotalSum(DayCounter);
def AvgBar66 = TotalSum(Bar66) / TotalSum(DayCounter);
def AvgBar67 = TotalSum(Bar67) / TotalSum(DayCounter);
def AvgBar68 = TotalSum(Bar68) / TotalSum(DayCounter);
def AvgBar69 = TotalSum(Bar69) / TotalSum(DayCounter);
def AvgBar70 = TotalSum(Bar70) / TotalSum(DayCounter);
def AvgBar71 = TotalSum(Bar71) / TotalSum(DayCounter);
def AvgBar72 = TotalSum(Bar72) / TotalSum(DayCounter);
def AvgBar73 = TotalSum(Bar73) / TotalSum(DayCounter);
def AvgBar74 = TotalSum(Bar74) / TotalSum(DayCounter);
def AvgBar75 = TotalSum(Bar75) / TotalSum(DayCounter);
def AvgBar76 = TotalSum(Bar76) / TotalSum(DayCounter);
def AvgBar77 = TotalSum(Bar77) / TotalSum(DayCounter);
def AvgBar78 = TotalSum(Bar78) / TotalSum(DayCounter);

def AvgValue =
     if BarCounter == 1  then AvgBar1
else if BarCounter == 2  then AvgBar2
else if BarCounter == 3  then AvgBar3
else if BarCounter == 4  then AvgBar4
else if BarCounter == 5  then AvgBar5
else if BarCounter == 6  then AvgBar6
else if BarCounter == 7  then AvgBar7
else if BarCounter == 8  then AvgBar8
else if BarCounter == 9  then AvgBar9
else if BarCounter == 10 then AvgBar10
else if BarCounter == 11 then AvgBar11
else if BarCounter == 12 then AvgBar12
else if BarCounter == 13 then AvgBar13
else if BarCounter == 14 then AvgBar14
else if BarCounter == 15 then AvgBar15
else if BarCounter == 16 then AvgBar16
else if BarCounter == 17 then AvgBar17
else if BarCounter == 18 then AvgBar18
else if BarCounter == 19 then AvgBar19
else if BarCounter == 20 then AvgBar20
else if BarCounter == 21 then AvgBar21
else if BarCounter == 22 then AvgBar22
else if BarCounter == 23 then AvgBar23
else if BarCounter == 24 then AvgBar24
else if BarCounter == 25 then AvgBar25
else if BarCounter == 26 then AvgBar26
else if BarCounter == 27 then AvgBar27
else if BarCounter == 28 then AvgBar28
else if BarCounter == 29 then AvgBar29
else if BarCounter == 30 then AvgBar30
else if BarCounter == 31 then AvgBar31
else if BarCounter == 32 then AvgBar32
else if BarCounter == 33 then AvgBar33
else if BarCounter == 34 then AvgBar34
else if BarCounter == 35 then AvgBar35
else if BarCounter == 36 then AvgBar36
else if BarCounter == 37 then AvgBar37
else if BarCounter == 38 then AvgBar38
else if BarCounter == 39 then AvgBar39
else if BarCounter == 40 then AvgBar40
else if BarCounter == 41 then AvgBar41
else if BarCounter == 42 then AvgBar42
else if BarCounter == 43 then AvgBar43
else if BarCounter == 44 then AvgBar44
else if BarCounter == 45 then AvgBar45
else if BarCounter == 46 then AvgBar46
else if BarCounter == 47 then AvgBar47
else if BarCounter == 48 then AvgBar48
else if BarCounter == 49 then AvgBar49
else if BarCounter == 50 then AvgBar50
else if BarCounter == 51 then AvgBar51
else if BarCounter == 52 then AvgBar52
else if BarCounter == 53 then AvgBar53
else if BarCounter == 54 then AvgBar54
else if BarCounter == 55 then AvgBar55
else if BarCounter == 56 then AvgBar56
else if BarCounter == 57 then AvgBar57
else if BarCounter == 58 then AvgBar58
else if BarCounter == 59 then AvgBar59
else if BarCounter == 60 then AvgBar60
else if BarCounter == 61 then AvgBar61
else if BarCounter == 62 then AvgBar62
else if BarCounter == 63 then AvgBar63
else if BarCounter == 64 then AvgBar64
else if BarCounter == 65 then AvgBar65
else if BarCounter == 66 then AvgBar66
else if BarCounter == 67 then AvgBar67
else if BarCounter == 68 then AvgBar68
else if BarCounter == 69 then AvgBar69
else if BarCounter == 70 then AvgBar70
else if BarCounter == 71 then AvgBar71
else if BarCounter == 72 then AvgBar72
else if BarCounter == 73 then AvgBar73
else if BarCounter == 74 then AvgBar74
else if BarCounter == 75 then AvgBar75
else if BarCounter == 76 then AvgBar76
else if BarCounter == 77 then AvgBar77
else if BarCounter == 78 then AvgBar78
else Double.NaN;

def Data = (Value / AvgValue) * 100;
def Condition = BarNumber() == 1;

def NormalValueAreaPercent = 61.8;
profile DataProfileVA = DataProfile(data = Data, pricePerRow = PricePerRow.TICKSIZE, startNewProfile = Condition, onExpansion = No, "value area percent" = NormalValueAreaPercent);
def VAH = DataProfileVA.GetHighestValueArea();
def VAL = DataProfileVA.GetLowestValueArea();

def MaxValueAreaPercent = 95;
profile DataProfileMax = DataProfile(data = Data, pricePerRow = PricePerRow.tICKSIZE, startNewProfile = Condition, onExpansion = No, "value area percent" = MaxValueAreaPercent);
def MaxVAH = DataProfileMax.GetHighestValueArea();

def CumulativeRelativeBarValue = if SecondsTillTime(OpenTime) == 0 and GetYYYYMMDD() != DSTSpringForwardDate then (Value / AvgValue) * 100 else if SecondsTillTime(DSTSpringForwardOpenTime) == 0 and GetYYYYMMDD() == DSTSpringForwardDate then (Value / AvgValue) * 100 else CumulativeRelativeBarValue[1] + ((Value / AvgValue) * 100);

def AvgCumulativeRelativeBarValueRawData = Round(CumulativeRelativeBarValue / BarCounter, 0);

plot AvgCumulativeRelativeBarValue = if AvgCumulativeRelativeBarValueRawData > MaxVAH then MaxVAH else AvgCumulativeRelativeBarValueRawData;
AvgCumulativeRelativeBarValue.SetLineWeight(2);
AvgCumulativeRelativeBarValue.HideBubble();
AvgCumulativeRelativeBarValue.SetDefaultColor(Color.white);
#AvgCumulativeRelativeBarValue.SetHiding(!ShowAvgCumRelBarValue);
AddChartBubble(SecondsTillTime(CloseBarTime) == 0, AvgCumulativeRelativeBarValue, AvgCumulativeRelativeBarValueRawData, if AvgCumulativeRelativeBarValueRawData > MaxVAH then Color.DARK_ORANGE else Color.LIGHT_GRAY, if AvgCumulativeRelativeBarValueRawData > VAH then No else Yes);

plot RelativeBarValue = if Round((Value / AvgValue) * 100, 0) > MaxVAH then MaxVAH else Round((Value / AvgValue) * 100, 0);
RelativeBarValue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelativeBarValue.SetLineWeight(3);
RelativeBarValue.HideBubble();

RelativeBarValue.AssignValueColor(
     if close > open and RelativeBarValue >= VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.GREEN
else if close > open and relativeBarValue >= VAH and RelativeBarValue < avgcumulativeRelativeBarValue then color.LIGHT_GREEN
else if close > open and relativeBarValue < VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.DARK_GREEN
else if close < open and RelativeBarValue >= VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.Red
else if close < open and relativeBarValue >= VAH and RelativeBarValue < avgcumulativeRelativeBarValue then color.LIGHT_Red
else if close < open and relativeBarValue < VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.DARK_RED
else if close == open and RelativeBarValue >= VAH then color.BLUE
else color.dark_GRAY);

plot ExtremeDot = if RelativeBarValue == MaxVAH then MaxVAH else Double.NaN;
ExtremeDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
ExtremeDot.SetLineWeight(5);
ExtremeDot.HideBubble();
ExtremeDot.SetDefaultColor(CreateColor(255, 255, 0));
ExtremeDot.HideTitle();

AddCloud(vah, val, Color.GRAY);
 
This code is from someone on this forum sometime ago, i modify it to my liking with lack thereof my coding skills ;) for 5 min chart.
However, I am more to a scalper mode recently and using 1-2 mins more often.
I would like the code to automatically recognize the time for example,
5 min = 78 bars
3 min = 130 bars
2 min = 195 bars
1 min = 390 bars

Can this be done by our master coder here?
Thank you.

Code:
declare lower;
declare hide_on_daily;

input ValueData = {
default "Volume",
        "Range",
        "Volume per Range",
        "Trades",
        "Trades per Range",
        "Volume per Trades"};
def Value;
def Range = if High - Low == 0 then TickSize() else High - Low;
switch (ValueData) {
case "Volume":
    Value = Volume;
case "Range":
    Value = Range;
case "Volume per Range":
    Value = Volume / Range;
case "Trades":
    Value = Tick_Count;
case "Trades per Range":
    Value = Tick_Count / Range;
case "Volume per Trades":
    Value = Volume / Tick_Count;}

input OpenTime = 930;
def DSTSpringForwardOpenTime = OpenTime - 100;
input CloseBarTime = 1600;
#hint DSTSpringForwardDate: If viewing futures with extended-hours trading sessions, enter "20200309" for 2020 or "20210315" for 2021. Otherwise enter "99999999".
input DSTSpringForwardDate = 20200309;
rec BarCounter = if SecondsTillTime(OpenTime) == 0 and GetYYYYMMDD() != DSTSpringForwardDate then 1 else if SecondsTillTime(DSTSpringForwardOpenTime) == 0 and GetYYYYMMDD() == DSTSpringForwardDate then 1 else BarCounter[1] + 1;

def Bar1  = if BarCounter == 1  then Value else 0;
def Bar2  = if BarCounter == 2  then Value else 0;
def Bar3  = if BarCounter == 3  then Value else 0;
def Bar4  = if BarCounter == 4  then Value else 0;
def Bar5  = if BarCounter == 5  then Value else 0;
def Bar6  = if BarCounter == 6  then Value else 0;
def Bar7  = if BarCounter == 7  then Value else 0;
def Bar8  = if BarCounter == 8  then Value else 0;
def Bar9  = if BarCounter == 9  then Value else 0;
def Bar10 = if BarCounter == 10 then Value else 0;
def Bar11 = if BarCounter == 11 then Value else 0;
def Bar12 = if BarCounter == 12 then Value else 0;
def Bar13 = if BarCounter == 13 then Value else 0;
def Bar14 = if BarCounter == 14 then Value else 0;
def Bar15 = if BarCounter == 15 then Value else 0;
def Bar16 = if BarCounter == 16 then Value else 0;
def Bar17 = if BarCounter == 17 then Value else 0;
def Bar18 = if BarCounter == 18 then Value else 0;
def Bar19 = if BarCounter == 19 then Value else 0;
def Bar20 = if BarCounter == 20 then Value else 0;
def Bar21 = if BarCounter == 21 then Value else 0;
def Bar22 = if BarCounter == 22 then Value else 0;
def Bar23 = if BarCounter == 23 then Value else 0;
def Bar24 = if BarCounter == 24 then Value else 0;
def Bar25 = if BarCounter == 25 then Value else 0;
def Bar26 = if BarCounter == 26 then Value else 0;
def Bar27 = if BarCounter == 27 then Value else 0;
def Bar28 = if BarCounter == 28 then Value else 0;
def Bar29 = if BarCounter == 29 then Value else 0;
def Bar30 = if BarCounter == 30 then Value else 0;
def Bar31 = if BarCounter == 31 then Value else 0;
def Bar32 = if BarCounter == 32 then Value else 0;
def Bar33 = if BarCounter == 33 then Value else 0;
def Bar34 = if BarCounter == 34 then Value else 0;
def Bar35 = if BarCounter == 35 then Value else 0;
def Bar36 = if BarCounter == 36 then Value else 0;
def Bar37 = if BarCounter == 37 then Value else 0;
def Bar38 = if BarCounter == 38 then Value else 0;
def Bar39 = if BarCounter == 39 then Value else 0;
def Bar40 = if BarCounter == 40 then Value else 0;
def Bar41 = if BarCounter == 41 then Value else 0;
def Bar42 = if BarCounter == 42 then Value else 0;
def Bar43 = if BarCounter == 43 then Value else 0;
def Bar44 = if BarCounter == 44 then Value else 0;
def Bar45 = if BarCounter == 45 then Value else 0;
def Bar46 = if BarCounter == 46 then Value else 0;
def Bar47 = if BarCounter == 47 then Value else 0;
def Bar48 = if BarCounter == 48 then Value else 0;
def Bar49 = if BarCounter == 49 then Value else 0;
def Bar50 = if BarCounter == 50 then Value else 0;
def Bar51 = if BarCounter == 51 then Value else 0;
def Bar52 = if BarCounter == 52 then Value else 0;
def Bar53 = if BarCounter == 53 then Value else 0;
def Bar54 = if BarCounter == 54 then Value else 0;
def Bar55 = if BarCounter == 55 then Value else 0;
def Bar56 = if BarCounter == 56 then Value else 0;
def Bar57 = if BarCounter == 57 then Value else 0;
def Bar58 = if BarCounter == 58 then Value else 0;
def Bar59 = if BarCounter == 59 then Value else 0;
def Bar60 = if BarCounter == 60 then Value else 0;
def Bar61 = if BarCounter == 61 then Value else 0;
def Bar62 = if BarCounter == 62 then Value else 0;
def Bar63 = if BarCounter == 63 then Value else 0;
def Bar64 = if BarCounter == 64 then Value else 0;
def Bar65 = if BarCounter == 65 then Value else 0;
def Bar66 = if BarCounter == 66 then Value else 0;
def Bar67 = if BarCounter == 67 then Value else 0;
def Bar68 = if BarCounter == 68 then Value else 0;
def Bar69 = if BarCounter == 69 then Value else 0;
def Bar70 = if BarCounter == 70 then Value else 0;
def Bar71 = if BarCounter == 71 then Value else 0;
def Bar72 = if BarCounter == 72 then Value else 0;
def Bar73 = if BarCounter == 73 then Value else 0;
def Bar74 = if BarCounter == 74 then Value else 0;
def Bar75 = if BarCounter == 75 then Value else 0;
def Bar76 = if BarCounter == 76 then Value else 0;
def Bar77 = if BarCounter == 77 then Value else 0;
def Bar78 = if BarCounter == 78 then Value else 0;


rec DayCounter = if SecondsTillTime(OpenTime) == 0 then 1 else 0;

def AvgBar1  = TotalSum(Bar1)  / TotalSum(DayCounter);
def AvgBar2  = TotalSum(Bar2)  / TotalSum(DayCounter);
def AvgBar3  = TotalSum(Bar3)  / TotalSum(DayCounter);
def AvgBar4  = TotalSum(Bar4)  / TotalSum(DayCounter);
def AvgBar5  = TotalSum(Bar5)  / TotalSum(DayCounter);
def AvgBar6  = TotalSum(Bar6)  / TotalSum(DayCounter);
def AvgBar7  = TotalSum(Bar7)  / TotalSum(DayCounter);
def AvgBar8  = TotalSum(Bar8)  / TotalSum(DayCounter);
def AvgBar9  = TotalSum(Bar9)  / TotalSum(DayCounter);
def AvgBar10 = TotalSum(Bar10) / TotalSum(DayCounter);
def AvgBar11 = TotalSum(Bar11) / TotalSum(DayCounter);
def AvgBar12 = TotalSum(Bar12) / TotalSum(DayCounter);
def AvgBar13 = TotalSum(Bar13) / TotalSum(DayCounter);
def AvgBar14 = TotalSum(Bar14) / TotalSum(DayCounter);
def AvgBar15 = TotalSum(Bar15) / TotalSum(DayCounter);
def AvgBar16 = TotalSum(Bar16) / TotalSum(DayCounter);
def AvgBar17 = TotalSum(Bar17) / TotalSum(DayCounter);
def AvgBar18 = TotalSum(Bar18) / TotalSum(DayCounter);
def AvgBar19 = TotalSum(Bar19) / TotalSum(DayCounter);
def AvgBar20 = TotalSum(Bar20) / TotalSum(DayCounter);
def AvgBar21 = TotalSum(Bar21) / TotalSum(DayCounter);
def AvgBar22 = TotalSum(Bar22) / TotalSum(DayCounter);
def AvgBar23 = TotalSum(Bar23) / TotalSum(DayCounter);
def AvgBar24 = TotalSum(Bar24) / TotalSum(DayCounter);
def AvgBar25 = TotalSum(Bar25) / TotalSum(DayCounter);
def AvgBar26 = TotalSum(Bar26) / TotalSum(DayCounter);
def AvgBar27 = TotalSum(Bar27) / TotalSum(DayCounter);
def AvgBar28 = TotalSum(Bar28) / TotalSum(DayCounter);
def AvgBar29 = TotalSum(Bar29) / TotalSum(DayCounter);
def AvgBar30 = TotalSum(Bar30) / TotalSum(DayCounter);
def AvgBar31 = TotalSum(Bar31) / TotalSum(DayCounter);
def AvgBar32 = TotalSum(Bar32) / TotalSum(DayCounter);
def AvgBar33 = TotalSum(Bar33) / TotalSum(DayCounter);
def AvgBar34 = TotalSum(Bar34) / TotalSum(DayCounter);
def AvgBar35 = TotalSum(Bar35) / TotalSum(DayCounter);
def AvgBar36 = TotalSum(Bar36) / TotalSum(DayCounter);
def AvgBar37 = TotalSum(Bar37) / TotalSum(DayCounter);
def AvgBar38 = TotalSum(Bar38) / TotalSum(DayCounter);
def AvgBar39 = TotalSum(Bar39) / TotalSum(DayCounter);
def AvgBar40 = TotalSum(Bar40) / TotalSum(DayCounter);
def AvgBar41 = TotalSum(Bar41) / TotalSum(DayCounter);
def AvgBar42 = TotalSum(Bar42) / TotalSum(DayCounter);
def AvgBar43 = TotalSum(Bar43) / TotalSum(DayCounter);
def AvgBar44 = TotalSum(Bar44) / TotalSum(DayCounter);
def AvgBar45 = TotalSum(Bar45) / TotalSum(DayCounter);
def AvgBar46 = TotalSum(Bar46) / TotalSum(DayCounter);
def AvgBar47 = TotalSum(Bar47) / TotalSum(DayCounter);
def AvgBar48 = TotalSum(Bar48) / TotalSum(DayCounter);
def AvgBar49 = TotalSum(Bar49) / TotalSum(DayCounter);
def AvgBar50 = TotalSum(Bar50) / TotalSum(DayCounter);
def AvgBar51 = TotalSum(Bar51) / TotalSum(DayCounter);
def AvgBar52 = TotalSum(Bar52) / TotalSum(DayCounter);
def AvgBar53 = TotalSum(Bar53) / TotalSum(DayCounter);
def AvgBar54 = TotalSum(Bar54) / TotalSum(DayCounter);
def AvgBar55 = TotalSum(Bar55) / TotalSum(DayCounter);
def AvgBar56 = TotalSum(Bar56) / TotalSum(DayCounter);
def AvgBar57 = TotalSum(Bar57) / TotalSum(DayCounter);
def AvgBar58 = TotalSum(Bar58) / TotalSum(DayCounter);
def AvgBar59 = TotalSum(Bar59) / TotalSum(DayCounter);
def AvgBar60 = TotalSum(Bar60) / TotalSum(DayCounter);
def AvgBar61 = TotalSum(Bar61) / TotalSum(DayCounter);
def AvgBar62 = TotalSum(Bar62) / TotalSum(DayCounter);
def AvgBar63 = TotalSum(Bar63) / TotalSum(DayCounter);
def AvgBar64 = TotalSum(Bar64) / TotalSum(DayCounter);
def AvgBar65 = TotalSum(Bar65) / TotalSum(DayCounter);
def AvgBar66 = TotalSum(Bar66) / TotalSum(DayCounter);
def AvgBar67 = TotalSum(Bar67) / TotalSum(DayCounter);
def AvgBar68 = TotalSum(Bar68) / TotalSum(DayCounter);
def AvgBar69 = TotalSum(Bar69) / TotalSum(DayCounter);
def AvgBar70 = TotalSum(Bar70) / TotalSum(DayCounter);
def AvgBar71 = TotalSum(Bar71) / TotalSum(DayCounter);
def AvgBar72 = TotalSum(Bar72) / TotalSum(DayCounter);
def AvgBar73 = TotalSum(Bar73) / TotalSum(DayCounter);
def AvgBar74 = TotalSum(Bar74) / TotalSum(DayCounter);
def AvgBar75 = TotalSum(Bar75) / TotalSum(DayCounter);
def AvgBar76 = TotalSum(Bar76) / TotalSum(DayCounter);
def AvgBar77 = TotalSum(Bar77) / TotalSum(DayCounter);
def AvgBar78 = TotalSum(Bar78) / TotalSum(DayCounter);

def AvgValue =
     if BarCounter == 1  then AvgBar1
else if BarCounter == 2  then AvgBar2
else if BarCounter == 3  then AvgBar3
else if BarCounter == 4  then AvgBar4
else if BarCounter == 5  then AvgBar5
else if BarCounter == 6  then AvgBar6
else if BarCounter == 7  then AvgBar7
else if BarCounter == 8  then AvgBar8
else if BarCounter == 9  then AvgBar9
else if BarCounter == 10 then AvgBar10
else if BarCounter == 11 then AvgBar11
else if BarCounter == 12 then AvgBar12
else if BarCounter == 13 then AvgBar13
else if BarCounter == 14 then AvgBar14
else if BarCounter == 15 then AvgBar15
else if BarCounter == 16 then AvgBar16
else if BarCounter == 17 then AvgBar17
else if BarCounter == 18 then AvgBar18
else if BarCounter == 19 then AvgBar19
else if BarCounter == 20 then AvgBar20
else if BarCounter == 21 then AvgBar21
else if BarCounter == 22 then AvgBar22
else if BarCounter == 23 then AvgBar23
else if BarCounter == 24 then AvgBar24
else if BarCounter == 25 then AvgBar25
else if BarCounter == 26 then AvgBar26
else if BarCounter == 27 then AvgBar27
else if BarCounter == 28 then AvgBar28
else if BarCounter == 29 then AvgBar29
else if BarCounter == 30 then AvgBar30
else if BarCounter == 31 then AvgBar31
else if BarCounter == 32 then AvgBar32
else if BarCounter == 33 then AvgBar33
else if BarCounter == 34 then AvgBar34
else if BarCounter == 35 then AvgBar35
else if BarCounter == 36 then AvgBar36
else if BarCounter == 37 then AvgBar37
else if BarCounter == 38 then AvgBar38
else if BarCounter == 39 then AvgBar39
else if BarCounter == 40 then AvgBar40
else if BarCounter == 41 then AvgBar41
else if BarCounter == 42 then AvgBar42
else if BarCounter == 43 then AvgBar43
else if BarCounter == 44 then AvgBar44
else if BarCounter == 45 then AvgBar45
else if BarCounter == 46 then AvgBar46
else if BarCounter == 47 then AvgBar47
else if BarCounter == 48 then AvgBar48
else if BarCounter == 49 then AvgBar49
else if BarCounter == 50 then AvgBar50
else if BarCounter == 51 then AvgBar51
else if BarCounter == 52 then AvgBar52
else if BarCounter == 53 then AvgBar53
else if BarCounter == 54 then AvgBar54
else if BarCounter == 55 then AvgBar55
else if BarCounter == 56 then AvgBar56
else if BarCounter == 57 then AvgBar57
else if BarCounter == 58 then AvgBar58
else if BarCounter == 59 then AvgBar59
else if BarCounter == 60 then AvgBar60
else if BarCounter == 61 then AvgBar61
else if BarCounter == 62 then AvgBar62
else if BarCounter == 63 then AvgBar63
else if BarCounter == 64 then AvgBar64
else if BarCounter == 65 then AvgBar65
else if BarCounter == 66 then AvgBar66
else if BarCounter == 67 then AvgBar67
else if BarCounter == 68 then AvgBar68
else if BarCounter == 69 then AvgBar69
else if BarCounter == 70 then AvgBar70
else if BarCounter == 71 then AvgBar71
else if BarCounter == 72 then AvgBar72
else if BarCounter == 73 then AvgBar73
else if BarCounter == 74 then AvgBar74
else if BarCounter == 75 then AvgBar75
else if BarCounter == 76 then AvgBar76
else if BarCounter == 77 then AvgBar77
else if BarCounter == 78 then AvgBar78
else Double.NaN;

def Data = (Value / AvgValue) * 100;
def Condition = BarNumber() == 1;

def NormalValueAreaPercent = 61.8;
profile DataProfileVA = DataProfile(data = Data, pricePerRow = PricePerRow.TICKSIZE, startNewProfile = Condition, onExpansion = No, "value area percent" = NormalValueAreaPercent);
def VAH = DataProfileVA.GetHighestValueArea();
def VAL = DataProfileVA.GetLowestValueArea();

def MaxValueAreaPercent = 95;
profile DataProfileMax = DataProfile(data = Data, pricePerRow = PricePerRow.tICKSIZE, startNewProfile = Condition, onExpansion = No, "value area percent" = MaxValueAreaPercent);
def MaxVAH = DataProfileMax.GetHighestValueArea();

def CumulativeRelativeBarValue = if SecondsTillTime(OpenTime) == 0 and GetYYYYMMDD() != DSTSpringForwardDate then (Value / AvgValue) * 100 else if SecondsTillTime(DSTSpringForwardOpenTime) == 0 and GetYYYYMMDD() == DSTSpringForwardDate then (Value / AvgValue) * 100 else CumulativeRelativeBarValue[1] + ((Value / AvgValue) * 100);

def AvgCumulativeRelativeBarValueRawData = Round(CumulativeRelativeBarValue / BarCounter, 0);

plot AvgCumulativeRelativeBarValue = if AvgCumulativeRelativeBarValueRawData > MaxVAH then MaxVAH else AvgCumulativeRelativeBarValueRawData;
AvgCumulativeRelativeBarValue.SetLineWeight(2);
AvgCumulativeRelativeBarValue.HideBubble();
AvgCumulativeRelativeBarValue.SetDefaultColor(Color.white);
#AvgCumulativeRelativeBarValue.SetHiding(!ShowAvgCumRelBarValue);
AddChartBubble(SecondsTillTime(CloseBarTime) == 0, AvgCumulativeRelativeBarValue, AvgCumulativeRelativeBarValueRawData, if AvgCumulativeRelativeBarValueRawData > MaxVAH then Color.DARK_ORANGE else Color.LIGHT_GRAY, if AvgCumulativeRelativeBarValueRawData > VAH then No else Yes);

plot RelativeBarValue = if Round((Value / AvgValue) * 100, 0) > MaxVAH then MaxVAH else Round((Value / AvgValue) * 100, 0);
RelativeBarValue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RelativeBarValue.SetLineWeight(3);
RelativeBarValue.HideBubble();

RelativeBarValue.AssignValueColor(
     if close > open and RelativeBarValue >= VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.GREEN
else if close > open and relativeBarValue >= VAH and RelativeBarValue < avgcumulativeRelativeBarValue then color.LIGHT_GREEN
else if close > open and relativeBarValue < VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.DARK_GREEN
else if close < open and RelativeBarValue >= VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.Red
else if close < open and relativeBarValue >= VAH and RelativeBarValue < avgcumulativeRelativeBarValue then color.LIGHT_Red
else if close < open and relativeBarValue < VAH and RelativeBarValue >= avgcumulativeRelativeBarValue then color.DARK_RED
else if close == open and RelativeBarValue >= VAH then color.BLUE
else color.dark_GRAY);

plot ExtremeDot = if RelativeBarValue == MaxVAH then MaxVAH else Double.NaN;
ExtremeDot.SetPaintingStrategy(PaintingStrategy.SQUARES);
ExtremeDot.SetLineWeight(5);
ExtremeDot.HideBubble();
ExtremeDot.SetDefaultColor(CreateColor(255, 255, 0));
ExtremeDot.HideTitle();

AddCloud(vah, val, Color.GRAY);

i'm not familiar with futures and not quite sure what your date variables are doing, but,
maybe looking at this code will give you some ideas. it reads data from 1 bar a day, for several days.
https://usethinkscript.com/threads/intraday-relative-volume-rvol-for-thinkorswim.16051/
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
236 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top