get value for "previous candle close"

tatl

Member
Hi hi, new here. Hope this question isn't too obvious. I have an indicator that works heavily with "open", but I want to try and replace that value with "previous candle close". Is there an input or line of code that gets this value easily?

best
 
Solution
@tatl
Replacing open with close[1] does produce a different value for percentmoved.
GWz0XQw.png


rWlqsAT.png


Are you rounding percentmoved by chance?
@tatl
close[1] or GetValue(close,1), depends on the context.

Why do you want to change it? You're opening yourself up for skewed results and in the case of strategies impossible trade prices.
 
@tatl
close[1] or GetValue(close,1), depends on the context.

Why do you want to change it? You're opening yourself up for skewed results and in the case of strategies impossible trade prices.
thanks for the reply. appreciate it. this community seems nice and active!

part of the indicator's equation is to tally "the percent that price moved in the bar, between high and low, relative to the open price".

however i'm realizing that i'm not entirely capturing all the price data if i do that, since there can be movement between the close of the previous bar and the open of the current one.

so instead, i want to express "the percent that price moved (between high and low) relative to the previous close"
 
@Svanoy

even between candles where the prev close was much higher than the current open, replacing "open" with either of these values in my formula didnt seem to change anything. any advise ?
 
@Svanoy quick question for you if you don't mind me prodding more...

lets say I had a simple bar chart indicator in blue, but I wanted it to print a yellow bar behind the blue bars which was an average of the last three blue values. what would the code look like?

and then further.....what if i wanted those yellow bars to only print Every Three Bars? so it would go blue - blue - blue/yellow - blue - blue - blue/yellow.

much obliged ...
 
lets say I had a simple bar chart indicator in blue, but I wanted it to print a yellow bar behind the blue bars which was an average of the last three blue values. what would the code look like?

and then further.....what if i wanted those yellow bars to only print Every Three Bars? so it would go blue - blue - blue/yellow - blue - blue - blue/yellow.


this draws yellow candles, every x bars, that are an average of the past x bars.

can pick how many bars to skip.

can pick an offset for the prices used in the average.
. if 0 is used, the average starts on the current candle.
. if 1 is used, the average starts on the previous candle.

can turn off the main price candles.

this uses addchart(), to draw candles


Ruby:
# skipcntavg

def bn = barnumber();
def na = double.nan;

input skip = 3;
input offset_average = 0;
input hide_main_price_candles = no;

HidePricePlot(hide_main_price_candles );

def x = if (bn % skip == 0) then 1 else 0;

def opnx = if !x then na else average(open[offset_average], skip);
def hix = if !x then na else average(high[offset_average], skip);
def lox = if !x then na else average(low[offset_average], skip);
def clsx = if !x then na else average(close[offset_average], skip);

AddChart(high = hix, low = lox, open = opnx, close = clsx, type = ChartType.CANDLE, growcolor = Color.yellow);

input test1_bubbles = no;
addchartbubble(test1_bubbles, low, bn , color.yellow, no);
#


hlhdbVB.jpg


with main price candles turned off
ksffeoM.jpg



ref - draw candles. can pick solid or hollow.
https://usethinkscript.com/threads/...ower-section-in-thinkorswim.10428/#post-92412
 
@halcyonguy wow thanks !! that is crazy. i may find some use for that ....

i didn't communicate properly....my indicator is a simple

.SetPaintingStrategy(paintingstrategy.HISTOGRAM);

indicator. ... similar to volume

that's what i meant by bar chart 😅
 
@halcyonguy this is the indicator on which i want to perform this

Code:
def percentmoved = (((high-low)/open) * 100);
plot volumeperpercent = (volume/percentmoved);
volumeperpercent.SetPaintingStrategy(paintingstrategy.HISTOGRAM);

not sure how to port over what you wrote for it
 
this draws yellow candles, every x bars, that are an average of the past x bars.

can pick how many bars to skip.

can pick an offset for the prices used in the average.
. if 0 is used, the average starts on the current candle.
. if 1 is used, the average starts on the previous candle.

can turn off the main price candles.

this uses addchart(), to draw candles


Ruby:
# skipcntavg

def bn = barnumber();
def na = double.nan;

input skip = 3;
input offset_average = 0;
input hide_main_price_candles = no;

HidePricePlot(hide_main_price_candles );

def x = if (bn % skip == 0) then 1 else 0;

def opnx = if !x then na else average(open[offset_average], skip);
def hix = if !x then na else average(high[offset_average], skip);
def lox = if !x then na else average(low[offset_average], skip);
def clsx = if !x then na else average(close[offset_average], skip);

AddChart(high = hix, low = lox, open = opnx, close = clsx, type = ChartType.CANDLE, growcolor = Color.yellow);

input test1_bubbles = no;
addchartbubble(test1_bubbles, low, bn , color.yellow, no);
#


hlhdbVB.jpg


with main price candles turned off
ksffeoM.jpg



ref - draw candles. can pick solid or hollow.
https://usethinkscript.com/threads/...ower-section-in-thinkorswim.10428/#post-92412

How do we read the bubble numbers? I see its named as test. Does it mean that its beta? :)
 
How do we read the bubble numbers? I see its named as test. Does it mean that its beta? :)

that bubble is just for debugging. it shows each bar barnumber in a bubble.

you change a value of the input variable, from no to yes.
input test1_bubbles = no;

studies > edit studies >
find the name of this study and click on the gear symbol to the right of the name. then look for the variable name and change the value.
 

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