Wilder’s Moving Average Strategy
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dongyun

//@version=4
strategy("Wilder’s Moving Average Strategy", overlay=true)

malength = input(36, "length", minval=1)

longd = false
shortd = false
lineColor = color.yellow
wild = 0.0

wild := nz(wild[1]) + (close -nz(wild[1]))/malength

longd := wild > wild[1]

shortd := wild < wild[1]

lineColor := longd ? color.green : shortd ? color.red : color.yellow

plot(wild, color=lineColor, linewidth=2, title="WILD")

if longd
    strategy.entry("long", strategy.long, when = strategy.position_size <= 0)
else
    if shortd
        strategy.entry("short", strategy.short, when = strategy.position_size >= 0)