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.
 

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

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);

Happy Trading,
Mashume
 
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.
 
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.
 
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!
 
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
# https://usethinkscript.com/threads/help-with-a-price-volume-study.2759/#post-69050
# 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);
#

qDcH5mL.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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