I almost always use the built in Ninjascript editor unless actively debugging an issue. The code below will compile as an indicator. The lines marked <Modified>
are the only lines I changed/added.
BTW... Your original code is very similar to the Ninjatrader built in DonchainChannel indicator.