Constant Median Line across a lower study

hbsopen

New member
VIP
I got this thought that; there are studies where you have a zero-line and then inputs for overbought ( = 80 usually) and oversold ( = 20 usually). But instead of such fixed values, why not have a Median (not a moving average) but a static value across for the Aggregation period and Time frame. I do understand that for a 20 year chart this may not make sense, but I intend to use it only for shorter periods like 5-days or 10-days..

Then, I will enhance such that, instead of overbought and oversold - I would have inputs for factor above and below that median price. This piece, I think, I can figure out looking at the code of some indicators where input is standard deviation (for e.g VWAP). What I am not being able to get to is the static Median line (instead of a zero line). I did try to use the Median* functions but those use price and for me it could be volume or it just could be an oscillator value or any other calculated value.

See below, so something similar to this but median value.

plot RS = if stddevVol == 0 then 0 else stddevVol;
RS.setDefaultColor(GetColor(6));

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);

So, above generates a static value across the aggregation and time frame selected. But, I don't believe, from what I read in ThinkScript help, this result in a Median, But I think you get the point.

I did search 'Media' in thread titles and didn't find a result that would lead me to above.
 
Solution
I got this thought that; there are studies where you have a zero-line and then inputs for overbought ( = 80 usually) and oversold ( = 20 usually). But instead of such fixed values, why not have a Median (not a moving average) but a static value across for the Aggregation period and Time frame. I do understand that for a 20 year chart this may not make sense, but I intend to use it only for shorter periods like 5-days or 10-days..

Then, I will enhance such that, instead of overbought and oversold - I would have inputs for factor above and below that median price. This piece, I think, I can figure out looking at the code of some indicators where input is standard deviation (for e.g VWAP). What I am not being able to get to is the...
I got this thought that; there are studies where you have a zero-line and then inputs for overbought ( = 80 usually) and oversold ( = 20 usually). But instead of such fixed values, why not have a Median (not a moving average) but a static value across for the Aggregation period and Time frame. I do understand that for a 20 year chart this may not make sense, but I intend to use it only for shorter periods like 5-days or 10-days..

Then, I will enhance such that, instead of overbought and oversold - I would have inputs for factor above and below that median price. This piece, I think, I can figure out looking at the code of some indicators where input is standard deviation (for e.g VWAP). What I am not being able to get to is the static Median line (instead of a zero line). I did try to use the Median* functions but those use price and for me it could be volume or it just could be an oscillator value or any other calculated value.

See below, so something similar to this but median value.

plot RS = if stddevVol == 0 then 0 else stddevVol;
RS.setDefaultColor(GetColor(6));

def sr = CompoundValue("historical data" = RS, "visible data" = if isNaN(sr[1]) then RS else sr[1]);

So, above generates a static value across the aggregation and time frame selected. But, I don't believe, from what I read in ThinkScript help, this result in a Median, But I think you get the point.

I did search 'Media' in thread titles and didn't find a result that would lead me to above.

Don't know what you really need but this seems to track the median value of an oscillator. Don't know if it provides additional "value" but it may be something you can play around with.

Code:
# Dynamic Median Line for Stochastic
declare lower;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 14;
input DPeriod = 3;
input medianLength = 20;

plot FullK = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, high, low, close, 3, AverageType.SIMPLE).FullK;
plot FullD = StochasticFull(over_bought, over_sold, KPeriod, DPeriod, high, low, close, 3, AverageType.SIMPLE).FullD;

# The Custom Median Line
plot StochasticMedian = Median(FullK, medianLength);
StochasticMedian.SetDefaultColor(Color.YELLOW);
StochasticMedian.SetStyle(Curve.SHORT_DASH);

plot Level80 = over_bought;
plot Level20 = over_sold;
 
Last edited by a moderator:
Solution
Thanks.

I realized that 'constant' may not be mos accurate term. I said that because I don't day-trade (have full time work), so I come back and look at the market or on Friday/ weekend. So if I look when markets are closed, that line will be a constant. I do understand that the line will be dynamic during trading hours. A better term is 'flat line'.

Having said that it could be average flat line (but not like a moving average). So essentially there would be no 'input' for length, as in your suggestded code. Instead it would be an average (or median) for all the bars in the time-interval (5 m, 15 min .. or even daily) across the time frame (5 days or 10 days or whatever is selected). That line would be a flat line across the study.

Hoping this can be done.
 
My guess is that you're looking for something like this, but you're not sure how to phrase it. I don't think the exact median value all that important in the context of what you've described. What you want sounds more like the center of the visible range.

def H = highestall(something);
def L = lowestall(something);
plot x = ((H - L) / 2) + L;
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1453 Online
Create Post

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