# Help with a Price/Volume Study

#### PocketsofTime

##### New member
I'm new here and have done some basic think script coding but nothing to this extent and this is just a bit (read A LOT) over my head.

I am looking to write a study that works in any time frame (if one has to be chosen - 2M) and will put an arrow under a green candle (when it closes) if it exceeds the height of the previous red candle (no matter how far back it is) and the green candle has a volume higher than the previous volume bar.

Would also like to include the premarket and aftermarket but not essential and repaint.

Hope this is clear and thanks for any help you can provide.

#### inthefutures

##### Active member
(no matter how far back it is) What this this part mean?

#### PocketsofTime

##### New member
Need to compare to the last negative price bar - whether it is the previous one or 3,4,5 etc. bars back.

#### mashume

##### Well-known member
VIP
Perhaps something like this:
Code:
``````declare upper;

def red_height = if close[1] < open[1]
then (high[1] - low[1])
else red_height[1];
def volume_signal = if VOLUME > VOLUME[1] then 1 else double.nan;

plot GO = if (high - low) > red_height and close > open and volume_signal == 1 then low else double.nan;

GO.SetPaintingStrategy(PaintingStrategy.ARROW_UP);``````

Mashume

#### PocketsofTime

##### New member
Mashume,

Thank you.

It seems to work perfectly, just one thing I did not think of in the beginning, eliminating the wicks of the green bar, just measuring the body.

Trying to learn so here is what I tried:

plot GO = if BodyHeight () > red_height and close > open and volume_signal == 1 then low else double.nan

I assume this will measure the body height of the current candle but not sure if this is right because how does it know if it was green.

#### mashume

##### Well-known member
VIP
Code:
``````declare upper;

def red_height = if close[1] < open[1]
then (high[1] - low[1])
else red_height[1];

def green_body = if close > open then close - open else 0;

def volume_signal = if VOLUME > VOLUME[1] then 1 else double.nan;

plot GO = if green_body > red_height and close > open and volume_signal == 1 then low else double.nan;

GO.SetPaintingStrategy(PaintingStrategy.ARROW_UP);``````

Maybe.

#### QUIKTDR1

##### Member
VIP
I'm sorry if I didn't make myself clear. The original code only gives signals bullish signals. I am attempting to add to code with bearish signals ( down arrows) Thank you!

#### halcyonguy

##### Well-known member
VIP
here you go, i fixed a few things.

i added bubbles to display variable values. i thought seeing how to do this will help you debug code in the future.
go to edit studies and click on the gear to the right of the study name and change
show_test_bubbles = yes to no to turn them off. or edit the code. it's at the end.
the bubble color is determined by the volume_signal variable.

==================================

looking at the code in post #11

you have the same variable , no , used twice, in 2 different plots. variables can only be used once.

no is a reserved word, can't use it as a variable.
https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words/no
https://tlc.thinkorswim.com/center/reference/thinkScript/Reserved-Words

i changed the 2 no variables to , no1 and no2

this line has an extra (, before high
def green_height = if close[1] > open[1] then (high[1] + low[1] else green_height[1];

no color specified for arrows. i added green for up arrors. i don't see any down arrows, so i made them white, to make sure i see them if they are plotted.
i added a size of 4 for the arrows, (can be 1-5), to make sure i see them, when they show up.

what @mashume said, volume_signal will never be equal to -1
def volume_signal = if VOLUME > VOLUME[1] then 1 else double.nan;

so your no plots will never be true and won't plot
Plot NO1 = if red_body > green_height and close < open and volume_signal == -1 then high else double.nan;

i changed the last part, from double.nan to be else -1
def volume_signal = if VOLUME > VOLUME[1] then 1 else -1;

=========================
down arrows show up now.
i didn't follow the code logic to determine what it is doing.

Ruby:
``````# PriceVolumez_01

# Help with a Price/Volume Study
# post #11
# QUIKTDR1

declare upper;

input arrow_size = 4;

def red_height = if close[1] < open[1] then (high[1] - low[1])
else red_height[1];

def green_body = if close > open then close - open else 0;

def green_height = if close[1] > open[1] then high[1] + low[1] else green_height[1];

def red_body = if close < open then close + open else 0;

#def volume_signal = if VOLUME > VOLUME[1] then 1 else double.nan;
#  change last part to be   else -1
def volume_signal = if VOLUME > VOLUME[1] then 1 else -1;

plot GO = if green_body > red_height and close > open and volume_signal == 1 then low else double.nan;
GO.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
go.setdefaultcolor(color.green);
go.setlineweight(arrow_size);

Plot NO1 = if red_body > green_height and close < open and volume_signal == -1 then high else double.nan;
NO1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
no1.setdefaultcolor(color.white);
no1.setlineweight(arrow_size);

plot NO2 = if green_body < red_height and close < open and volume_signal ==-1 then high else double.nan;
NO2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
no1.setdefaultcolor(color.white);
no2.setlineweight(arrow_size);

input show_test_bubbles = yes;
addchartbubble(show_test_bubbles, low * 0.997 , "G " +  green_body + "\n" + "R " + red_height + "\n" + "V " + volume_signal , if volume_signal == 1 then color.green else if volume_signal == -1 then color.red else color.gray, no);
#``````

#### QUIKTDR1

##### Member
VIP
halcyon, Thank you that's it! Ready for testing. Good Work!

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?