• Get $40 off VIP by signing up for a free account! Sign Up

Need Help with Tos code writing.

soni1

New member
Hello, I need help writing a TOS code for getting some levels from low and high of day. So example would be to start with I need to take low and high of previous day. Thank I need to take a certain percentage from low and high of day to come up with targets. Example

Low of day 202.51 Buy level would be 202.51*.002, Stoploss would be 202.51*.999% Target1 would be 202.51*1.45% Target 2 would be 202.51*2%. So I should be able to Change the low price any time and new targets should be calculated based on percentages i mentioned with lines on the chart. Please help if possible. Thanks in advance!
 

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

Hello, I need help writing a TOS code for getting some levels from low and high of day. So example would be to start with I need to take low and high of previous day. Thank I need to take a certain percentage from low and high of day to come up with targets. Example

Low of day 202.51 Buy level would be 202.51*.002, Stoploss would be 202.51*.999% Target1 would be 202.51*1.45% Target 2 would be 202.51*2%. So I should be able to Change the low price any time and new targets should be calculated based on percentages i mentioned with lines on the chart. Please help if possible. Thanks in advance!

here is one way to draw lines, based on yesterdays low

Code:
#prev_day_levels_targets

#https://usethinkscript.com/threads/need-help-with-tos-code-writing.16990/
#Need Help with Tos code writing.
#soni1  11/7

# take low and high of previous day.
# take a certain percentage from low and high of day to come up with targets.

# example, Low of day 202.51
#  Buy level would be  low of prev day * 0.2%
#   Stoploss would be  low of prev day * 0.999%
#   Target 1 would be  low of prev day * 1.45%
#   Target 2 would be  low of prev day * 2%

#  So I should be able to Change the low price any time and new targets should be calculated based on percentages i mentioned with lines on the chart.


def na = Double.NaN;
def bn = BarNumber();
def big = 99999;

def istoday = if GetLastDay() == GetDay() then 1 else 0;
def day_last = (istoday and !istoday[-1]);
#addverticalline(day_last, "-", color.cyan);

input buy_per = 0.2;
input stop_per = -0.1;
input target1_per = 1.5;
input target2_per = 2.0;

#input agg = AggregationPeriod.DAY;
#def day_low = low(period = agg);
#def day_high = high(period = agg);

def days_back = 1;
def data_day = (getday() + days_back) == getlastday();

def day_high = if bn == 1 then 0
 else if data_day then max(high, day_high[1])
 else day_high[1];
def day_low = if bn == 1 then big
 else if data_day then min(low, day_low[1])
 else day_low[1];

def target2 = day_low[1] * (1 + (target2_per/100));
def target1 = day_low[1] * (1 + (target1_per/100));
def buy = day_low[1] * (1 + (buy_per/100));
def stop = day_low[1] * (1 + (stop_per/100));

plot zt2 = if istoday then target2 else na;
plot zt1 = if istoday then target1 else na;
plot zb = if istoday then buy else na;
plot zs = if istoday then stop else na;

zt2.SetDefaultColor(Color.light_gray);
zt2.hidebubble();
zt1.SetDefaultColor(Color.light_gray);
zt1.hidebubble();
zb.SetDefaultColor(Color.green);
zb.hidebubble();
zs.SetDefaultColor(Color.red);
zs.hidebubble();

input level_bubbles = yes;
addchartbubble(level_bubbles and day_last, target2, "Target 2  " + asdollars(target2) + "  " + round(target2_per,2) + "%", color.yellow, yes);
addchartbubble(level_bubbles and day_last, target1, "Target 1  " + asdollars(target1)  + "  " + round(target1_per,2) + "%", color.yellow, yes);
addchartbubble(level_bubbles and day_last, buy, "Buy  " + asdollars(buy)  + "  " + round(buy_per,2) + "%", color.yellow, no);
addchartbubble(level_bubbles and day_last, stop, "Stop  " + asdollars(stop)  + "  " + round(stop_per,2) + "%", color.yellow, no);

# ------------------

input test1_prev_low_level = no;
plot zlo = if test1_prev_low_level and istoday then day_low else na;
zlo.SetStyle(Curve.MEDIUM_DASH);
zlo.SetDefaultColor(Color.magenta);
# .setlineweight(1);

input test2_data_day_levels = no;
plot z1 = if test2_data_day_levels and day_high > 0 and data_day then day_high else na;
plot z2 = if test2_data_day_levels and day_low < big and data_day then day_low else na;
#

OQTjDtR.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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