HTF PO3 Indicator For ThinkOrSwim

If you add the study multiple times, you can compare the last 5 hours of NQ vs Bonds while looking at a 2m chart on ES. Maybe it's too much o_O

View attachment 18506
How do you add multiple codes as shown above? Can the previous week and days also be shown with other lower time frames when selecting from the study? When I add more than one study it overlays on top of each other. I'm also using the code by @netarchitech if that makes a difference.
 
How do you add multiple codes as shown above? Can the previous week and days also be shown with other lower time frames when selecting from the study? When I add more than one study it overlays on top of each other. I'm also using the code by @netarchitech if that makes a difference.
I've setup an NQ chart with the prior 5 daily candles showing on an hourly chart. Monday's candle looks a bit off b/c it was a holiday but that's just TOS data.
pBWQHKE.png


The trick to set it up like this is to add that study multiple times (for as many candles as you would like to display). And you MUST have your expansion area large enough to fit the candles you are adding (minimum 3 per candle you add). I've included this setup as a shared chart so you should just be able to modify the timeframe and get what you are looking for.

Shared chart
 
I've setup an NQ chart with the prior 5 daily candles showing on an hourly chart. Monday's candle looks a bit off b/c it was a holiday but that's just TOS data.
pBWQHKE.png


The trick to set it up like this is to add that study multiple times (for as many candles as you would like to display). And you MUST have your expansion area large enough to fit the candles you are adding (minimum 3 per candle you add). I've included this setup as a shared chart so you should just be able to modify the timeframe and get what you are looking for.

Shared chart
So how do you add six candles if candle type only goes four back?
 
Tried that. Couldn't get it right, if you post the code for two additioal candles be much appreciated.
I have modified to support up to 10 candles. You need to manually select which candle you want (eg. 0 is current, 1 is previous and so on). So if you want 10 candles, you want candleType 0 in Candle 'Tenth' and candleType 1 in Candle 'Ninth' and so on. Hopefully this is enough to get you going.

Ruby:
#hint: <b>Intro</b> \n This study displays a higher timeframe candle to the right of the chart in the expansion area. \n <li>Typically used for showing PO3 for daily chart</li> <li>You must have an expansion area of 4 or greater set for this to work</li>
#hint candleType: 0 is current, 1 is previous, 2 is 2 back, etc

# Created by @tony_futures inspired by the ICT Power of 3 concept
declare hide_on_daily;
input htf = AggregationPeriod.DAY;
input useMidnight = no;
input candle = { default "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"};
#input candleType = { default "Current", "Previous", "Two Back", "Three Back", "Four Back"};
def candleCount;
input candleType = 0;
def candlePos = candleType;

switch (candle)
{
    case "First":
      candleCount = 1;
    case "Second":
      candleCount = 4;
  case "Third":
      candleCount = 7;
  case "Fourth":
      candleCount = 10;
  case "Fifth":
      candleCount = 13;
  case "Sixth":
      candleCount = 16;
  case "Seventh":
      candleCount = 19;
  case "Eighth":
      candleCount = 22;
  case "Ninth":
      candleCount = 25;
  case "Tenth":
      candleCount = 28;
}

def wickOffset = candleCount;
def midnight = 0000;
def isMidnight = secondsFromTime(midnight) == 0;
def midPrice = if isMidnight then open else midPrice[1];
def xO0 = if useMidnight then midPrice else open(period = htf)[candlePos];
def xH0 = high(period = htf)[candlePos];
def xL0 = low(period = htf)[candlePos];
def xC0 = close(period = htf)[candlePos];


def exp2 = (isNaN(close[wickOffset]) OR isNaN(close[wickOffset+1]) OR isNaN(close[wickOffset+2])) and !isNan(close[wickOffset+3]);
def expMid = isNaN(close[wickOffset+1]) and !isNaN(close[wickOffset+2]);
def expMid2 = isNaN(close[wickOffset+2]) and !isNaN(close[wickOffset+3]);
def expEnd = isNaN(close[wickOffset+3]) and !isNaN(close[wickOffset+4]);
def expFinal = isNaN(close[wickoffset+3]);
def NaN = Double.NaN;

def priceOffset =  if expEnd then (wickOffset + 4) else if expMid then (wickOffset + 2) else if expMid2 then (wickOffset + 3) else (wickOffset + 1);
def XH = getValue(xH0, priceOffset);
def XO = getValue(xO0, priceOffset);
def xC = getValue(xC0, priceOffset);
def xL = getValue(xL0, priceOffset);

