Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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);
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.@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.
What is input ratio? Input price?? Thank you@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);
Adding short would really help. Works really nice on longs.What is input ratio? Input price?? Thank you
updated code: https://usethinkscript.com/threads/thinkorswim-risk-reward-indicator.7210/#post-73021Adding short would really help. Works really nice on longs.
No delta is not available for your scriptcan 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
@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
They cannot be automated. The only thing you can do is create a strategy that prints entries and exists on the chart.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
Try taking out the future bars pointer [-1]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 am very new. How do you import this into Think or Swim (TOS)?Thank you for this. What is t1, t2, t3??
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/I am very new. How do you import this into Think or Swim (TOS)?
great script. I wanted to change something, but nothing happened. If it is possible I ask for help.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);
change: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.
to:input entry_price = 2.75;
def entry_price = close;
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
ATR Risk Control Indicator for ThinkorSwim | Indicators | 14 | ||
Repaints Cup and Handle Indicator for ThinkorSwim | Indicators | 24 | ||
The Ultimate Buy and Sell Indicator for ThinkOrSwim | Indicators | 5 | ||
S | SharkWaveTrend For ThinkOrSwim | Indicators | 46 | |
Repaints Smart Money Breakouts [ChartPrime] for ThinkOrSwim | Indicators | 15 |
Start a new thread and receive assistance from our community.
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.
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.