Daily Hi/Lo TOS tweak

grapetux

Member
Hey there,

Looking for help improving the below code so that it displays the previous month hi/lo price, not the current, or show those current levels on the right side of the pic, Thanks

BNlxmqq.jpg


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);
 
Last edited by a moderator:
Solution
Hey there,

Looking for help improving the below code so that it displays the previous month hi/lo price, not the current, or show those current levels on the right side of the pic, Thanks

BNlxmqq.jpg


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))...
Hey there,

Looking for help improving the below code so that it displays the previous month hi/lo price, not the current, or show those current levels on the right side of the pic, Thanks

BNlxmqq.jpg


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);
[Edit] Just noticed that if you are using a Daily chart, the following may not work the way you want. If so, let me know].

Below is the above script modified to your request. In the image below, you can see this script is used for both requests. It just needs to be added 2 times and the inputs changed as shown for each.

Optional bubbles were added. Examples of the data in the bubbles are the MH1 is Monthly High from 1 Month ago; the DH0 is Daily High 0 days ago (ie: Today's Daily High)).

To get the prior month's H/L, changed input aggregation to aggregation.month
To get the current day's H/L, changed displace to 0 and onexpansion to yes
Capture.jpg
Ruby:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input onexpansion = yes;

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

DailyHigh.SetDefaultColor(color.green);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(color.red);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#Bubbles
input bubbles = yes;
input bubblemover = 2;#hint bubblemover: moves bubbles sideways
def bm = bubblemover;
def bm1 = bm + 1;
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]), DailyHigh,
               (if aggregationPeriod == AggregationPeriod.DAY then "DH" else
               if aggregationPeriod == AggregationPeriod.MONTH then "MH"
               else "H") + AbsValue(displace), DailyHigh.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]), DailyLow,
               (if aggregationPeriod == AggregationPeriod.DAY then "DL" else
               if aggregationPeriod == AggregationPeriod.MONTH then "ML"
               else "H")+absvalue(displace), DailyLow.TakeValueColor(),no);
 
Last edited:
Solution
[Edit] Just noticed that if you are using a Daily chart, the following may not work the way you want. If so, let me know].

Below is the above script modified to your request. In the image below, you can see this script is used for both requests. It just needs to be added 2 times and the inputs changed as shown for each.

Optional bubbles were added. Examples of the data in the bubbles are the MH1 is Monthly High from 1 Month ago; the DH0 is Daily High 0 days ago (ie: Today's Daily High)).

To get the prior month's H/L, changed input aggregation to aggregation.month
To get the current day's H/L, changed displace to 0 and onexpansion to yes

Here is a version that will work better on a daily chart. See the image for the input settings

Capture.jpg
Ruby:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input onexpansion = no;

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

DailyHigh.SetDefaultColor(color.green);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(color.red);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#Bubbles
input bubbles = yes;
input bubblemover = 2;#hint bubblemover: moves bubbles sideways
def bm = bubblemover;
def bm1 = bm + 1;
AddChartBubble(bubbles and !isnan(dailyhigh) and isnan(dailyhigh[-1]), DailyHigh,
               (if aggregationPeriod == AggregationPeriod.DAY then "DH" else
               if aggregationPeriod == AggregationPeriod.MONTH then "MH"
               else "H") + AbsValue(displace), DailyHigh.TakeValueColor());
AddChartBubble(bubbles and !isnan(dailylow) and isnan(dailylow[-1]), DailyLow,
               (if aggregationPeriod == AggregationPeriod.DAY then "DL" else
               if aggregationPeriod == AggregationPeriod.MONTH then "ML"
               else "H")+absvalue(displace), DailyLow.TakeValueColor(),no);
 

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
352 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