Harmonic System Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ceyhun

//@version=4
strategy("Harmonic System Strategy", overlay=true)

harm_average(x,y,z) =>3 / (1 / x + 1 / y + 1 / z)
T1 = harm_average(close[1], close[2], close[3])
T2 = harm_average(T1, T1[1], T1[2])
T3 = harm_average(T2, T2[1], T2[2])
T4 = harm_average(T3, T3[1], T3[2])
T5 = harm_average(T4, T4[1], T4[2])
T6 = harm_average(T5, T5[1], T5[2])
Balance = 18 / (1 / T1 * 3 + 1 / T2 * 3 + 1 / T3 * 3 + 1 / T4 * 3 + 1 / T5 * 3 + 1 / T6 * 3)

plot(T1,linewidth=2, color=color.green,title="T1")
plot(T2,linewidth=1, color=color.blue,title="T2")
plot(T3,linewidth=1, color=color.blue,title="T3")
plot(Balance,linewidth=2, color=color.black,title="Balance")
plot(T4,linewidth=1, color=color.blue,title="T4")
plot(T5,linewidth=1, color=color.blue,title="T5")
plot(T6,linewidth=2, color=color.red,title="T6")

X1 = min(min(T1,T2),T3)
X2 = max(max(T4,T5),T6)
X3 = min(T1,T2)
X4 = max(T3,T4)

Buy=crossover(X1,X2)
Sell=crossunder(X3,X4)

if crossover(X1,X2)
    strategy.entry("Long", strategy.long, comment="Long")

if crossunder(X3,X4)
    strategy.entry("Short", strategy.short, comment="Short")