def isUp = xo < xc;
def isDn = xo > xc;
def isDoji = xO == xC;

# Global Color setup
DefineGlobalColor("greenCandle", CreateColor(103, 135, 151));
DefineGlobalColor("redCandle", CreateColor(136, 93, 100));
DefineGlobalColor("wick", Color.GRAY);

AddCloud( if exp2 and isUp then xC else NaN, xO, GlobalColor("greenCandle"), GlobalColor("redCandle"));
AddCloud( if exp2 and isDn then xO else NaN, xC, GlobalColor("redCandle"), GlobalColor("redCandle"));

plot dojiWick = if isDoji and exp2 then xO else NaN;
dojiWick.setDefaultColor(GlobalColor("wick"));

def wickHigh = if isUp then xC else xO;
def wickLow = if isDn then xC else xO;
AddChart(if expMid then xH else NaN, if expMid then wickHigh else Double.NaN,  NaN,  NaN, ChartType.BAR, GlobalColor("wick"));
AddChart(if expMid then xL else NaN, if expMid then wickLow else Double.NaN,  NaN,  NaN, ChartType.BAR, GlobalColor("wick"));

input showTimeFrameBubble = no;
def tf = htf/60000;
AddChartBubble(showTimeFrameBubble and expMid,xL,(if tf == 43200 then "M" else if tf == 10080 then "W" else if tf == 1440 then "D" else if tf == 240 then "4h" else if tf == 120 then "2h" else if tf == 60 then "H" else Round(tf,0)+"") + if candlePos != 0 then " -" + CandlePos else "",Color.WHITE,no);

input showBubbles = no;
AddChartBubble(showBubbles and expEnd and isUp, xO, xO, GlobalColor("greenCandle"), no);
AddChartBubble(showBubbles and expEnd and isDn, xO, xO, GlobalColor("redCandle"), yes);
AddChartBubble(showBubbles and expEnd, xL, xL, if isUp then GlobalColor("greenCandle") else GlobalColor("redCandle"), no);
AddChartBubble(showBubbles and expEnd, xH, xH, if isUp then GlobalColor("greenCandle") else GlobalColor("redCandle"), yes);

input showLabels = no;
def candleRange = xH - xL;
AddLabel(showLabels,(if tf == 43200 then "M" else if tf == 10080 then "W" else if tf == 1440 then "D" else if tf == 240 then "4h" else if tf == 120 then "2h" else if tf == 60 then "H" else AsText(tf)) + " Range: " + candleRange, if isUp then GlobalColor("greenCandle") else if isDn then GlobalColor("redCandle") else GlobalColor("wick"));

def xCL = close(period = htf)[candlePOS-1];
def lastCandle = isNaN(xCL);
input showAdditionalLines = no;

plot currentHigh = if showAdditionalLines and lastCandle and !expFinal then xH else NaN;
currentHigh.setPaintingStrategy(PaintingStrategy.DASHES);
currentHigh.setDefaultColor(GlobalColor("wick"));
currentHigh.DefineColor("Normal", GlobalColor("wick"));
currentHigh.DefineColor("Daily", GlobalColor("greenCandle"));
currentHigh.AssignValueColor(if tf == 1440 then currentHigh.Color("Daily") else currentHigh.Color("Normal"));


plot currentLow = if showAdditionalLines and lastCandle and !expFinal then xL else NaN;
currentLow.setPaintingStrategy(PaintingStrategy.DASHES);
currentLow.setDefaultColor(GlobalColor("wick"));
currentLow.DefineColor("Normal", GlobalColor("wick"));
currentLow.DefineColor("Daily", GlobalColor("redCandle"));
currentLow.AssignValueColor(if tf == 1440 then currentLow.Color("Daily") else currentLow.Color("Normal"));
 
I have modified to support up to 10 candles. You need to manually select which candle you want (eg. 0 is current, 1 is previous and so on). So if you want 10 candles, you want candleType 0 in Candle 'Tenth' and candleType 1 in Candle 'Ninth' and so on. Hopefully this is enough to get you going.

Ruby:
#hint: <b>Intro</b> \n This study displays a higher timeframe candle to the right of the chart in the expansion area. \n <li>Typically used for showing PO3 for daily chart</li> <li>You must have an expansion area of 4 or greater set for this to work</li>
#hint candleType: 0 is current, 1 is previous, 2 is 2 back, etc

