input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PrevDayClose = Double.NaN;
} else { PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
#Price Comparison From Previous Day at the same bar
input DaysAgo = 1;
def c = close;
def x = BarNumber();
def nan = double.nan;
def RTHbar1 = if getday()<>getday()[Daysago]
then x
else RTHbar1[1];
def PrevRTHbar1 = if RTHbar1 != RTHbar1[1]
then RTHbar1[1]
else PrevRTHbar1[1];
def indexBar = RTHbar1 - PrevRTHbar1;
plot PrevDay = if IsNaN(c)
then nan
else GetValue(c, indexBar);
PrevDay.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDay.SetDefaultColor(CreateColor(0, 255, 255));
PrevDay.SetLineWeight(1);
plot Current_Price = c;
Current_Price.SetPaintingStrategy(PaintingStrategy.LINE);
Current_Price.SetDefaultColor(CreateColor(0, 191, 0));
Current_Price.SetLineWeight(1);
AddLabel(1, "Same Bar Comparison from " + DaysAgo + " Days ago " + PrevDay , PrevDay.TakeValueColor());
AddLabel(1, "Current Price = " + Current_Price , Current_Price.TakeValueColor());
#END Price Comparison From Previous Day at the same bar
It's almost what I'm looking for. I ended up being able to stack percentage changes of multiple securities from the market open. Unfortunately they bleed over into another. Don't know yet if that's a desired effect. Thx Ben.@btran1993 Did you try the built-in Comparison indicator in ThinkorSwim?
Hi - is there a way to plot this without having to plot the current days price action? It seems that the previous day's price action for a given time does not plot until the current bar is being formedi was pretty bored.. 2hrs later here you go what you requested:
Its Price Comparison From Previous Day at the same bar (or same time )and can be adjusted to compare XZY days ago by adjusting the "DaysAgo"
remember to hit the like button if you liked my post!
![]()
Code:#Price Comparison From Previous Day at the same bar input DaysAgo = 1; def c = close; def x = BarNumber(); def nan = double.nan; def RTHbar1 = if getday()<>getday()[Daysago] then x else RTHbar1[1]; def PrevRTHbar1 = if RTHbar1 != RTHbar1[1] then RTHbar1[1] else PrevRTHbar1[1]; def indexBar = RTHbar1 - PrevRTHbar1; plot PrevDay = if IsNaN(c) then nan else GetValue(c, indexBar); PrevDay.SetPaintingStrategy(PaintingStrategy.LINE); PrevDay.SetDefaultColor(CreateColor(0, 255, 255)); PrevDay.SetLineWeight(1); plot Current_Price = c; Current_Price.SetPaintingStrategy(PaintingStrategy.LINE); Current_Price.SetDefaultColor(CreateColor(0, 191, 0)); Current_Price.SetLineWeight(1); AddLabel(1, "Same Bar Comparison from " + DaysAgo + " Days ago " + PrevDay , PrevDay.TakeValueColor()); AddLabel(1, "Current Price = " + Current_Price , Current_Price.TakeValueColor()); #END Price Comparison From Previous Day at the same bar
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
E | Heiken Ashi Overlay Displaced | Questions | 1 | |
T | Heikin Ashi overlay | Questions | 1 | |
R | MACD + TTM SQUEEZE OVERLAY | Questions | 7 | |
![]() |
Overlay Alignment Question | Questions | 4 | |
J | Compare Symbols Overlay | Questions | 2 |
Start a new thread and receive assistance from our community.
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.
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.