Add mid-price line to DailyHighLow study

ARL

Member
Plus
Greetings! I'd like to add a mid-price horizontal line to the TOS study DailyHighLow which would indicate the average price of the prior trading day's high and low price. This would probably be a simple modification for an experienced coder and I would appreciate the help. I didn't find anything in the forums but maybe I overlooked an existing post that addresses this. Just direct me there, please, if that's the case. Here's the existing DailyHighLow script:

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Solution
@ARL
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
plot DailyMid;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyMid = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
DailyMid = (DailyHigh + DailyLow)/2;
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL)...
@ARL
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
plot DailyMid;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyMid = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
DailyMid = (DailyHigh + DailyLow)/2;
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyMid.SetDefaultColor(GetColor(4));
DailyMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
  • Like
Reactions: ARL
Solution

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

I modified this to add the Prior Day's Close and Labels. Hope you find it useful. Prior Day's Close is often an important S/R line.

Code:
#
# JS_Prior_HighLowMidClose with Labels
#
input showLabel = yes;

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
plot DailyMid;
plot DailyClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
    DailyMid = Double.NaN;
    DailyClose = Double.NaN;

} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
    DailyMid = (DailyHigh + DailyLow) / 2;
    DailyClose = close(period = aggregationPeriod)[-displace];
}

DailyHigh.SetDefaultColor(GetColor(1));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(2));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyMid.SetDefaultColor(GetColor(3));
DailyMid.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyClose.SetDefaultColor(GetColor(4));
DailyClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

def aboveHigh = Close > DailyHigh;
def aboveMid = Close > DailyMid and Close <= DailyHigh;
def belowMid = Close < DailyMid and close >= DailyLow;
def belowLow = close < DailyLow;

AddLabel(showLabel, if aboveHigh then "Day>HI" else if aboveMid then "Day>ML" else if belowMid then "Day<ML" else "Day<LO", if aboveHigh then color.green else if aboveMid then color.light_Green else if belowMid then color.Light_red else color.red);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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