# Created by @tony_futures inspired by the ICT Power of 3 concept
declare hide_on_daily;
input htf = AggregationPeriod.DAY;
input useMidnight = no;
input candle = { default "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth"};
#input candleType = { default "Current", "Previous", "Two Back", "Three Back", "Four Back"};
def candleCount;
input candleType = 0;
def candlePos = candleType;

switch (candle)
{
    case "First":
      candleCount = 1;
    case "Second":
      candleCount = 4;
  case "Third":
      candleCount = 7;
  case "Fourth":
      candleCount = 10;
  case "Fifth":
      candleCount = 13;
  case "Sixth":
      candleCount = 16;
  case "Seventh":
      candleCount = 19;
  case "Eighth":
      candleCount = 22;
  case "Ninth":
      candleCount = 25;
  case "Tenth":
      candleCount = 28;
}

def wickOffset = candleCount;
def midnight = 0000;
def isMidnight = secondsFromTime(midnight) == 0;
def midPrice = if isMidnight then open else midPrice[1];
def xO0 = if useMidnight then midPrice else open(period = htf)[candlePos];
def xH0 = high(period = htf)[candlePos];
def xL0 = low(period = htf)[candlePos];
def xC0 = close(period = htf)[candlePos];


def exp2 = (isNaN(close[wickOffset]) OR isNaN(close[wickOffset+1]) OR isNaN(close[wickOffset+2])) and !isNan(close[wickOffset+3]);
def expMid = isNaN(close[wickOffset+1]) and !isNaN(close[wickOffset+2]);
def expMid2 = isNaN(close[wickOffset+2]) and !isNaN(close[wickOffset+3]);
def expEnd = isNaN(close[wickOffset+3]) and !isNaN(close[wickOffset+4]);
def expFinal = isNaN(close[wickoffset+3]);
def NaN = Double.NaN;

def priceOffset =  if expEnd then (wickOffset + 4) else if expMid then (wickOffset + 2) else if expMid2 then (wickOffset + 3) else (wickOffset + 1);
def XH = getValue(xH0, priceOffset);
def XO = getValue(xO0, priceOffset);
def xC = getValue(xC0, priceOffset);
def xL = getValue(xL0, priceOffset);

def isUp = xo < xc;
def isDn = xo > xc;
def isDoji = xO == xC;

# Global Color setup
DefineGlobalColor("greenCandle", CreateColor(103, 135, 151));
DefineGlobalColor("redCandle", CreateColor(136, 93, 100));
DefineGlobalColor("wick", Color.GRAY);

AddCloud( if exp2 and isUp then xC else NaN, xO, GlobalColor("greenCandle"), GlobalColor("redCandle"));
AddCloud( if exp2 and isDn then xO else NaN, xC, GlobalColor("redCandle"), GlobalColor("redCandle"));

plot dojiWick = if isDoji and exp2 then xO else NaN;
dojiWick.setDefaultColor(GlobalColor("wick"));

def wickHigh = if isUp then xC else xO;
def wickLow = if isDn then xC else xO;
AddChart(if expMid then xH else NaN, if expMid then wickHigh else Double.NaN,  NaN,  NaN, ChartType.BAR, GlobalColor("wick"));
AddChart(if expMid then xL else NaN, if expMid then wickLow else Double.NaN,  NaN,  NaN, ChartType.BAR, GlobalColor("wick"));

input showTimeFrameBubble = no;
def tf = htf/60000;
AddChartBubble(showTimeFrameBubble and expMid,xL,(if tf == 43200 then "M" else if tf == 10080 then "W" else if tf == 1440 then "D" else if tf == 240 then "4h" else if tf == 120 then "2h" else if tf == 60 then "H" else Round(tf,0)+"") + if candlePos != 0 then " -" + CandlePos else "",Color.WHITE,no);

input showBubbles = no;
AddChartBubble(showBubbles and expEnd and isUp, xO, xO, GlobalColor("greenCandle"), no);
AddChartBubble(showBubbles and expEnd and isDn, xO, xO, GlobalColor("redCandle"), yes);
AddChartBubble(showBubbles and expEnd, xL, xL, if isUp then GlobalColor("greenCandle") else GlobalColor("redCandle"), no);
AddChartBubble(showBubbles and expEnd, xH, xH, if isUp then GlobalColor("greenCandle") else GlobalColor("redCandle"), yes);

