D

#### Dixon72

##### New member

**VIP**

declare upper;

input period = AggregationPeriod.DAY;

input over_bought = 80;

input over_sold = 20;

input KPeriod = 5;

input DPeriod = 3;

input slowing_period = 3;

input priceH = high;

input priceL = low;

input priceC = close;

input aP = AggregationPeriod.DAY;

input averageType = AverageType.SIMPLE;

DefineGlobalColor("CrossDown", Color.GREEN);

DefineGlobalColor("CrossUp", Color.RED);

script SymbolStochastic {

def CrossUp = FullK >= FullD;

def CrossDown = FullK < FullD;

def lowest_k = Lowest(priceL, KPeriod);

def c1 = priceC – lowest_k;

def c2 = Highest(priceH, KPeriod) – lowest_k;

def FastK = if c2 != 0 then c1 / c2 * 100 else 0;

def FullK = MovingAverage(averageType, FastK, slowing_period);

def FullD = MovingAverage(averageType, FullK, DPeriod);

def currentPeriod = GetAggregationPeriod();

if period >= currentPeriod {

s1 = SymbolStochastic(aP = period);

} else {

s1 = Double.NaN;

}

AddLabel(!IsNaN(s1), if period == AggregationPeriod.MONTH then "M" else

if period == AggregationPeriod.WEEK then "W" else

if period == AggregationPeriod.FOUR_DAYS then "4D" else

if period == AggregationPeriod.THREE_DAYS then "3D" else

if period == AggregationPeriod.TWO_DAYS then "2D" else

if period == AggregationPeriod.DAY then "D" else

if period == AggregationPeriod.FOUR_HOURS then "4H" else

if period == AggregationPeriod.TWO_HOURS then "2H" else

if period == AggregationPeriod.HOUR then "60m" else

if period == AggregationPeriod.THIRTY_MIN then "30m" else

if period == AggregationPeriod.TWENTY_MIN then "20m" else

if period == AggregationPeriod.FIFTEEN_MIN then "15m" else

if period == AggregationPeriod.TEN_MIN then "10m" else

if period == AggregationPeriod.FIVE_MIN then "5m" else

if period == AggregationPeriod.FOUR_MIN then "4m" else

if period == AggregationPeriod.THREE_MIN then "3m" else

if period == AggregationPeriod.TWO_MIN then "2m" else

if period == AggregationPeriod.MIN then "1m"

else "", if s1 > 0 then GlobalColor("CrossUp") else GlobalColor("CrossDown"));