FastStochastic NOT above 80 for X bars

tinfox

Member
How would you ask that faststochastic NOT have been above 80 or below 20 for the last N amount of bars?
I should clarify something. I want to know that faststoch crossed 80 now, but hasn't in the past 20 bars.
 
Last edited by a moderator:
Solution
How would you ask that faststochastic NOT have been above 80 or below 20 for the last N amount of bars?
I should clarify something. I want to know that faststoch crossed 80 now, but hasn't in the past 20 bars.

here is one way.
read the signal , fastK.
check if it was above OB or below OS
use sum to add up the times that the check was 1. if >0 then it was out of the midrange
i used an offset of 1 , so it is checking the previous bars, not the current.
check if OB was crossed.
cond1 = true if ob was crossed and fastk stayed in the midrange, for past x bars


Code:
# stochfast_midrng_00
input bars_back = 20;
input over_bought = 80;
input over_sold = 20;
def stch_fast_k = reference StochasticFast(over_bought, over_sold).FastK;
def...
How would you ask that faststochastic NOT have been above 80 or below 20 for the last N amount of bars?
I should clarify something. I want to know that faststoch crossed 80 now, but hasn't in the past 20 bars.

here is one way.
read the signal , fastK.
check if it was above OB or below OS
use sum to add up the times that the check was 1. if >0 then it was out of the midrange
i used an offset of 1 , so it is checking the previous bars, not the current.
check if OB was crossed.
cond1 = true if ob was crossed and fastk stayed in the midrange, for past x bars


Code:
# stochfast_midrng_00
input bars_back = 20;
input over_bought = 80;
input over_sold = 20;
def stch_fast_k = reference StochasticFast(over_bought, over_sold).FastK;
def stch_fast_d = reference StochasticFast(over_bought, over_sold).Fastd;

def above_ob = if (stch_fast_k > over_bought) then 1 else 0;
def ispastx_above_ob = if sum(above_ob[1], bars_back) > 0 then 1 else 0;

def below_os = if (stch_fast_k < over_sold) then 1 else 0;
def ispastx_below_os = if sum(below_os[1], bars_back) > 0 then 1 else 0;

def isbetween_obos = if (ispastx_above_ob == 0 and ispastx_below_os == 0) then 1 else 0;

def obcross = if (stch_fast_k crosses over_bought) then 1 else 0;

addlabel(1, "StochasticFast - K " + stch_fast_k, color.yellow);

addlabel(1, ( if ispastx_above_ob then "True" else "False") + " ,fastK was above OB, in past " + bars_back + " bars" , color.yellow);
addlabel(1, ( if ispastx_below_os then "True" else "False") + " ,fastK was below OS, in past " + bars_back + " bars" , color.yellow);

addlabel(1, ( if isbetween_obos then "True" else "False") + " ,fastK stayed between OB and OS, in past " + bars_back + " bars" , color.yellow);

addlabel(1, "StochasticFast - K " + stch_fast_k, color.yellow);

# crossed OB and past x bars were in the middle rng
def cond1 = if (isbetween_obos and obcross) then 1 else 0;

addlabel(cond1, "crossed OB and past x bars were in the middle rng", color.green);
#

https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/StochasticFast
 
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
519 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