Body- and Shadowsizes
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © martinislichten

//@version=5
indicator("Mein Skript")

//Init of variables
float ls = 0
float bd = 0
float us = 0

float ls1 = 0
float bd1 = 0
float us1 = 0

float tra1 = 0
float tra2 = 0
float tra3 = 0

length = input.int(100, 'lookback', minval = 1) //Length of Lookback for Calculation
length1 = input.int(2001, 'lookback1', minval = 1) //Length of Lookback for Comparison
deltalookback = input.int (20, "deltalookback", minval = 3) //Length of Lookback for Delta-Calculation

//Calculation of Shadow and Body Sizes for wanted length
for i = 0 to length - 1
    if close[i] < open[i]
        ls += close[i] - low[i]
        bd += open[i] - close[i]
        us += high[i] - open[i]
        
    else if close[i] > open[i]
        ls += open[i] - low[i]
        bd += close[i] - open[i]
        us += high[i] - close[i]

//Calculation of Shadow and Body Sizes for compared length
for j = 0 to length1 - 1
    if close[j] < open[j]
        ls1 += close[j] - low[j]
        bd1 += open[j] - close[j]
        us1 += high[j] - open[j]
        
    else if close[j] > open[j]
        ls1 += open[j] - low[j]
        bd1 += close[j] - open[j]
        us1 += high[j] - close[j]

ta.pivothigh(length,0)

//Relation of the bigger to the smaller Lookback, so that the same amount of candles will be compared later on 
//Verhältnis der zwei Lookbacks, sodass gleiche Zeiträume miteinander verglichen werden
float verhlengthes1 = length1/length

//Average of the comparing lookback, adjusted to amount of candles of the bigger one
//Durschnitt der jeweiligen Größen angepasst auf die kürzere Länge
avgLS1 = ls1/verhlengthes1
avgBS1 = bd1/verhlengthes1
avgUS1 = us1/verhlengthes1

//Differences of shadow and bodysizes
for f = 0 to deltalookback - 1
    tra1 += ls[f] - ls[f + 1]

for f = 0 to deltalookback - 1
    tra2 += bd[f] - bd[f + 1]

for f = 0 to deltalookback - 1
    tra3 += us[f] - us[f + 1]


//plot
//Zeichnen
plot(ls,"Lower Shadow Size", color = color.red)
plot(bd,"Body Size", color = color.yellow, linewidth = 3)
plot(us,"Upper Shadow Size", color = color.green)

plot(avgLS1,"Average Lower Shadow Size", color = color.blue)
plot(avgBS1,"Average Body Size", color = color.purple, linewidth = 3)
plot(avgUS1,"Average Upper Shadow Size", color = color.navy)

plot(ls1,"Lower Shadow Size To Compare", color = color.black)
plot(bd1,"Body Size To Compare", color = color.lime, linewidth = 3)
plot(us1,"Upper Shadow Size To Compare", color = color.silver)

plot(tra1,"Delta of Lower Shadows", color = color.orange)
plot(tra2,"Delta of Bodies", color = color.aqua)
plot(tra3,"Delta of Higher Shadows", color = color.teal)

//plot(close)
