THINKorSWIM RISK REWARD INDICATOR

@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 = 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:" + floor(shares), color.yellow);
 
Last edited:
I had modified the codes contributed by "Generic" to allow for Long and Short trade

(updated error fixed)
Ruby:
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);
 
Last edited by a moderator:
I thought it was supposed to act as price lines, where you click&drag to move them.
This one I have to manually change entry price if I wanna slide the whole study up / down.
 
I thought it was supposed to act as price lines, where you click&drag to move them.
This one I have to manually change entry price if I wanna slide the whole study up / down.

@us3r001 The only priceslines we can Drag & Drop are the Order pricelines for Limit and Stoploss for trades...
 
@rktrader Watch the video from post #1. From what I saw you put how much your position size into amount, put the amount you're willing to risk, and decide on a risk to reward ratio and it'll plot where you should exit.
 
I had modified the codes contributed by "Generic" to allow for Long and Short trade

Code:
input action = {Default "Long","Short"};
input price = 2.75;
input amount = 2000;
input risk = 100;
input ratio = 2;

def shares = Floor(amount / price);
plot stop;
switch (action) {
case Long:
stop = if isnan(close[-1]) then round((amount - risk) / shares)
              else double.nan;
Case Short:
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);
Thank you for this. What is t1, t2, t3??
 
Do you have to enter a trade to have the targets generated? Can we get one that's "floating" and doesn't require an entry to plot please?
 
@stamenski They're targets based on risk to reward ratio.

@otterflips You don't need to be in a trade but you do need to manually input your entry.
It's not plotting anything for me except for the entry line, that's why I asked.

Edit: figured it out, but having to edit the "amount" just to bring the targets into perspective is not viable, I understand editing entry price - that's fine. But in a live trade it's difficult to manage more than one and guess just to have it displayed. It needs to be something like ATR based on last 5 bars so it doesn't need to be edited in my opinion. The entry price is fine, but the other stuff too? Would be awesome if we could only need to edit the entry for the plot to be accurate. Not sure why mine isn't, if that's how it's supposed to be.
 
Last edited:
@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.
 
@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.
Nah please don't take it the wrong way, I love the idea of the indicator and what it can accomplish. It's just on TSLA when I plugged in entry price it only displayed my entry price, and I had to set the "amount" to 20,000 to be able to see the targets, I could completely be doing it wrong. But it's the only way I could find the targets/stop displayed on my chart. Not sure what the issue was. Any idea? + if it's set for Tesla and I flip to another ticker and change the entry price, it's gone again. I was just curious what I was doing wrong.
 
@otterflips There's a mistake in the script. I changed it so that risk is a stop loss percent instead. Position size input doesn't really matter since it just changes the amount of shares. Only things you need to change is entry price, and sl percent and rr ratio to whatever you're comfortable with.

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);
 
Last edited:
Do you have to enter a trade to have the targets generated? Can we get one that's "floating" and doesn't require an entry to plot please?
No u don't have to enter the trade. You can keep it in your chart studies and unclick show plot. then when u do have a chart that you want to plot the RR then you click the show plot and enter the info. A floating one would be cool.
 

@generic


Great script, thank you. Question, first attempt to alter a thinkscript. Wanted the it to pull my average price and shares from my portfolio.

def qty = GetQuantity();
input action = {default "Long", "Short"};
def entry_price = GetAveragePrice();
input sl_percent = 2.0;
input rr_ratio = 3;
def position_size = qty;
input offset = 2;

1) Pricing was fine but for some reason shares was incorrect, I own 345 it displays 17?
2) If I switch to a stock symbol for which I do not own any shares, it sets price too zero and shares is N/A (as expected since we don't own any actual shares), however the chart is flatten out, all candle sticks are squashed down?

So I though lets add the default "2.75" as you had set for the entry price, if no shares were owned.

def qty = GetQuantity();
input action = {default "Long", "Short"};
def entry_price = if GetAveragePrice() then GetAveragePrice() else 2.75;
input sl_percent = 2.0;
input rr_ratio = 3;
def position_size = qty;
input offset = 2;

That worked and set the entry at 2.75 as default if no shares owned was found, however the chart was still flatten out? if you scroll over to the left (older time frames) and you lose visibility to this plot the chart candle sticks unflatten.

After some more testing I thought maybe it was the "input offset = (i tried 3 and 2) " and replacement of all the close[-1] to close[offset] that created this issue with charts. reverting back to -1 and still same issue. If you wouldn't mind taking a look as why this is the case it would be greatly appreciated. I try 1m and 5m charts, same.
 

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