indicator: x% from current price

ARL

Member
Plus
Greetings! Any ideas on how an indicator could show what x% from current price above and below the current bar would look like? For example, the illustration below could be showing 1.5% above & below the current price, changing position dynamically as the price changes.

I believe this would be a helpful visual in managing risk by seeing what the "x% from" looks like relative to other indicators like MAs, support/resistance, etc. Right now, this is being done with a calculator on a spreadsheet and I suspect there's a much better way. I didn't find anything about this in the forums. Thanks!

https%3A//i.imgur.com/RRB7X6F.jpg[/img]']
RRB7X6F.jpg
 

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

Hi, Svanoy. Thanks for your reply. Your solution would work for representing the x% from CURRENT bar's price on, say, a five minute chart? It seems it works for the opening only on a static basis and not dynamically throughout the day for the current bar. Maybe I'm misunderstanding the script.
 
As I stated in my previous post, you will have to change the definition line of 'dayopen' to whatever price level you want it to be. Written to update realtime:

@ARL
Ruby:
input Price_Point_1_Percentage = 1.5;
input Price_Point_2_Percentage = 1.0;
input Price_Point_3_Percentage = 0.5;
input Price_Point_4_Percentage = -0.5;
input Price_Point_5_Percentage = -1;
input Price_Point_6_Percentage = -1.5;

def Start = if !IsNaN(close) and IsNaN(close[-1]) then close else Start[1];
def o = fold io = 0 to 1 while !IsNaN(close[10]) do Start;

plot StartPlot = if o > 0 and IsNaN(close[-1]) then o else Double.NaN;
StartPlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
StartPlot.AssignValueColor(color.white);

def pricepoint1 = (Start * (Price_Point_1_Percentage/100)) + Start;
def pricepoint2 = (Start * (Price_Point_2_Percentage/100)) + Start;
def pricepoint3 = (Start * (Price_Point_3_Percentage/100)) + Start;
def pricepoint4 = (Start * (Price_Point_4_Percentage/100)) + Start;
def pricepoint5 = (Start * (Price_Point_5_Percentage/100)) + Start;
def pricepoint6 = (Start * (Price_Point_6_Percentage/100)) + Start;

def a = fold ia = 0 to 1 while !IsNaN(close[10]) do pricepoint1;
def b = fold ib = 0 to 1 while !IsNaN(close[10]) do pricepoint2;
def c = fold ic = 0 to 1 while !IsNaN(close[10]) do pricepoint3;
def d = fold id = 0 to 1 while !IsNaN(close[10]) do pricepoint4;
def e = fold ie = 0 to 1 while !IsNaN(close[10]) do pricepoint5;
def f = fold if = 0 to 1 while !IsNaN(close[10]) do pricepoint6;

plot PP1 = if a > 0 and IsNaN(close[-1]) then a else Double.NaN;
PP1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP1.AssignValueColor(color.white);

plot PP2 = if b > 0 and IsNaN(close[-1]) then b else Double.NaN;
PP2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP2.AssignValueColor(color.white);

plot PP3 = if c > 0 and IsNaN(close[-1]) then c else Double.NaN;
PP3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP3.AssignValueColor(color.white);

plot PP4 = if d > 0 and IsNaN(close[-1]) then d else Double.NaN;
PP4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP4.AssignValueColor(color.white);

plot PP5 = if e > 0 and IsNaN(close[-1]) then e else Double.NaN;
PP5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP5.AssignValueColor(color.white);

plot PP6 = if f > 0 and IsNaN(close[-1]) then f else Double.NaN;
PP6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP6.AssignValueColor(color.white);

AddChartBubble(!IsNaN(StartPlot) and IsNaN(StartPlot[-1]) ,Start,"Start Price",Color.WHITE,if Price_Point_1_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP1) and IsNaN(PP1[-1]),a,"Price Point 1: "+Price_Point_1_Percentage+"%",Color.WHITE,if Price_Point_1_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP2) and IsNaN(PP2[-1]),b,"Price Point 2: "+Price_Point_2_Percentage+"%",Color.WHITE,if Price_Point_2_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP3) and IsNaN(PP3[-1]),c,"Price Point 3: "+Price_Point_3_Percentage+"%",Color.WHITE,if Price_Point_3_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP4) and IsNaN(PP4[-1]),d,"Price Point 4: "+Price_Point_4_Percentage+"%",Color.WHITE,if Price_Point_4_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP5) and IsNaN(PP5[-1]),e,"Price Point 5: "+Price_Point_5_Percentage+"%",Color.WHITE,if Price_Point_5_Percentage >= 0 then yes else no);
AddChartBubble(!IsNaN(PP6) and IsNaN(PP6[-1]),f,"Price Point 6: "+Price_Point_6_Percentage+"%",Color.WHITE,if Price_Point_6_Percentage >= 0 then yes else no);
 
Last edited by a moderator:
  • To The Moon
Reactions: ARL
Right on, Svanoy . . . THANK YOU! I modified it to display inputs 1 & 6 only and it's perfect for my application. Have it running in OnDemand now and it looks great. Appreciate your attention to this. Take care. =A=
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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