High Low Lookback for ThinkorSwim

@Armageddon Please be specific. What symbol? What aggregation? Do you have extended hours on or not? Is "Fit Studies" checked or un-checked? In order to try to help, you must provide the information necessary to attempt to duplicate the problem. It would also be helpful to post a screenshot of the problem in addition to the answers for my questions.
 
@Armageddon Perhaps try this -
Code:
input endDate = 20210104;
def cond = if GetYYYYMMDD() < enddate then double.nan
           else if GetYYYYMMDD() == endDate then low(period = aggregationperiod.day)
           else cond[1];
plot Price = cond;
Price.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
@Armageddon Perhaps try this -
Code:
input endDate = 20210104;
def cond = if GetYYYYMMDD() < enddate then double.nan
           else if GetYYYYMMDD() == endDate then low(period = aggregationperiod.day)
           else cond[1];
plot Price = cond;
Price.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Super! One question solved!!! On the daily chart, everything is super!! Thanks!!There's only one thing left. I turn on the graph (example) 5 days 5 minutes or 2 days 1 minute and the level becomes "0". "Fit Studies" turned on and the indicator appeared at the level " 0 " and turned off, then the indicator disappeared.
 
@Armageddon Perhaps try this -
Code:
input endDate = 20210104;
def cond = if GetYYYYMMDD() < enddate then double.nan
           else if GetYYYYMMDD() == endDate then low(period = aggregationperiod.day)
           else cond[1];
plot Price = cond;
Price.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
How to attach a photo here is not easy to understand?
 
@Armageddon Can you see 01/04 on your chart? You need to be able to see the inputted date for the script to work.

Edit: Okay just saw the newer post. Your chart needs to include the inputted date for it to work.
 
@Armageddon Can you see 01/04 on your chart? You need to be able to see the inputted date for the script to work.

Edit: Okay just saw the newer post. Your chart needs to include the inputted date for it to work.
Ahhh! It's a pity if you can't do it. Just a date can be a year ago and a short timeframe for a year is a lot. But thanks for your help anyway!!!
 
Kory,

Curious on your coding for the stochastic indicator. When the indicator is overbought, I need it to look at the current price and compare it to the price the last time the indicator was overbought. If the current price is lower then I need the indicator to paint red. Same thing for oversold except if price is higher currently than previously, the indicator would paint green. If these conditions are not met when oversold or overbought, the indicator would be cyan. Any help would be appreciated.
 
@maston21 you can either use a fold (loop) to look back, or what i might do is just carry forward prevPriceOverbought/Oversold variables from the last signal.

psudeocode:

if (overbought)
prevPriceOverbought = close
else
prevPriceOverbought = prevPriceOverbought[1]

and just use it when you wish to compare
 
How do I modify the script to exclude the current candle?
There is no way to do that in this snippet. Perhaps after you add it to your script. You can subtract the current candle from your resulting calculations.
 
I was working on a request from a friend for highlighting a bar a given number of bars back, and then tracking the subsequent highest high and lowest low from that bar.

This ties into some other work I can share later where you can see where the most recent bars are relative to a lookback period like you might use in a SMA or Stochastic, etc.

Here is what the study looks like on a Ford (F) 1Y 1D chart.

xbL10wh.png


Some things to notice:
  • labels
  • chart bubble at (high+low)/2 on the lookback bar
  • purple squares at high and low on the lookback bar
  • purple squares have Bubbles hidden (on the right vertical axis)
  • LOW chart bubble
  • LOW line
  • HIGH chart bubble
  • HIGH line
Keeping track of and calculating which bar numbers are meaningful is fairly straightforward, but did take me a few attempts to get right. Debugging with labels helps a lot to troubleshoot some issues, and plotting values can also be a good diagnostic tool.

Code for HighLowLookback

Code:
#
# HighLowLookback
#
# Study to show the highest high and lowest low after a given number of bars back.
#
# Author: Kory Gill, @korygill
#
# VERSION HISTORY (sortable date and time (your local time is fine), and your initials
# 20190710-2200-KG    - created
# ...
# ...
#

#
# Inputs
#
input length = 13;

#
# Common Variables that may also reduce calls to server
#
def vClose = close;
def vLow = low;
def vHigh = high;
def nan = double.NaN;

#
# Logic
#
def currentBarNumber = if !IsNaN(vClose) then BarNumber() else nan;
def lastBarNumber = HighestAll(currentBarNumber);
def lookbackBar = lastBarNumber - length + 1;
def doPlot = if currentBarNumber >= lookbackBar then 1 else 0;

def mostRecentHigh = CompoundValue(1, if doPlot && vHigh > mostRecentHigh[1] then vHigh else mostRecentHigh[1],double.NEGATIVE_INFINITY);
def highBarNumber  = CompoundValue(1, if doPlot && vHIgh > mostRecentHigh[1] then currentBarNumber else highBarNumber[1],0);
plot mrh = if currentBarNumber >= HighestAll(highBarNumber) then mostRecentHigh else nan;
mrh.SetDefaultColor(Color.GREEN);

def mostRecentLow = CompoundValue(1, if doPlot && vLow < mostRecentLow[1] then vLow else mostRecentLow[1],double.POSITIVE_INFINITY);
def lowBarNumber  = CompoundValue(1, if doPlot && vLow < mostRecentLow[1] then currentBarNumber else lowBarNumber[1],0);
plot mrl = if currentBarNumber >= HighestAll(lowBarNumber) then mostRecentLow else nan;
mrl.SetDefaultColor(Color.RED);

#
# Visualizations
#
AddChartBubble(
    currentBarNumber == HighestAll(highBarNumber),
    vHigh,
    "HIGH",
    Color.WHITE,
    yes);

AddChartBubble(
    currentBarNumber == HighestAll(lowBarNumber),
    vLow,
    "LOW",
    Color.WHITE,
    no);

AddChartBubble(
    currentBarNumber == lookbackBar,
    (vHigh+vLow)/2,
    length+"\nBar",
    Color.GRAY,
    yes);

plot bbH = if currentBarNumber == lookbackBar then vHigh + TickSize()*1 else nan;
bbH.SetPaintingStrategy(PaintingStrategy.SQUARES);
bbH.SetDefaultColor(Color.MAGENTA);
bbH.SetLineWeight(5);
bbH.HideBubble();

plot bbL = if currentBarNumber == lookbackBar then vLow - TickSize()*1 else nan;
bbL.SetPaintingStrategy(PaintingStrategy.SQUARES);
bbL.SetDefaultColor(Color.MAGENTA);
bbL.SetLineWeight(5);
bbL.HideBubble();

#
# Labels
#
AddLabel(yes,
"mostRecentHigh: " + mostRecentHigh,
Color.Gray);

AddLabel(yes,
"mostRecentLow: " + mostRecentLow,
Color.Gray);

Shareable Link to flexgrid and code
https://tos.mx/lNzBi8
is there a way to extend these lines to the right side?
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
561 Online
Create Post

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