input showLabels = no;
def candleRange = xH - xL;
AddLabel(showLabels,(if tf == 43200 then "M" else if tf == 10080 then "W" else if tf == 1440 then "D" else if tf == 240 then "4h" else if tf == 120 then "2h" else if tf == 60 then "H" else AsText(tf)) + " Range: " + candleRange, if isUp then GlobalColor("greenCandle") else if isDn then GlobalColor("redCandle") else GlobalColor("wick"));

def xCL = close(period = htf)[candlePOS-1];
def lastCandle = isNaN(xCL);
input showAdditionalLines = no;

plot currentHigh = if showAdditionalLines and lastCandle and !expFinal then xH else NaN;
currentHigh.setPaintingStrategy(PaintingStrategy.DASHES);
currentHigh.setDefaultColor(GlobalColor("wick"));
currentHigh.DefineColor("Normal", GlobalColor("wick"));
currentHigh.DefineColor("Daily", GlobalColor("greenCandle"));
currentHigh.AssignValueColor(if tf == 1440 then currentHigh.Color("Daily") else currentHigh.Color("Normal"));


plot currentLow = if showAdditionalLines and lastCandle and !expFinal then xL else NaN;
currentLow.setPaintingStrategy(PaintingStrategy.DASHES);
currentLow.setDefaultColor(GlobalColor("wick"));
currentLow.DefineColor("Normal", GlobalColor("wick"));
currentLow.DefineColor("Daily", GlobalColor("redCandle"));
currentLow.AssignValueColor(if tf == 1440 then currentLow.Color("Daily") else currentLow.Color("Normal"));
Thank you sir.
 
I've setup an NQ chart with the prior 5 daily candles showing on an hourly chart. Monday's candle looks a bit off b/c it was a holiday but that's just TOS data.
pBWQHKE.png


The trick to set it up like this is to add that study multiple times (for as many candles as you would like to display). And you MUST have your expansion area large enough to fit the candles you are adding (minimum 3 per candle you add). I've included this setup as a shared chart so you should just be able to modify the timeframe and get what you are looking for.

Shared chart
great thanks looking good
 
Here is a chart with 10 htf candles added. Hopefully you can start with this and configure to your needs:

Shared chart
Not to be pain; but instead of timeframe, how difficult would it be to code a bubble below the lists the abbreviated days of the week like M,Tu,Wed,Th,F? for like each respective day? Thank you for this code, very well done!
 
Not to be pain; but instead of timeframe, how difficult would it be to code a bubble below the lists the abbreviated days of the week like M,Tu,Wed,Th,F? for like each respective day? Thank you for this code, very well done!
Unfortunately, I believe this would be a challenge. In the code I can only 'get' the current day of the week (1 through 5) and we can be grabbing candles from 9+ days ago. Would require quite a bit of manual coding to factor in the starting point and the possible outcomes. I will think about it a bit and see if I can find a reasonable solution.
 
Unfortunately, I believe this would be a challenge. In the code I can only 'get' the current day of the week (1 through 5) and we can be grabbing candles from 9+ days ago. Would require quite a bit of manual coding to factor in the starting point and the possible outcomes. I will think about it a bit and see if I can find a reasonable solution.
Actually, I figured out a way to get this to work for the last five days. There is a slight problem when you get closer to the end of the day b/c the expansion area is in the 'next day' and the calculations are off by one day. I'm not sure if there is a way around that.

DCPKDuZ.png


Add this code to the study to get those bubbles:

Ruby:
input showDailyBubbles = yes;
def currentDay = getDayOfWeek(getYYYYMMDD());
def tempDay = currentDay - candlePos;
def displayDay = if (currentDay == 4 and candlePos == 4) then 5 else if (currentDay == 3 and candlePos == 4) then 4 else if (currentDay == 3 and candlePos == 3) then 5 else if (currentDay == 2 and candlePos == 4) then 3 else if (currentDay == 2 and candlePos == 3) then 4 else if (currentDay == 2 and candlePos == 2) then 5 else tempDay;
AddChartBubble(showDailyBubbles and expMid,xL,(if displayDay == 1 then "M" else if displayDay == 2 then "Tu" else if displayDay == 3 then "W" else if displayDay == 4 then "Th" else if displayDay == 5 then "F" else displayDay + ""),Color.WHITE,no);
 
Tony - How do you add different tickers with this study for the comparison?
That image was an experimental study that I did not end up releasing here. If I have some time over the next few weeks I will see if I can resurrect it and clean it up for release.
 

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