Risk and sizing
Risk and Reward Preview
Give it an entry and a stop and it draws the one, two and three R levels with labels, so the reward a trade needs is a line on the chart rather than a number you talked yourself into.
indicator
//@version=6
indicator("Risk and Reward Preview", "R Targets", overlay = true)
entryPrice = input.price(0.0, "Entry price", confirm = true, group = "Settings")
stopPrice = input.price(0.0, "Stop price", confirm = true, group = "Settings")
barsBack = input.int(40, "Bars drawn behind", minval = 1, group = "Settings")
targetCol = input.color(#26A69A, "Targets", group = "Style")
stopCol = input.color(#EF5350, "Stop", group = "Style")
entryCol = input.color(#787B86, "Entry", group = "Style")
oneR = entryPrice - stopPrice
ready = oneR != 0
target1 = entryPrice + oneR
target2 = entryPrice + oneR * 2
target3 = entryPrice + oneR * 3
var array<line> levelLines = array.new<line>()
var array<label> levelTags = array.new<label>()
drawLevel(float price, color col, string name) =>
array.push(levelLines, line.new(bar_index - barsBack, price, bar_index, price, color = col))
array.push(levelTags, label.new(bar_index, price, name + " " + str.tostring(price, format.mintick), style = label.style_label_left, color = color.new(col, 85), textcolor = col, size = size.small))
if barstate.islast and ready
for old in levelLines
line.delete(old)
for tag in levelTags
label.delete(tag)
array.clear(levelLines)
array.clear(levelTags)
drawLevel(stopPrice, stopCol, "Stop")
drawLevel(entryPrice, entryCol, "Entry")
drawLevel(target1, targetCol, "1R")
drawLevel(target2, targetCol, "2R")
drawLevel(target3, targetCol, "3R")
reachedOne = ready and ta.cross(close, target1)
plotshape(reachedOne, "One R reached", location = location.abovebar, style = shape.circle, color = targetCol, size = size.tiny)
alertcondition(reachedOne, "One R reached", "Price has traded through the first R multiple")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.
What it will not do
- R multiples are arithmetic on your two inputs. Drawing a three R line says nothing about whether price will reach it.
- Fees, slippage and the spread all come out of the R you actually collect, and none of them are in these levels.
- The lines are static. Move your stop and the targets on the chart no longer describe the trade you are in.
- Nothing here checks that the stop sits anywhere sensible. It will happily draw targets from an arbitrary pair of prices.
Written from this description
Take an entry price and a stop price as inputs, treat the distance between them as one R, and draw the entry, the stop and the one, two and three R targets as labelled horizontal lines. Alert when price trades through the first target.
Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.