Essential: Stochastic Discovery

inputs: 
     PriceH( High ) [
         DisplayName = "PriceH", 
         ToolTip = "Price High.  Enter the High value to use in the Stochastics calculations."],  
 PriceL( Low ) [     DisplayName = "PriceL",      ToolTip = "Price Low.  Enter the Low value to use in the Stochastics calculations."],  PriceC( Close ) [     DisplayName = "PriceC",      ToolTip = "Price Close.  Enter the current price value to use in the Stochastics calculations."],  StochLength( 14 ) [     DisplayName = "StochLength",      ToolTip = "Stochastic Length.  Enter the length used in the stochastic calculations."],  SmoothingLength1( 3 ) [     DisplayName = "SmoothingLength1",      ToolTip = "Enter number of bars to use in the moving average of the FastK values."], SmoothingLength2( 3 ) [     DisplayName = "SmoothingLength2",      ToolTip = "Enter number of bars to use in the moving average of the FastD values."], SmoothingType( 1 ) [     DisplayName = "SmoothingType",      ToolTip = "Enter the smoothing type to use.  Enter 1 for Original (simple average), 2 for Legacy (exponential smoothing)."], OverSold( 20 ) [     DisplayName = "OverSold",      ToolTip = "Enter the level of the indicator at which you consider the market to be oversold (too low)."],  OverBought( 80 ) [     DisplayName = "OverBought",      ToolTip = "Enter the level of the indicator at which you consider the market to be overbought (too high)."], 
 KD("K"),
 lLevel(20),
 hLevel(80);
 Vars:
     ReturnValue( 0 ),
     oFastK( 0 ), 
     oFastD( 0 ), 
     oSlowK( 0 ), 
     oSlowD( 0 ),
     Ind(0);
 ReturnValue = Stochastic( PriceH, PriceL, PriceC, StochLength, SmoothingLength1, 
  SmoothingLength2, SmoothingType, oFastK, oFastD, oSlowK, oSlowD );
 Ind = oSlowK;
 if c > average(c,200) and Ind crosses above lLevel then buy 10000/c shares next bar market; 
 if ind crosses below lLevel then sell next bar market;
 if Ind crosses below hLevel then sell next bar market;