THINKorSWIM RISK REWARD INDICATOR

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

@generic This is what I did to move the script to the right of the candles. Any suggestions or update is much appreciated!!

input action = {Default "Long","Short"};
input entry_price = 2.75;
input sl_percent =0.3;
input rr_ratio = 2;
input position_size = 2000;
input offset = 5;
def shares = position_size / entry_price;
plot stop;
switch (action) {
case Long:
stop = if isnan(close[5]) then round((position_size - (sl_percent * position_size / 100)) / shares)
else double.nan;
Case Short:
stop = if isnan(close[5]) then round((position_size + (sl_percent * position_size / 100)) / shares)
else double.nan;}

plot entry = if isnan(close[5]) then entry_price else double.nan;
plot t1 = if isnan(close[5]) then entry_price + rr_ratio * (entry_price - stop) else double.nan;
plot t2 = if isnan(close[5]) then entry_price + (2 * rr_ratio) * (entry_price - stop) else double.nan;
plot t3 = if isnan(close[5]) then entry_price + (3 * rr_ratio) * (entry_price - stop) else double.nan;
AddCloud(entry_price, stop, Color.GRAY, Color.GRAY);
AddCloud(t1, t2, Color.GREEN, Color.GREEN);
AddCloud(t2, t3, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddChartBubble(IsNaN(close[5]) and !IsNaN(close[6]), entry_price, entry_price, Color.Light_Gray);
AddChartBubble(IsNaN(close[5]) and !IsNaN(close[6]), t1, "T1 $" + t1, Color.GREEN);
AddChartBubble(IsNaN(close[5]) and !IsNaN(close[6]), t2, "T2 $" + t2, Color.GREEN);
AddChartBubble(IsNaN(close[5]) and !IsNaN(close[6]), t3, "T3 $" + t3, Color.GREEN);
AddChartBubble(IsNaN(close[5]) and !IsNaN(close[6]), stop, "STOP $" + stop, Color.RED, no);
 
@s1111
Code:
input action = {Default "Long","Short"};
input entry_price = 2.75;
input sl_percent =0.3;
input rr_ratio = 2.0;
input position_size = 2000;
input offset = 5;

def line_plot = IsNaN(close[offset]);
def label_plot = IsNaN(close[offset]) and !IsNaN(close[offset + 1]);

def shares = position_size / entry_price;
plot stop;
switch (action) {
case Long:
stop = if line_plot then round((position_size - (sl_percent * position_size / 100)) / shares)
else double.nan;
Case Short:
stop = if line_plot then round((position_size + (sl_percent * position_size / 100)) / shares)
else double.nan;}

plot entry = if line_plot then entry_price else double.nan;
plot t1 = if line_plot then entry_price + rr_ratio * (entry_price - stop) else double.nan;
plot t2 = if line_plot then entry_price + (2 * rr_ratio) * (entry_price - stop) else double.nan;
plot t3 = if line_plot then entry_price + (3 * rr_ratio) * (entry_price - stop) else double.nan;
AddCloud(entry_price, stop, Color.GRAY, Color.GRAY);
AddCloud(t1, t2, Color.GREEN, Color.GREEN);
AddCloud(t2, t3, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddChartBubble(label_plot, entry_price, entry_price, Color.Light_Gray);
AddChartBubble(label_plot, t1, "T1 $" + t1, Color.GREEN);
AddChartBubble(label_plot, t2, "T2 $" + t2, Color.GREEN);
AddChartBubble(label_plot, t3, "T3 $" + t3, Color.GREEN);
AddChartBubble(label_plot, stop, "STOP $" + stop, Color.RED, no);
 
Last edited:
@madburg Ill check it out after market close today, post a ss if you can. The squished chart might be because you have Fit Studies enabled.
You were correct the option "Fit Studies" was enabled, once I disabled it your script worked as expected and that behavior of a squished chart stopped. Thank you.

Any idea why if I try to pull both average price and quantity dynamically it doesn't work?:

Replacing "input entry_price = 2.75;" with "def entry_price = GetAveragePrice();"
Replacing "input position_size = 50;" with "def position_size = GetQuantity();"
 
@madburg I think portfolio functions need to be enabled in your TD account settings which you need to ask TOS support for. I'm not 100% sure on this.
 
@rwfarrell @hockeycoachdoug Only works for long, I'll add short to it if you guys are gonna use this.
Code:
input amount = 2000;
input risk = 100;
input price = 2.75;
input ratio = 2;

def shares = floor(amount / price);
plot stop = if isnan(close[-1]) then round((amount - risk) / shares) else double.nan;
plot entry = if isnan(close[-1]) then price else double.nan;
plot t1 = if isnan(close[-1]) then price + ratio * (price - stop) else double.nan;
plot t2 = if isnan(close[-1]) then price + (2 * ratio) * (price - stop) else double.nan;
plot t3 = if isnan(close[-1]) then price + (3 * ratio) * (price - stop) else double.nan;

addcloud(price, stop, color.gray, color.gray);
addcloud(t1, t2, color.green, color.green);
addcloud(t2, t3, color.light_green, color.light_green);

addchartbubble(isnan(close[2]) and !isnan(close[3]), price, price, color.white);
addchartbubble(isnan(close[2]) and !isnan(close[3]), t1, "T1 $" + t1, color.green);
addchartbubble(isnan(close[2]) and !isnan(close[3]), t2, "T2 $" + t2, color.green);
addchartbubble(isnan(close[2]) and !isnan(close[3]), t3, "T3 $" + t3, color.green);
addchartbubble(isnan(close[2]) and !isnan(close[3]), stop, "STOP $" + stop, color.red, no);
addchartbubble(isnan(close[10]) and !isnan(close[11]), price, "SHARES:" + shares, color.yellow);
What is input ratio? Input price?? Thank you
 
can this be tied to a delta for options to the stop price? So if im buying the option price at $5.00 with a delta of ..50 and i want a risk reward of 3/1 the stock has to move $3.00 to get a $1.50 move etc
 
can this be tied to a delta for options to the stop price? So if im buying the option price at $5.00 with a delta of ..50 and i want a risk reward of 3/1 the stock has to move $3.00 to get a $1.50 move etc
No delta is not available for your script
 
@otterflips What ticker were you looking at? I think the point of this indicator is to have the freedom of manual inputs but I can make some changes when I have time. Lmk know what you're looking for and I'll try to adjust it

anyway can be somewhat automated? or when there is no trade have it at the current price bar?any options on getting it to plot once certain conditions are met or levels are broken? kind of like how the ORB strategy doesnt generate targets until conditions are met,,,

any assiastance will be greatly appreciated
 
anyway can be somewhat automated? or when there is no trade have it at the current price bar?any options on getting it to plot once certain conditions are met or levels are broken? kind of like how the ORB strategy doesnt generate targets until conditions are met,,,

any assiastance will be greatly appreciated
They cannot be automated. The only thing you can do is create a strategy that prints entries and exists on the chart.
 
I created the study and copy and pasted the code in and the code checks out with no errors. I have been using it on the daily time frame. If I check the left axis button., the values will show up on the left, but not to scale on the chart. In other words where it might say price target #1 is at 83, the price bubble says 83 but the level it is displayed at might be 100. And there are no lines drawn. I believe when fully working there will be lines drawn indicating entry, stop loss, and three price target levels and price bubbles reflecting those values on the right. I have tried using varying inputs like different position sizes, r/r, stop loss values etc. but to no avail. I have used other custom scripts with no issues in the past, so I am not sure why this one is giving me trouble.

Brand new to TOS. This is the code:
input action = {Default "Long","Short"};
input entry_price = 2.75;
input sl_percent = 2.0;
input rr_ratio = 2;
input position_size = 2000;

def shares = position_size / entry_price;
plot stop;
switch (action) {
case Long:
stop = if isnan(close[-1]) then round((position_size - (sl_percent * position_size / 100)) / shares)
else double.nan;
Case Short:
stop = if isnan(close[-1]) then round((position_size + (sl_percent * position_size / 100)) / shares)
else double.nan;}

plot entry = if isnan(close[-1]) then entry_price else double.nan;
plot t1 = if isnan(close[-1]) then entry_price + rr_ratio * (entry_price - stop) else double.nan;
plot t2 = if isnan(close[-1]) then entry_price + (2 * rr_ratio) * (entry_price - stop) else double.nan;
plot t3 = if isnan(close[-1]) then entry_price + (3 * rr_ratio) * (entry_price - stop) else double.nan;
AddCloud(entry_price, stop, Color.GRAY, Color.GRAY);
AddCloud(t1, t2, Color.GREEN, Color.GREEN);
AddCloud(t2, t3, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), entry_price, entry_price, Color.WHITE);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t1, "T1 $" + t1, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t2, "T2 $" + t2, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t3, "T3 $" + t3, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), stop, "STOP $" + stop, Color.RED, no);
AddChartBubble(IsNaN(close[10]) and !IsNaN(close[11]), entry_price, "SHARES:" + Floor(shares), Color.YELLOW);
 
