Distance Oscillator Strategy- evo
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EvoCrypto

//@version=4
strategy("Distance Oscillator Strategy- evo", shorttitle="Distance Oscillator Strategy")

// INPUTS {
na_1                =   input(false,    title="────────────{ Oscillator }──────────────")

// Osc_Src             =   input(close,    title="Oscillator Source                                ")

Example_Length      =   input(20,       title="Example Length", minval=1)
Osc_Src             =   (highest(Example_Length) + lowest(Example_Length)) / 2

// Strategy can not let you choose a Moving Average to connect with like the study version, so I use the MA above as example

Osc_Format          =   input("Percent",title="Oscillator Format",              options=["Percent", "Currency"]) 

na_2                =   input(false,    title="─────────────{ Average }──────────────")
Average_Type        =   input("Hull",   title="Average Type",                   options=["Hull", "Sma", "Ema", "Wma"])
Length              =   input(50,       title="Average Length", minval=1)
Lagg                =   input(12,       title="Average Lagg",   minval=1)
Display_MA          =   input(true,     title="Display Average")
// }

// SETTINGS {
Osc_Sum             =   
 Osc_Format == "Percent"  ? (close - Osc_Src) / close * 100 :
 Osc_Format == "Currency" ? (close - Osc_Src)               : na

Osc_MA              =   Display_MA == false ? na:
 Average_Type == "Hull"? hma(Osc_Sum, Length)   :
 Average_Type == "Sma" ? sma(Osc_Sum, Length)   :
 Average_Type == "Ema" ? ema(Osc_Sum, Length)   :
 Average_Type == "Wma" ? wma(Osc_Sum, Length)   : na
Osc_MA_1            =   Osc_MA[Lagg]

Cross_Up            =   crossover( Osc_MA, Osc_MA_1)
Cross_Down          =   crossunder(Osc_MA, Osc_MA_1)

Osc_Color           =   Osc_Sum > 0         ? color.new(#bbdefb, 70)  : Osc_Sum < 0          ? color.new(#000000, 70)  : na
Average_Color       =   Osc_MA  > Osc_MA_1  ? color.new(#311b92, 100) : Osc_MA  < Osc_MA_1   ? color.new(#b71c1c, 100) : na
// }

// PLOT {
plot(Osc_Sum,                           title="Oscillator", color=Osc_Color, style=plot.style_histogram, linewidth=2)

Plot_0              =   plot(Osc_MA,    title="Osc Average",color=#b71c1c, linewidth=2)
Plot_1              =   plot(Osc_MA_1,  title="Osc Average",color=#311b92, linewidth=2)
fill(Plot_0, Plot_1,                    title="Average",    color=Average_Color)

plotshape(Cross_Up   ? Osc_MA_1 : na,   title="Cross Up",   color=#bbdefb, location=location.absolute, size=size.tiny, style=shape.circle)
plotshape(Cross_Down ? Osc_MA_1 : na,   title="Cross Down", color=#000000, location=location.absolute, size=size.tiny, style=shape.circle)
// }

// STRATEGY {
if (Cross_Up)
    strategy.entry("Long", strategy.long)
if (Cross_Down)
    strategy.entry("Short", strategy.short)
// }