Market and Volume Profile combined For ThinkOrSwim

Cwparker23

Member
Code:
##########################################################
# Original script by TD AMERITRADE MODIfied BY Cwparker23#
##########################################################
#-----------------
#DISCLAIMER
#-----------------
#I am not a certified financial advisor. The content of this page/site and tools are for informational purposes only and does not constitute financial or legal advice. Under no circumstances will the author be responsible for errors or use of this tool and site. User assumes all risks.


input pricePerRowHeightMode = {default AUTOMATIC, TICKSIZE, CUSTOM};
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = yes;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 70;
input opacity = 50;

def period;
def yyyymmdd = getYyyyMmDd();
def seconds = secondsFromTime(0);
def month = getYear() * 12 + getMonth();
def day_number = daysFromDate(first(yyyymmdd)) + getDayOfWeek(first(yyyymmdd));
def dom = getDayOfMonth(yyyymmdd);
def dow = getDayOfWeek(yyyymmdd - dom + 1);
def expthismonth = (if dow > 5 then 27 else 20) - dow;
def exp_opt = month + (dom > expthismonth);
switch (timePerProfile) {
case CHART:
    period = 0;
case MINUTE:
    period = floor(seconds / 60 + day_number * 24 * 60);
case HOUR:
    period = floor(seconds / 3600 + day_number * 24);
case DAY:
    period = countTradingDays(min(first(yyyymmdd), yyyymmdd), yyyymmdd) - 1;
case WEEK:
    period = floor(day_number / 7);
case MONTH:
    period = floor(month - first(month));
case "OPT EXP":
    period = exp_opt - first(exp_opt);
case BAR:
    period = barNumber() - 1;
}

def count = CompoundValue(1, if period != period[1] then (count[1] + period - period[1]) % multiplier else count[1], 0);
def cond = count < count[1] + period - period[1];
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
    height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    height = PricePerRow.TICKSIZE;
case CUSTOM:
    height = customRowHeight;
}

profile vol = volumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def con = compoundValue(1, onExpansion, no);
def pc_VOLUME = if IsNaN(vol.getPointOfControl()) and con then pc_VOLUME[1] else vol.getPointOfControl();
def hVA_VOLUME = if IsNaN(vol.getHighestValueArea()) and con then hVA_VOLUME[1] else vol.getHighestValueArea();
def lVA_VOLUME = if IsNaN(vol.getLowestValueArea()) and con then lVA_VOLUME[1] else vol.getLowestValueArea();

def hProfile_VOLUME = if IsNaN(vol.getHighest()) and con then hProfile_VOLUME[1] else vol.getHighest();
def lProfile_VOLUME = if IsNaN(vol.getLowest()) and con then lProfile_VOLUME[1] else vol.getLowest();
def plotsDomain = IsNaN(close) == onExpansion;

plot POC_VOLUME = if plotsDomain then pc_VOLUME else Double.NaN;
plot ProfileHigh_VOLUME = if plotsDomain then hProfile_VOLUME else Double.NaN;
plot ProfileLow_VOLUME = if plotsDomain then lProfile_VOLUME else Double.NaN;
plot VAHigh_VOLUME = if plotsDomain then hVA_VOLUME else Double.NaN;
plot VALow_VOLUME = if plotsDomain then lVA_VOLUME else Double.NaN;

DefineGlobalColor("Profile_VOLUME", GetColor(1));
DefineGlobalColor("Point Of Control_VOLUME", GetColor(5));
DefineGlobalColor("Value Area_VOLUME", GetColor(8));

vol.show(globalColor("Profile_VOLUME"), if showPointOfControl then globalColor("Point Of Control_VOLUME") else color.current, if showValueArea then globalColor("Value Area_VOLUME") else color.current, opacity);
POC_VOLUME.SetDefaultColor(globalColor("Point Of Control_VOLUME"));
POC_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_VOLUME.SetDefaultColor(globalColor("Value Area_VOLUME"));
VALow_VOLUME.SetDefaultColor(globalColor("Value Area_VOLUME"));
ProfileHigh_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow_VOLUME.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh_VOLUME.SetDefaultColor(GetColor(3));
ProfileLow_VOLUME.SetDefaultColor(GetColor(3));
ProfileHigh_VOLUME.hide();
ProfileLow_VOLUME.hide();

##################################    TPOProfile         #############################
profile tpo = timeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc_PRICE = if IsNaN(tpo.getPointOfControl()) and con then pc_PRICE[1] else tpo.getPointOfControl();
def hVA_PRICE = if IsNaN(tpo.getHighestValueArea()) and con then hVA_PRICE[1] else tpo.getHighestValueArea();
def lVA_PRICE = if IsNaN(tpo.getLowestValueArea()) and con then lVA_PRICE[1] else tpo.getLowestValueArea();

def hProfile_PRICE = if IsNaN(tpo.getHighest()) and con then hProfile_PRICE[1] else tpo.getHighest();
def lProfile_PRICE = if IsNaN(tpo.getLowest()) and con then lProfile_PRICE[1] else tpo.getLowest();
plot POC_PRICE = if plotsDomain then pc_PRICE else Double.NaN;
plot ProfileHigh_PRICE = if plotsDomain then hProfile_PRICE else Double.NaN;
plot ProfileLow_PRICE = if plotsDomain then lProfile_PRICE else Double.NaN;
plot VAHigh_PRICE = if plotsDomain then hVA_PRICE else Double.NaN;
plot VALow_PRICE = if plotsDomain then lVA_PRICE else Double.NaN;

DefineGlobalColor("Profile_PRICE", GetColor(1));
DefineGlobalColor("Point Of Control_PRICE", GetColor(5));
DefineGlobalColor("Value Area_PRICE", GetColor(8));

tpo.show(globalColor("Profile_PRICE"), if showPointOfControl then globalColor("Point Of Control_PRICE") else color.current, if showValueArea then globalColor("Value Area_PRICE") else color.current, opacity);
POC_PRICE.SetDefaultColor(globalColor("Point Of Control_PRICE"));
POC_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh_PRICE.SetDefaultColor(globalColor("Value Area_PRICE"));
VALow_PRICE.SetDefaultColor(globalColor("Value Area_PRICE"));
ProfileHigh_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileLow_PRICE.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ProfileHigh_PRICE.SetDefaultColor(GetColor(3));
ProfileLow_PRICE.SetDefaultColor(GetColor(3));
ProfileHigh_PRICE.hide();
ProfileLow_PRICE.hide();


PLOT VPPOCXX = (POC_VOLUME + POC_PRICE)/2;
PLOT VPVAHXX = (VAHigh_VOLUME + VAHigh_PRICE)/2;
PLOT VPVALXX = (VALow_VOLUME + VALow_PRICE)/2;
VPPOCXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VPVAHXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VPVALXX.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 

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

It doesn't work.
Your post does not provide enough information to say where you went astray.
Did you know that indicators using PROFILE() functions print n the expansion area?

Here is a shared chart link: http://tos.mx/NysVNBv Click here for --> Easiest way to load shared links
Providing you with an example of how to set up your charts to use this study.
c1Iauip.png
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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