I created the study and copy and pasted the code in and the code checks out with no errors. I have been using it on the daily time frame. If I check the left axis button., the values will show up on the left, but not to scale on the chart. In other words where it might say price target #1 is at 83, the price bubble says 83 but the level it is displayed at might be 100. And there are no lines drawn. I believe when fully working there will be lines drawn indicating entry, stop loss, and three price target levels and price bubbles reflecting those values on the right. I have tried using varying inputs like different position sizes, r/r, stop loss values etc. but to no avail. I have used other custom scripts with no issues in the past, so I am not sure why this one is giving me trouble.

Brand new to TOS. This is the code:
input action = {Default "Long","Short"};
input entry_price = 2.75;
input sl_percent = 2.0;
input rr_ratio = 2;
input position_size = 2000;

def shares = position_size / entry_price;
plot stop;
switch (action) {
case Long:
stop = if isnan(close[-1]) then round((position_size - (sl_percent * position_size / 100)) / shares)
else double.nan;
Case Short:
stop = if isnan(close[-1]) then round((position_size + (sl_percent * position_size / 100)) / shares)
else double.nan;}

plot entry = if isnan(close[-1]) then entry_price else double.nan;
plot t1 = if isnan(close[-1]) then entry_price + rr_ratio * (entry_price - stop) else double.nan;
plot t2 = if isnan(close[-1]) then entry_price + (2 * rr_ratio) * (entry_price - stop) else double.nan;
plot t3 = if isnan(close[-1]) then entry_price + (3 * rr_ratio) * (entry_price - stop) else double.nan;
AddCloud(entry_price, stop, Color.GRAY, Color.GRAY);
AddCloud(t1, t2, Color.GREEN, Color.GREEN);
AddCloud(t2, t3, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), entry_price, entry_price, Color.WHITE);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t1, "T1 $" + t1, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t2, "T2 $" + t2, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), t3, "T3 $" + t3, Color.GREEN);
AddChartBubble(IsNaN(close[2]) and !IsNaN(close[3]), stop, "STOP $" + stop, Color.RED, no);
AddChartBubble(IsNaN(close[10]) and !IsNaN(close[11]), entry_price, "SHARES:" + Floor(shares), Color.YELLOW);
Try taking out the future bars pointer [-1]
 
