Percent Points Based On Open For ThinkOrSwim

clarkymlarky

New member
Hi, I want to plot 6 different price points based on a strategy I have. Basically they are price points that are related to the opening price. Its annoying to have to manually draw the price levels every day, so I was wondering if there was a way I could have them inputted beforehand. I need the price points to be inputted based on percentage change from the opening price of the day. Hopefully someone can help
 
UPDATED 6/5/2022
Percent Points Based On Open For ThinkOrSwim
ogTiVjm.png

Ruby:
# Percent Points Based On Open For ThinkOrSwim
# @Svanoy UPDATED 6/5/2022
input periodstart = 0930;
input periodend = 1630;
input Target_Percentage = 1.0;
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 daystart = SecondsFromTime(periodstart) == 0;
def activeperiod = if SecondsFromTime(periodstart) >= 0 and SecondsTillTime(periodend) > 0 then yes else Double.NaN;

def dayopen = if daystart then open else DayOpen[1];
def o = fold io = 0 to 1 while !IsNaN(close[10]) do dayopen;

plot DayOpenPlot = if o > 0 and activeperiod then o else Double.NaN;
DayOpenPlot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayOpenPlot.AssignValueColor(color.white);

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

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 activeperiod then a else Double.NaN;
PP1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP1.AssignValueColor(color.white);

plot PP2 = if b > 0 and activeperiod then b else Double.NaN;
PP2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP2.AssignValueColor(color.white);

plot PP3 = if c > 0 and activeperiod then c else Double.NaN;
PP3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP3.AssignValueColor(color.white);

plot PP4 = if d > 0 and activeperiod then d else Double.NaN;
PP4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP4.AssignValueColor(color.white);

plot PP5 = if e > 0 and activeperiod then e else Double.NaN;
PP5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP5.AssignValueColor(color.white);

plot PP6 = if f > 0 and activeperiod then f else Double.NaN;
PP6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP6.AssignValueColor(color.white);

AddChartBubble(!IsNaN(DayOpenPlot) and IsNaN(DayOpenPlot[-1]) and activeperiod,dayopen,"Day Open",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);

Alert(activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)), "Target Hit", Alert.BAR, Sound.Ding);

AddLabel(yes,if activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)) then "Target Hit" else "          ",if activeperiod and ((close[1] > Target_Percentage and close <= Target_Percentage) or (close[1] < Target_Percentage and close >= Target_Percentage)) then color.green else color.gray);
 
Last edited by a moderator:
@Svanoy there is one issue with this script. when the stock price is below 1$, the price levels dont appear. I think its because calculating percentage differences is weird when the price is a decimal
 
@clarkymlarky my mistake, for some reason I assumed the values would be greater than 1. Just had to change the plot statement conditions to greater than 0 instead of greater than 1.

Fix in my post above.
excellent tool, would you help me set alarms and visual alarms (sosora and visual label) when a certain percentage passes? Thank you
 
Last edited by a moderator:
@Autotrade Modified my last post to add an input for 'Target Percentage', an alert for 'close crossing above or below Target Percentage', and a label with the same criteria as the alert.
I have not tested the added code.
 
@Autotrade Modified my last post to add an input for 'Target Percentage', an alert for 'close crossing above or below Target Percentage', and a label with the same criteria as the alert.
I have not tested the added code.
thank you! Sorry but I can't find the update, you'd be so kind to send the link, thank you
 

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