Plotting 4 decimal points instead of just two?

Ian_Tai

New member
Hello all -

I've lately been interested in range and when to take profit and when to accept a loss. I found someone else's indicator that compares Day Range to ATR in a label format that I would like to use. But, it only plots two decimals. Not effective for FX trading. I'll post the code below. Would appreciate a tip. Thanks.

Code:
##### TS ATR
##### Made By Leonard
##### Version 1
##### 4/23/2015
##### Copyright Leonard Tulko 2014 - 2015 All rights reserved
##### This software is licensed for individual use only.


declare upper;

input ATRLength = 14;
input averagetype = AverageType.WILDERS;
input BasePeriod = AggregationPeriod.DAY;
input showlabel = yes;

def ATR = MovingAverage (averagetype, TrueRange(high(period = BasePeriod)[1], close(period = BasePeriod)[1], low(period = BasePeriod)[1]), ATRLength);

def Today_High = Highest(high(period = baseperiod)[0], 1);
def Today_Low = Lowest(low(period =baseperiod)[0], 1);

def DR = Today_High - Today_Low;

AddLabel(showlabel, "DayRange: " + Round(DR , 2) + " - ATR:" +round(ATR,2));
 
Last edited by a moderator:

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

Glad you got what you want. You are telling it to round to 4 digits. So when you removed round but not the # of digits to round to it gave the error.
I should have been clearer in my previous answer.
AddLabel(showlabel, "DayRange: " + (DR ) + " - ATR:" +(ATR));
 
Does anyone know how to output a specific amount of decimal places? Thinkorswm talks about using the Numberformat function, but that doesnt seem to work. For instance I want this output to show 5 decimal places:
def SMA = Average(price[-displace], length);
plot zero=0;
plot output=((SMA-SMA[1])/close)*100;

ive tried using round, but that doesnt seem to help. I can't find any docs to help.
Any help would be great, thank you!
 
Plot values read out in the data box has just 2 decimal points. Any way to increase the precision to say 4 decimal points for specific plots in the data box?
 
Last edited:
Not that I am aware of. You could multiply the target value by 100 to bring the digits into view.

It scales automatically with the size of the number.

Plot - Data Box

0.123456 --> 0.123456

1.123456 --> 1.12346

10.123456 --> 10.1235

100.123456 --> 100.123

1000.123456 --> 1000.12

10000.123456 -- > 10000.1

100000.123456 -- > 100000
 
Last edited:
In this example it runs out to about 5 or six decimal places.

#plot NextHigh = fold i = 0 to 100 with price = Double.NaN while IsNaN(price) do if getValue(high, -i, -99) > 40 #then getValue(high, -i, -99) else Double.NaN;

# UpPoints DownPoints Ratio
# tomsk
# 1.17.2020

# Plots the ratio of Up/Down points relative to the prior candle

declare lower;



def o = open;
def h = high;
def l = low;
def c = close;
def UpO;
def UpH;
def UpL;
def UpC;
if o < c
then {
UpO = o;
UpH = h;
UpL = l;
UpC = c;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}

# OHLC DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
DnO = o;
DnH = h;
DnL = l;
DnC = c;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
AddChart(high = UpH, low = UpL, open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);

def upPoints = fold i = 0 to 21
with p
do p + GetValue(if close == h[1] then close + close[1] else 0,( i));
plot Countup= sum(uppoints);
countup.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_Up);

def downPoints = fold j = 0 to 21
with r
do r + GetValue(if close < h[1] then close + close[1] else 0, j);

plot Countdown=Sum(downPoints);

AddLabel(1,"Up Points Count " + Countup + " %", color.white);
AddLabel(1, "Up Points = " + upPoints, Color.YELLOW);
AddLabel(1, "Down Points = " + downPoints, Color.YELLOW);
AddLabel(1,"Down Points Count " + CountDown + " %", color.white);
# End UpPoints DownPoints Ratio

plot NextHigh = fold u = 0 to 100 with price = Double.NaN while IsNaN(price) do if getValue(high, -u, -99) > 40 then getValue(high, -u, -99) else Double.NaN;
NextHigh.setPaintingStrategy(paintingStrategy.HISTOGRAM);
nexthigh.setdefaultcolor(color.BLUE);