input action = {Default "Long","Short"};
input entry_price = 2.75;
input sl_percent =0.3;
input rr_ratio = 2.0;
input position_size = 2000;
input offset = 5;

def line_plot = IsNaN(close[offset]);
def label_plot = IsNaN(close[offset]) and !IsNaN(close[offset + 1]);

def shares = position_size / entry_price;
plot stop;
switch (action) {
case Long:
stop = if line_plot then round((position_size - (sl_percent * position_size / 100)) / shares)
else double.nan;
Case Short:
stop = if line_plot then round((position_size + (sl_percent * position_size / 100)) / shares)
else double.nan;}

plot entry = if line_plot then entry_price else double.nan;
plot t1 = if line_plot then entry_price + rr_ratio * (entry_price - stop) else double.nan;
plot t2 = if line_plot then entry_price + (2 * rr_ratio) * (entry_price - stop) else double.nan;
plot t3 = if line_plot then entry_price + (3 * rr_ratio) * (entry_price - stop) else double.nan;
AddCloud(entry_price, stop, Color.GRAY, Color.GRAY);
AddCloud(t1, t2, Color.GREEN, Color.GREEN);
AddCloud(t2, t3, Color.LIGHT_GREEN, Color.LIGHT_GREEN);

AddChartBubble(label_plot, entry_price, entry_price, Color.Light_Gray);
AddChartBubble(label_plot, t1, "T1 $" + t1, Color.GREEN);
AddChartBubble(label_plot, t2, "T2 $" + t2, Color.GREEN);
AddChartBubble(label_plot, t3, "T3 $" + t3, Color.GREEN);
AddChartBubble(label_plot, stop, "STOP $" + stop, Color.RED, no);
great script. I wanted to change something, but nothing happened. If it is possible I ask for help.
1) I would like the entry price to be the last price on the chart and it to be dynamic, not standing still.
2) So that this data would work on all charts when switching and I did not need to change anything.
I indicate the volume, risks and buying or selling and the data dynamically changes on each chart depending on the price change.
 
Last edited:
great script. I wanted to change something, but nothing happened. If it is possible I ask for help.
1) I would like the entry price to be the last price on the chart and it to be dynamic, not standing still.
2) So that this data would work on all charts when switching and I did not need to change anything.
I indicate the volume, risks and buying or selling and the data dynamically changes on each chart depending on the price change.
change:
input entry_price = 2.75;
to:
def entry_price = close;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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