Indicator · Pine Script v4 · On the chart

Risk Management Tool [LuxAlgo]

by theonetrade· code credited to LuxAlgo

Risk Management Tool [LuxAlgo] is an overlay indicator that assists traders with position sizing and trade planning directly on the price chart.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code101
Settings13inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

101 lines of Pine Script v4 from assets/indicator/bit-exact/risk_management_tool_luxalgo_fLtr5XhT.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

risk_management_tool_luxalgo_fLtr5XhT.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=4
study("Risk Management Tool [LuxAlgo]",overlay=true)
pos_type = input('Long','Position Type',options=['Long','Short'])
acc_size = input(1000.,'Account Size',minval=0)

risk = input(2.,'Risk               ',minval=0,inline='risk')
risk_type = input('%','',options=['%','USD'],inline='risk')

entry_price = input(40000.,'Entry Price',confirm=true)
entry_cross = input(false,'Entry From Cross',inline='entry')
cross_src = input(open,"",inline='entry')
//----
tp = input(5.,'Take Profit',minval=0
  ,group='Take Profit/Stop Loss',inline='tp',confirm=true)
tp_type = input('%','',options=['ATR','%','Price','Range']
  ,group='Take Profit/Stop Loss',inline='tp',confirm=true)
//----
sl = input(5.,'Stop Loss  ',minval=0
  ,group='Take Profit/Stop Loss',inline='sl',confirm=true)
sl_type = input('%','',options=['ATR','%','Price','Range']
  ,group='Take Profit/Stop Loss',inline='sl',confirm=true)
//----
profit_col = input(color.new(#009688,80),'Profit Color'
  ,group='Style',inline='col')
loss_col = input(color.new(#f44336,80),'Loss Color'
  ,group='Style',inline='col')
//------------------------------------------------------------------------------
tp_val = 0.
sl_val = 0.
entry = 0.
pos = pos_type == 'Long' ? 1 : -1

if entry_cross
    entry := valuewhen(cross(close,cross_src)[1],open,0)
else
    entry := entry_price

tp_range = highest(max(round(tp),1)) - lowest(max(round(tp),1))
sl_range = highest(max(round(sl),1)) - lowest(max(round(sl),1))

if tp_type == 'ATR'
    tp_val := entry + atr(max(round(tp),1))*pos
else if tp_type == '%'
    tp_val := entry + tp/100*entry*pos
else if tp_type == 'Price'
    tp_val := tp
else if tp_type == 'Range'
    tp_val := entry + (tp_range)*pos

if sl_type == 'ATR'
    sl_val := entry - atr(max(round(sl),1))*pos
else if sl_type == '%'
    sl_val := entry - sl/100*entry*pos
else if sl_type == 'Price'
    sl_val := sl
else if sl_type == 'Range'
    sl_val := entry - (sl_range)*pos
//------------------------------------------------------------------------------
open_pl = (close - entry)*pos
position_size = 0.
RR = abs((tp_val-entry)/(sl_val-entry))
if risk_type == '%'
    position_size := risk/100*acc_size/((entry-sl_val)*pos)
else
    position_size := risk/((entry-sl_val)*pos)
//------------------------------------------------------------------------------
n = bar_index
var tbl = table.new(position.bottom_right,2,3)
if barstate.islast
    box.delete(box.new(n,tp_val,n+100,entry,bgcolor=profit_col,border_width=0)[1])
    box.delete(box.new(n,entry,n+100,sl_val,bgcolor=loss_col,border_width=0)[1])
    
    label.delete(label.new(n+100,entry
      ,str.format('P&L : {0} {1} ({2,number,percent})',open_pl,syminfo.currency,open_pl/entry)
      ,color=open_pl>0?profit_col:loss_col
      ,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1]) 
    
    if tp
        label.delete(label.new(n+100,tp_val
          ,str.format('TP : {0} ({1,number,percent})',tp_val,(tp_val-entry)/entry)
          ,color=profit_col
          ,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1]) 
    if sl
        label.delete(label.new(n+100,sl_val
          ,str.format('TSL : {0} ({1,number,percent})',sl_val,(entry-sl_val)/entry)
          ,color=loss_col
          ,style=label.style_label_left,textcolor=color.gray,textalign=text.align_left)[1])
      
    table.cell(tbl,0,0,'Risk/Reward',text_color=color.gray,text_halign=text.align_center)
    table.cell(tbl,1,0,tostring(RR,'#.####'),text_color=color.gray,text_halign=text.align_center)
    table.cell(tbl,0,1,'Position Size',text_color=color.gray,text_halign=text.align_center)
    table.cell(tbl,1,1,tostring(position_size,'#.####')+' '+syminfo.basecurrency
      ,text_color=color.gray,text_halign=text.align_center)
//------------------------------------------------------------------------------
Close = plot(close,editable=false,display=display.none)
Entry = plot(entry,editable=false,display=display.none)
fill(Close,Entry,color=open_pl>0?profit_col:loss_col)
plotchar(open_pl,'Rolling Open PL%','',location.abovebar,open_pl > 0 ? profit_col : loss_col)

Overview

Risk Management Tool [LuxAlgo] calculates position size using account size, risk defined in percentage or cash amount, entry price, and stop-loss or take-profit targets. Targets can be calculated using percentage, ATR, specific price levels, or price ranges. The indicator projects profit and loss target boxes into future bars and displays key metrics such as risk-reward ratio, trade size, and unrealized profit and loss directly on the chart.

Details

Published by

theonetrade on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Position TypestringLongpos_type
Account Sizeinput1000.acc_size
Risk               input2.risk
risk_typestring%risk_type
Entry Priceinput40000.entry_price
Entry From Crossboolfalseentry_cross
cross_srcsourceopencross_src
Take Profitinput5.tp
tp_typestring%tp_type
Stop Loss  input5.sl
sl_typestring%sl_type
Profit Colorcolorcolor.new(#009688,80)profit_col
Show all 13 settings
SettingTypeDefaultVariable
Loss Colorcolorcolor.new(#f44336,80)loss_col
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This overlay indicator scans a pasted list of symbols for ICT liquidity sweep patterns using prior swing sweeps. The screening method looks back one, two, or three swings and can list long and short signals in a results table with adjustable rows, position, an

Indicator v5 SMC / ICT / price actionScreeners & dashboards
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Sweep Pattern Scanner
368 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 3 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

BZ-tracker

by Allen1212
302 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 3 years ago · None stated GitHub repository of BZ-tracker
257 stars

This indicator overlays an intraday SPX and ES chart with a midnight session range, regular-trading-hours opening levels, and a VWAP projection box. It draws the midnight high, mid, and low, flags edge rejections within an absolute tolerance, and plots optiona

Indicator v6 TrendSupport & resistance
Updated 2 months ago · None stated GitHub repository of SPX Midnight Box + Snag Logic

Golden Bullet Strategy

by TradersPost
228 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 4 months ago · None stated GitHub repository of Golden Bullet Strategy

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers