Unfortunately, on TradingView till date (PineScript v4), there is no ability to create color inputs, neither for plots (only from Style-properties,but not as input) nor for Drawing elements (like Line or Label).

Moreover, there is no ability to set “user-selected” transparency for colors (i.e. for functions like color.new (again, not to even mention for line/label). However, there might exist the following trick…

User-Selectable Color/Input

In previous article we showed a way how to create the color input, but if you want to create a transparent color input, then you will need a bit different approach like this function:

// ########## Trading.Codes ##########
//@version=4
study("Sample Transparent color (Trading.Codes)")


// Transparent Color function ( https://trading.codes/?p=223 ); round to nearest 10, otherwise code will become heavier if all numbers were hardcoded
Transparent_Color(c,t_)=> t = floor(t_ /10)*10, 
  c=="aqua"    ? (t==0 ? color.new(color.aqua,0) : t==10 ? color.new(color.aqua,10) : t==20 ? color.new(color.aqua,20) : t==30 ? color.new(color.aqua,30) : t==40 ? color.new(color.aqua,40) : t==50 ? color.new(color.aqua,50) : t==60 ? color.new(color.aqua,60) : t==70 ? color.new(color.aqua,70) : t==80 ? color.new(color.aqua,80) : t==90 ? color.new(color.aqua,90) : color.new(color.aqua,100) ) :
  c=="black"   ? (t==0 ? color.new(color.black,0) : t==10 ? color.new(color.black,10) : t==20 ? color.new(color.black,20) : t==30 ? color.new(color.black,30) : t==40 ? color.new(color.black,40) : t==50 ? color.new(color.black,50) : t==60 ? color.new(color.black,60) : t==70 ? color.new(color.black,70) : t==80 ? color.new(color.black,80) : t==90 ? color.new(color.black,90) : color.new(color.black,100) ) :
  c=="blue"    ? (t==0 ? color.new(color.blue,0) : t==10 ? color.new(color.blue,10) : t==20 ? color.new(color.blue,20) : t==30 ? color.new(color.blue,30) : t==40 ? color.new(color.blue,40) : t==50 ? color.new(color.blue,50) : t==60 ? color.new(color.blue,60) : t==70 ? color.new(color.blue,70) : t==80 ? color.new(color.blue,80) : t==90 ? color.new(color.blue,90) : color.new(color.blue,100) ) :
  c=="fuchsia" ? (t==0 ? color.new(color.fuchsia,0) : t==10 ? color.new(color.fuchsia,10) : t==20 ? color.new(color.fuchsia,20) : t==30 ? color.new(color.fuchsia,30) : t==40 ? color.new(color.fuchsia,40) : t==50 ? color.new(color.fuchsia,50) : t==60 ? color.new(color.fuchsia,60) : t==70 ? color.new(color.fuchsia,70) : t==80 ? color.new(color.fuchsia,80) : t==90 ? color.new(color.fuchsia,90) : color.new(color.fuchsia,100) ) :
  c=="gray"    ? (t==0 ? color.new(color.gray,0) : t==10 ? color.new(color.gray,10) : t==20 ? color.new(color.gray,20) : t==30 ? color.new(color.gray,30) : t==40 ? color.new(color.gray,40) : t==50 ? color.new(color.gray,50) : t==60 ? color.new(color.gray,60) : t==70 ? color.new(color.gray,70) : t==80 ? color.new(color.gray,80) : t==90 ? color.new(color.gray,90) : color.new(color.gray,100) ) :
  c=="green"   ? (t==0 ? color.new(color.green,0) : t==10 ? color.new(color.green,10) : t==20 ? color.new(color.green,20) : t==30 ? color.new(color.green,30) : t==40 ? color.new(color.green,40) : t==50 ? color.new(color.green,50) : t==60 ? color.new(color.green,60) : t==70 ? color.new(color.green,70) : t==80 ? color.new(color.green,80) : t==90 ? color.new(color.green,90) : color.new(color.green,100) ) :
  c=="lime"    ? (t==0 ? color.new(color.lime,0) : t==10 ? color.new(color.lime,10) : t==20 ? color.new(color.lime,20) : t==30 ? color.new(color.lime,30) : t==40 ? color.new(color.lime,40) : t==50 ? color.new(color.lime,50) : t==60 ? color.new(color.lime,60) : t==70 ? color.new(color.lime,70) : t==80 ? color.new(color.lime,80) : t==90 ? color.new(color.lime,90) : color.new(color.lime,100) ) :
  c=="orange"  ? (t==0 ? color.new(color.orange,0) : t==10 ? color.new(color.orange,10) : t==20 ? color.new(color.orange,20) : t==30 ? color.new(color.orange,30) : t==40 ? color.new(color.orange,40) : t==50 ? color.new(color.orange,50) : t==60 ? color.new(color.orange,60) : t==70 ? color.new(color.orange,70) : t==80 ? color.new(color.orange,80) : t==90 ? color.new(color.orange,90) : color.new(color.orange,100) ) :
  c=="purple"  ? (t==0 ? color.new(color.purple,0) : t==10 ? color.new(color.purple,10) : t==20 ? color.new(color.purple,20) : t==30 ? color.new(color.purple,30) : t==40 ? color.new(color.purple,40) : t==50 ? color.new(color.purple,50) : t==60 ? color.new(color.purple,60) : t==70 ? color.new(color.purple,70) : t==80 ? color.new(color.purple,80) : t==90 ? color.new(color.purple,90) : color.new(color.purple,100) ) :
  c=="red"     ? (t==0 ? color.new(color.red,0) : t==10 ? color.new(color.red,10) : t==20 ? color.new(color.red,20) : t==30 ? color.new(color.red,30) : t==40 ? color.new(color.red,40) : t==50 ? color.new(color.red,50) : t==60 ? color.new(color.red,60) : t==70 ? color.new(color.red,70) : t==80 ? color.new(color.red,80) : t==90 ? color.new(color.red,90) : color.new(color.red,100) ) :
  c=="white"   ? (t==0 ? color.new(color.white,0) : t==10 ? color.new(color.white,10) : t==20 ? color.new(color.white,20) : t==30 ? color.new(color.white,30) : t==40 ? color.new(color.white,40) : t==50 ? color.new(color.white,50) : t==60 ? color.new(color.white,60) : t==70 ? color.new(color.white,70) : t==80 ? color.new(color.white,80) : t==90 ? color.new(color.white,90) : color.new(color.white,100) ) :
  c=="yellow"  ? (t==0 ? color.new(color.yellow,0) : t==10 ? color.new(color.yellow,10) : t==20 ? color.new(color.yellow,20) : t==30 ? color.new(color.yellow,30) : t==40 ? color.new(color.yellow,40) : t==50 ? color.new(color.yellow,50) : t==60 ? color.new(color.yellow,60) : t==70 ? color.new(color.yellow,70) : t==80 ? color.new(color.yellow,80) : t==90 ? color.new(color.yellow,90) : color.new(color.yellow,100) ) : color.black

//inputs
var my_color_1 = input(title="Color", defval="green", options=["aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "orange", "purple", "red", "white", "yellow"])
var my_transparency = input(53, title="transparency")

var myCol=Transparent_Color(my_color_1, my_transparency) // better to save into "var" constant to avoid unnecesasary recalculation on each bar
plot(high, color=myCol ) 
//line.new(...color=myCol)

[ Revisions: #php:dwiAUKtb #5: AJC3S3Jx #10:JamcBgya ]

Leave a Reply

Your email address will not be published. Required fields are marked *