ThreeXOscillator - can someone up and down add arrows

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);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@stocksniper Here you go. I also removed code that wasn't being used.

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 _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 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;
def green = stochD >= stochD[1];
def red = stochD < stochD[1];
stochD.SetPaintingStrategy( PaintingStrategy.POINTS );
stochD.HideBubble();
stochD.AssignValueColor( if green then Color.GREEN else if red then Color.RED else Color.GRAY );

plot Up = if green and red[1] then stochD else Double.NaN;
Up.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plot Down = if red and green [1] then stochD else Double.NaN;
Down.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
##################################################
# 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);
 
@stocksniper SlowK has been being discussed lately. And my research turned up this variation of the 3x Oscillator by R. Houser. I found it here: https://bigchickenstockpicks.wordpress.com/mechanically-separated-tos-scripts/

Code:
# RHouser created 3X Oscillator code
# RHouser modified to include alerts: bubbles and audio
# RHouser updated 5/18/12 due to FullD not being calculated
# correctly by TOS
# Stochastic calculated using Lane’s formulas
# Updated 5/23/12 – ability to turn on/off alert bubbles
# Place # before or delete last line of code should OB/OS
# colored candles not to show on chart – code provided by
# by Achilles Dent 5/21/12
# Original code uses K=10 and D=10
declare lower;

input K_period = 10;
input D_period = 10;
input SlowTrendLength = 3;
input smoothing_type = { default EMA, SMA };
input stochastic_type = { FAST, default SLOW };
input over_bought = 85;
input over_sold = 25;
input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;

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.AssignValueColor( if stochD >= stochD[1] then Color.CYAN else if stochD < stochD[1] then Color.BLUE else Color.GRAY );

#—Reference lines
plot OverBought = over_bought;
OverBought.SetDefaultColor( Color.BLACK );
def Hundred = 100;
AddCloud( OverBought, Hundred, Color.RED, Color.RED );

plot OverSold = over_sold;
OverSold.SetDefaultColor( Color.BLACK );
def Zero = 0;
AddCloud( OverSold, Zero, Color.YELLOW, Color.YELLOW );

#—Calculate primary buy/sell
def primaryBuy = stochD >= OverSold and stochD[1] < OverSold;
def primarySell = stochD <= OverBought and stochD[1] > OverBought;

#—Calculate secondary buy/sell
def fastTrendUp = stochD < stochD[-1];
def slowTrendUp = stochD > stochD[_slowTrendLength];
def valley = fastTrendUp and !fastTrendUp[1] and stochD > OverSold;
def peak = !fastTrendUp and fastTrendUp[1] and stochD < OverBought;
def secondaryBuy = valley and stochD < OverBought;
def secondarySell = peak and stochD > OverSold;

plot buy = if primaryBuy or secondaryBuy then stochD else Double.NaN;
buy.DefineColor( “pBuy”, Color.UPTICK );
buy.DefineColor( “sBuy”, CreateColor( 0, 255, 0 ) );
buy.AssignValueColor( if primaryBuy then buy.color( “pBuy” ) else buy.color( “sBuy” ) );
buy.SetPaintingStrategy( PaintingStrategy.ARROW_UP );
buy.setHiding( show_bubbles );

plot sell = if primarySell or secondarySell then stochD else Double.NaN;
sell.DefineColor( “pSell”, Color.DOWNTICK );
sell.DefineColor( “sSell”, Color.MAGENTA );
sell.AssignValueColor( if primarySell then sell.color( “pSell” ) else sell.color( “sSell” ) );
sell.SetPaintingStrategy( PaintingStrategy.ARROW_DOWN );
sell.setHiding( show_bubbles );

AddChartBubble( show_bubbles and primaryBuy, stochD, “pBUY”, Color.UPTICK, no );
AddChartBubble( show_bubbles and show_sec_bbls and secondaryBuy, stochD, “sBUY”, CreateColor( 0, 255, 0 ), no );
AddChartBubble( show_bubbles and primarySell, stochD, “pSELL”, Color.DOWNTICK, yes );
AddChartBubble( show_bubbles and show_sec_bbls and secondarySell, stochD, “sSELL”, Color.MAGENTA, yes );

alert( show_alerts and buy, if primaryBuy then concat( “Primary BUY @ “, close ) else concat( “Secondary BUY @ “, close ), Alert.BAR, Sound.Ring );
alert( show_alerts and sell, if primarySell then concat( “Primary SELL @ “, close ) else concat( “Secondary SELL @ “, close ), Alert.BAR, Sound.Chimes );

AssignPriceColor(if slowk>80 then Color.cyan else if slowk<20 then color.pink else color.current);
qJsNgEa.png
 
@generic I like this one a lot but i wish there was a warning before the dots change color from green to red or vice versa and could paint 2 or 3 dots in yellow when it`s close to changing color/direction. Basically a heads up to pay attention of a possible trend shift.

Can this be added to the code somehow? Would make it even better than it already is.
 
MerryDay, I am following one of your chart- setup, which outlines overlay of Zscore and Bull power. There I saw excellent annotations too and some other lower study too. Unfortunately I could not find it now:(
Could you pl help me to find it? ( This is it looks like -https://tos.mx/meGAsla)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
295 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top