input price1 = close;
input length = 21;
plot SMA = (fold n = 0 to length with s do s + getValue(price1, n, length - 1)) / length;
 
Such inflated 100x plots mess up the visuals of the underlying price chart. I am deliberately using decimal plots so they stay very low on the price scale and hence do not interfere with the visual price chart. I don't need these plot values all the time and when needed I use the data box for the read out.

Not that I am aware of. You could multiply the target value by 100 to bring the digits into view.

It scales automatically with the size of the number.

Plot - Data Box

0.123456 --> 0.123456

1.123456 --> 1.12346

10.123456 --> 10.1235

100.123456 --> 100.123

1000.123456 --> 1000.12

10000.123456 -- > 10000.1

100000.123456 -- > 100000
 
what is this?? how does it help?

I've noticed adding study with "declare lower" displays more decimals on the databox read out. Without "declare lower" its just 2 dp on the databox read out. Adding "declare lower" but then moving the study from sub-graph to the main chart continues to display more decimals in the databox read out. However, the "declare lower" study scale does not align with the main charts scale i.e. it has its own scale and the plots mess with the main chart visuals. So cannot use this "declare lower" work arnd.


In this example it runs out to about 5 or six decimal places.

#plot NextHigh = fold i = 0 to 100 with price = Double.NaN while IsNaN(price) do if getValue(high, -i, -99) > 40 #then getValue(high, -i, -99) else Double.NaN;

# UpPoints DownPoints Ratio
# tomsk
# 1.17.2020

# Plots the ratio of Up/Down points relative to the prior candle

declare lower;



def o = open;
def h = high;
def l = low;
def c = close;
def UpO;
def UpH;
def UpL;
def UpC;
if o < c
then {
UpO = o;
UpH = h;
UpL = l;
UpC = c;
} else {
UpO = Double.NaN;
UpH = Double.NaN;
UpL = Double.NaN;
UpC = Double.NaN;
}

# OHLC DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
DnO = o;
DnH = h;
DnL = l;
DnC = c;
} else {
DnO = Double.NaN;
DnH = Double.NaN;
DnL = Double.NaN;
DnC = Double.NaN;
}
AddChart(high = UpH, low = UpL, open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);

def upPoints = fold i = 0 to 21
with p
do p + GetValue(if close == h[1] then close + close[1] else 0,( i));
plot Countup= sum(uppoints);
countup.setPaintingStrategy(paintingStrategy.BOOLEAN_ARROW_Up);

def downPoints = fold j = 0 to 21
with r
do r + GetValue(if close < h[1] then close + close[1] else 0, j);

plot Countdown=Sum(downPoints);

AddLabel(1,"Up Points Count " + Countup + " %", color.white);
AddLabel(1, "Up Points = " + upPoints, Color.YELLOW);
AddLabel(1, "Down Points = " + downPoints, Color.YELLOW);
AddLabel(1,"Down Points Count " + CountDown + " %", color.white);
# End UpPoints DownPoints Ratio

plot NextHigh = fold u = 0 to 100 with price = Double.NaN while IsNaN(price) do if getValue(high, -u, -99) > 40 then getValue(high, -u, -99) else Double.NaN;
NextHigh.setPaintingStrategy(paintingStrategy.HISTOGRAM);
nexthigh.setdefaultcolor(color.BLUE);

input price1 = close;
input length = 21;
plot SMA = (fold n = 0 to length with s do s + getValue(price1, n, length - 1)) / length;
 
Last edited:
Are you using an upper study, with "fit studies" disabled, while keeping your plots so small that they are out of view, just for the sake of the databox? Is this correct?
 
yes, thats right. To keep them out of view, I have these plot values in decimals and that keeps them away from interfering with the price chart visual. I don't look up penny or low price stocks, so this method works for me for that occasional data box read out of some variable/plot.

Are you using an upper study, with "fit studies" disabled, while keeping your plots so small that they are out of view, just for the sake of the databox? Is this correct?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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