The code by Ehlers is ok. Period is declared under "Vars", and is 0 as long as no other value is assigned.
However a sine wave indicator is much simpler. You only need the sine of the dominant phase plus an offset:
var LeadSine = sin(DominantPhase(Price,30)+PI/4);