stocksniper
Member
Hey guys, this is a really good oscillator one of my favorites, can someone help me adding arrows on the study. Thanks so much in advance.
Code:
#hint:<b>Three X Stochastic Oscillator</b>
# Title = Three_X_Oscillator
# Richard Houser created this 3X Oscillator code on the Yahoo ThinkScript forum
# Stochastic calculated using Lane's formulas in favor over TOS' (has issues)
declare lower;
input Use_OB_OS = yes;#hint Use_OB_OS:<b>Show OverBought/OverSold lines.</b>\n Is alternate to using HH/LL lines.
input Use_HH_LL = no;#hint Use_HH_LL:<b>Show Highest/Lowest actual value lines.</b>\n Is alternate to using OB/OS lines.
input show40_60 = no;#hint show40_60:Yes shows the 40 & 60 lines
input K_period = 21;
input D_period = 9;
input SlowTrendLength = 3;
input smoothing_type = { default EMA, SMA };
input stochastic_type = { FAST, default SLOW };
input over_bought = 80;#hint over_bought:This can be replaced by the line of the highest actual value
input over_sold = 20;#hint over_sold:This can replaced by the line of the lowest actual value
Plot OB = If Use_OB_OS then over_bought else double.nan;
OB.SetLineWeight(1);
OB.SetDefaultColor(Color.yellow);
Plot OS = If Use_OB_OS then over_sold else double.nan;
OS.SetLineWeight(1);
OS.SetDefaultColor(Color.yellow);
plot Mid = 50;
mid.SetStyle(Curve.LONG_DASH);
mid.SetLineWeight(2);
mid.SetDefaultColor(Color.pink);
plot Mid_h = If show40_60 then 60 else Double.nan ;
Mid_h.SetStyle(Curve.SHORT_DASH);
Mid_h.SetLineWeight(1);
Mid_h .SetDefaultColor(Color.pink);
Mid_H.Hidebubble();
plot Mid_L = If show40_60 then 40 else Double.nan ;
Mid_L.SetStyle(Curve.SHORT_DASH);
Mid_L.SetLineWeight(1);
Mid_L.SetDefaultColor(Color.pink);
Mid_L.Hidebubble();
def aggPer = GetAggregationPeriod();
def adjAggPer = if aggPer == AggregationPeriod.MIN then
AggregationPeriod.THREE_MIN
else if aggPer == AggregationPeriod.TWO_MIN then
AggregationPeriod.FIVE_MIN
else if aggPer == AggregationPeriod.THREE_MIN then
AggregationPeriod.TEN_MIN
else if aggPer == AggregationPeriod.FOUR_MIN then
AggregationPeriod.TEN_MIN
else if aggPer == AggregationPeriod.FIVE_MIN then
AggregationPeriod.FIFTEEN_MIN
else if aggPer == AggregationPeriod.TEN_MIN then
AggregationPeriod.THIRTY_MIN
else if aggPer == AggregationPeriod.FIFTEEN_MIN then
AggregationPeriod.HOUR
else if aggPer == AggregationPeriod.TWENTY_MIN then
AggregationPeriod.HOUR
else if aggPer == AggregationPeriod.THIRTY_MIN then
AggregationPeriod.TWO_HOURS
else if aggPer == AggregationPeriod.HOUR then
AggregationPeriod.FOUR_HOURS
else if aggPer == AggregationPeriod.TWO_HOURS then
AggregationPeriod.DAY
else if aggPer == AggregationPeriod.FOUR_HOURS then
AggregationPeriod.DAY
else if aggPer == AggregationPeriod.DAY then
AggregationPeriod.THREE_DAYS
else if aggPer == AggregationPeriod.TWO_DAYS then
AggregationPeriod.WEEK
else if aggPer == AggregationPeriod.THREE_DAYS then
AggregationPeriod.WEEK
else if aggPer == AggregationPeriod.FOUR_DAYS then
AggregationPeriod.MONTH
else if aggPer == AggregationPeriod.WEEK then
AggregationPeriod.MONTH
else if aggPer == AggregationPeriod.MONTH then
AggregationPeriod.MONTH
else
Double.NaN;
def _kPeriod;
def _dPeriod;
def _slowTrendLength;
if aggPer == AggregationPeriod.MONTH
then {
_kPeriod = K_period * 3;
_dPeriod = D_period * 3;
_slowTrendLength = SlowTrendLength * 3;
} else {
_kPeriod = K_period;
_dPeriod = D_period;
_slowTrendLength = SlowTrendLength;
}
def priceH = high( period = adjAggPer );
def priceL = low( period = adjAggPer );
def priceC = close( period = adjAggPer );
def lowest_low = Lowest( low, _kPeriod );
def highest_high = Highest( high, _kPeriod );
def fastK = if ( highest_high - lowest_low ) <= 0 then 0 else 100 * ( close - lowest_low ) / ( highest_high - lowest_low );
def fastD = if smoothing_type == smoothing_type.EMA then ExpAverage( fastK, _dPeriod ) else Average( fastK, _dPeriod );
def slowK = fastD;
def slowD = if smoothing_type == smoothing_type.EMA then ExpAverage( slowK, _dPeriod ) else Average( slowK, _dPeriod );
#---Stochastic
plot stochD = if stochastic_type == stochastic_type.FAST then fastD else slowD;
stochD.SetPaintingStrategy( PaintingStrategy.POINTS );
stochD.HideBubble();
stochD.AssignValueColor( if stochD >= stochD[1] then Color.GREEN else if stochD < stochD[1] then Color.RED else Color.GRAY );
##################################################
# Script below will plot a horizontal line at the lowest 3x Osc levelfor all of the data loaded to the chart
plot stochlowest = If Use_HH_LL then LowestAll(stochD) else double.nan;
stochlowest.SetPaintingStrategy(PaintingStrategy.LINE);
stochlowest.SetStyle(Curve.SHORT_DASH);
stochlowest.SetDefaultColor(Color.red);
stochlowest.SetLineWeight(2);
stochlowest.HideBubble();
stochlowest.HideTitle();
#####
#Script below will plot a horizontal line at the highest 3x Osc level for all of the data loaded to the chart
plot stochhighest = If Use_HH_LL then HighestAll(stochD) else double.nan;
stochhighest.SetPaintingStrategy(PaintingStrategy.LINE);
stochhighest.SetStyle(Curve.SHORT_DASH);
stochhighest.SetLineWeight(2);
stochhighest.SetDefaultColor(Color.green);
stochhighest.HideBubble();
stochhighest.HideTitle();
AddLabel(Use_HH_LL,"Highest value " + HighestAll(round(stochD,2)) + " Bars Ago = " + AsText(stochhighest, NumberFormat.TWO_DECIMAL_PLACES), Color.GREEN);
AddLabel(Use_HH_LL, "Lowest value " + LowestAll(round(stochD,2)) + " Bars Ago = " + AsText(stochlowest, NumberFormat.TWO_DECIMAL_PLACES), Color.RED);