Strategy Code (Required Function is below)
Inputs: size(10000), sshort(1), bLev(50), tvlev(.05), tvlb(20); Vars: RS(0), NP(0); RS = RSI(C,14); if RS crosses above bLev then buy (tv(tvlev,tvlb) data2 * size) / c shares next bar market; if sshort = 0 then begin if RS crosses below bLev then sell next bar market; end; if sshort = 1 then begin if RS crosses below bLev then sellshort (tv(tvlev,tvlb) data2 * size) / c shares next bar market; end;
Target Volatility Function
Inputs: TargetVolatility(Numeric), HVlookback(Numeric); Vars: Allocation(0), HistoricalVolatility(0); HistoricalVolatility = standarddev( (c - c[1]) / c[1], HVlookback, 1) * Squareroot(252) ; if HistoricalVolatility > TargetVolatility then Allocation = TargetVolatility / HistoricalVolatility else Allocation = 1.00 ; TV = Allocation;