Position Sizing Calculator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Settaphat_Assarakulsith

//@version=4
study(title = "Position Sizing Calculator" , shorttitle = "Position Calc" , overlay = true )
//Input
Capital = input(title = "Capital (USD)", type=input.integer , defval = 10000 , minval = 0 ,maxval = 10000000)
Risk = input(title = "Risk (%)", type=input.integer , defval = 2 , minval = 0.1 ,maxval = 100 , options=[0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0])

//Calculation
risk_money = (Capital * Risk)/100
lowest_low = lowest(close,12)
last_close = close[0]
Buy_amount = round(risk_money/(last_close - lowest_low),5)
//plot
label_text = "You should Buy " + tostring(Buy_amount) + " Coins"
our_label = label.new(bar_index,y=na,text = label_text,yloc=yloc.belowbar,color=color.green,textcolor=color.white,style=label.style_label_up)
label.delete(our_label[1])
plot(lowest_low,title = "Most significant low" , color=color.blue , style = plot.style_line,show_last = 1 )