Horizontal Lines In ThinkOrSwim

Hello my fellow code geeks -

I've been a long time admirer of this community and i learnt little coding.
i was looking for SR Lines (Support Resistance lines) that joins two or more candles that has same close price. Something like below snip.

See if this helps

Capture.jpg
Ruby:
input minimum_consequtive = 2;
def c = if Sum( close == close[1], minimum_consequtive) >= minimum_consequtive
        then close
        else c[1];
plot x = c;
x.SetPaintingStrategy(PaintingStrategy.DASHES);
x.setlineWeight(3);
 
@SorcererPrince How would you define a minute on a tick chart? There are no timeframes on tick charts. It is possible to get some limited time math functionality of range charts.
 
Okay. So there is no way to draw a horizontal line every one minute on a tick chart?
You can draw lines but the key with the 'not translating well' is that each bar on a tick chart takes a different amount of time to complete. If looking at a bigger tick chart, it may take 3 minutes for one candle and 30 seconds for the next. TOS makes 'calculations' per candle. That's why it is difficult to translate between the two. But it is not impossible. You just have to remember this fact.
 
You can draw lines but the key with the 'not translating well' is that each bar on a tick chart takes a different amount of time to complete. If looking at a bigger tick chart, it may take 3 minutes for one candle and 30 seconds for the next. TOS makes 'calculations' per candle. That's why it is difficult to translate between the two. But it is not impossible. You just have to remember this fact.
Okay. Thanks. Will try to figure it out myself.
 
The bottom image, is my "5 Day Vol: xxx" label, that is shown on the top of the first image. I thought I'd be able to figure out how to make the price levels appear automatically, that I manually have drawn on the chart, using much of the same basic information.

The price levels, on the daily chart, start from the 5th bar back (turning off left extension), moving forward... The highest point, and lowest point, of the last 5 daily bars.

This thread has a lot of info about price levels, but I can't make any of it fit together with what I want in my head! How could this be done?

HiLo5-2.jpg


HiLo5-1.jpg
 
The bottom image, is my "5 Day Vol: xxx" label, that is shown on the top of the first image. I thought I'd be able to figure out how to make the price levels appear automatically, that I manually have drawn on the chart, using much of the same basic information.

The price levels, on the daily chart, start from the 5th bar back (turning off left extension), moving forward... The highest point, and lowest point, of the last 5 daily bars.

This thread has a lot of info about price levels, but I can't make any of it fit together with what I want in my head! How could this be done?

HiLo5-2.jpg


HiLo5-1.jpg

Try this

Ruby:
def high5 = Highest(high(period = AggregationPeriod.DAY), 5);
def low5  = Lowest(low(period = AggregationPeriod.DAY), 5);
AddLabel(1, "H: " + astext(high5), Color.GREEN);
AddLabel(1, "L: " + astext(low5), Color.LIGHT_RED);
 
Instead of making it as the label, I'd like it to display as the actual price lines on the chart.

** Edit to add: I kinda like those labels, hadn't thought of that before. But I'd still like the price line/levels drawn...

Try this

Capture.jpg
Ruby:
def high5 = if IsNaN(close) then high5[1] else Highest(high(period = AggregationPeriod.DAY), 5);
def low5  = if IsNaN(close()) then low5[1]  else Lowest(low(period = AggregationPeriod.DAY), 5);

AddLabel(1, "H: " + AsText(high5), Color.GREEN);
AddLabel(1, "L: " + AsText(low5), Color.LIGHT_RED);

def bn    = barnumber();
def last  = highestall(if isnan(close[-1]) and !isnan(close) then bn else double.nan);

plot hi5  = if Bn < last then Double.NaN else high5;
hi5.SetPaintingStrategy(PaintingStrategy.DASHES);

plot lo5  = if Bn < last then Double.NaN else low5;
lo5.SetPaintingStrategy(PaintingStrategy.DASHES);
 
This is the JScript.Please ook the "Parsefloat" function. it pics up the first available clse or 1st available bar's close when the condition is satisfied and plots the line starting the bar where 1st close price is detected.


