# Stoch FullD Crosses

#### Nick

##### New member
Hello everyone, I use a variety of indicators for bullish/bearish signals. I need some help with the script for when a signal is either bullish or bearish, but it is in between the bull/bear signal zones.
For example, the code below uses the stochastic oscillator. The histogram is painted green when it is overbought, red when it is oversold, and yellow when it is in between those levels.
A bull signal is generated when FullD crosses above 60 and I assign 1 point.
A bear signal occurs when FullD crosses below 40 and I assign -1 point.
Once the signal occurs, I want to have the point value remain at either +1 or -1 until a new signal reverses the existing one. Zero points is not wanted.
I'm assuming that I need to use the Case or Switch statements, but I've never written that script.

#Declarations
declare lower;

#Inputs
input over_bought = 60;
input over_sold = 40;
input KPeriod = 126;
input DPeriod = 5;
input priceH = close;
input priceL = close;
input priceC = close;
input slowing_period = 1;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On FullK", "On FullD", "On FullK & FullD"};

#Definitions
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 AboveOB = FullD > over_bought;
def BetweenOBOS = FullD <= over_bought and FullD >= over_sold;
def StochClose = StochasticFull(UTLevel, DTLevel, StochLength, StochSMA, Price, Price, Price, SlowP)."FullD";
def SCSignal = if StochClose > UTLevel then 1 else if SCSignal[1] == 1 and StochClose >= DTLevel then 1 else if StochClose < DTLevel then -1 else if SCSignal[1] ==-1 and StochClose <= UTLevel then -1 else 0;

#Plots
plot StochClose = FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;

#Painting Strategies
StochClose.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
StochClose.AssignValueColor(If BetweenOBOS then Color.YELLOW else if AboveOB then Color.GREEN else Color.RED);

Any assistance would be appreciated.

What I would like help with is the following: FullD is above 60 and the indicator is set to 1. The indicator will remain at 1 until FullD crosses below 40, which will change the indicator to -1. Conversely, the indicator remains at -1 until FullD crosses back above 60.
Any help would be appreciated.

What I would like help with is the following: FullD is above 60 and the indicator is set to 1. The indicator will remain at 1 until FullD crosses below 40, which will change the indicator to -1. Conversely, the indicator remains at -1 until FullD crosses back above 60.
Any help would be appreciated.

something like this

def x = if barnumber() == 1 then 0
else if fulld crosses below 40 then -1
else if fulld crosses above 60 then 1
else x[1];

87k+ Posts
304 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?