function draw_sr_lines(sr_lines) {
remove_sr_lines();
for (let x = 0; x < sr_lines.length; x++) {
plotLines.push(
chart.yAxis[0].addPlotLine({
value: parseFloat(sr_lines[x]),
color: "#ffffff",
width: 1,
dashStyle: "dash",
label: {
text: "SR Level = $" + parseFloat(sr_lines[x]).toString(),
style: {
color: "white",
},
x: 50,
},
zIndex: 3,
})
);
}
}
 
See if this helps

This is my version of code. but its not even close to that in the picture in plotting the lines.

input LookFrontPeriod = 50;
def vClose = Round(Close, 1);
def vOpen = Round(Open, 1);
def bn = barnumber();
def nan = double.NaN;

#--------------------------------------------------------------
def _CloseInPeriod = vClose;

#--------------------------------------------------------------
##Logic: for every bar's close value, look front LookFrontPeriod bars for same close, if true then return close else move ahead one bar front
def marketClose1 = if _CloseInPeriod == _CloseInPeriod[LookFrontPeriod] then _CloseInPeriod else nan;
def marketClose1bn = if _CloseInPeriod == _CloseInPeriod[LookFrontPeriod] then bn else marketClose1bn[1];

##if above def is true then capture the close price of the bar where the def first is true
def _markedClose1 = vClose == marketClose1;
def _markedClose1bn = bn == marketClose1bn;

##Loop until no close price exist on the chart i.e until last bar of the chart
rec _lastMarkedLow1 = CompoundValue(1, if IsNaN(_markedClose1) then _lastMarkedLow1[1] else if _markedClose1 then vClose else _lastMarkedLow1[1], vClose);
rec _lastMarkedLow1bn = CompoundValue(1, if IsNaN(_markedClose1bn) then _lastMarkedLow1bn[1] else if _markedClose1bn then _markedClose1bn else _lastMarkedLow1bn[1], bn);

#--------------------------------------------------------------
##Plots and formatting

plot SR1 = Lowestall(_lastMarkedLow1);
#plot SR1 = Highestall(_lastMarkedLow1);
#SR1.SetStyle(Curve.Short_Dash);
SR1.SetLineWeight(1);
#SR1.SetDefaultColor(color.gray);
SR1.AssignValueColor(if vClose == SR1 then color.gray else
if vClose > SR1 then Color.Dark_Green else
if vClose < SR1 then Color.Dark_Red else color.gray);
AssignPriceColor(if vClose == SR1 then color.magenta else color.current);
 
I found this on TOS education center but I don't know how to use..

GetAveragePrice​

GetAveragePrice ( Symbol symbol);

Default values:

symbol: current symbol

Description​

Returns the average trade price for a specified instrument, for the currently selected account.
 
Is it possible to plot a line between the latest values of two simple moving averages, say of 10 and 200?
 
I found this on TOS education center but I don't know how to use..

GetAveragePrice​

GetAveragePrice ( Symbol symbol);

Default values:

symbol: current symbol

Description​

Returns the average trade price for a specified instrument, for the currently selected account.
@xleb27
So I am pretty new to ThinkScript but this put a line on my options trade I did Friday morning:
(The price line is the cyan line on the bottom)

Code:
plot intAvgCost = if GetAveragePrice() == 0 then double.nan else GetAveragePrice();
AvgCost.png
 
Is it possible to plot a line between the latest values of two simple moving averages, say of 10 and 200?

Here is one way to do that with the unsupported addchart() function. You can move the line left/right at the input offset.

Capture.jpg
Ruby:
plot ma1 = SimpleMovingAvg(close, 10);
plot ma2 = SimpleMovingAvg(close, 100);
ma1.SetLineWeight(2);
ma2.SetLineWeight(2);

input offset = -1;#hint offset: use to move line left/right
def last     = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else 0;
def ma1last  = if BarNumber() == HighestAll(last + 1) then GetValue(ma1, 1) else 0;
def ma2last  = if BarNumber() == HighestAll(last + 1) then GetValue(ma2, 1) else 0;

AddChart(Max(ma1last[offset], ma2last[offset]), Min(ma1last[offset], ma2last[offset]), 0, 0, ChartType.BAR, growColor = Color.WHITE);
 

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