PSESS1 - Learn PineScript Inputs
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Mahdi_Fatemi1998

//@version=5
indicator(title='Learn PineScript Inputs', overlay=true)
//some parameters of the indicator() function, when used, will populate the script’s “Inputs” tab with a field. The parameters are timeframe and timeframe_gaps (comment above indicator call and uncomment below to see the effect in inputs window)
//indicator(title='Learn Input',  overlay=true, timeframe = "D", timeframe_gaps = false)


// arguments passed to input function
var title   = 'title'   // this string is shown next to input field in input window
var tooltip = 'tooltip' // this string is shown when hovering on the question mark next to input field
var inline  = 'inline'  // inputs having the same inline string are placed in the same line (if set to '' the inputs will be in different lines)
var group   = 'group'   // a header (header inner text is the string) will be added above the inputs having the same group string in all capital letters (if set to '' there will be no group)
var confirm = false     // asks the user for input right after adding indicator to chart (price and time are asked differently, user selects them by specifying a point on chart)
// when confirm is true, defval will not have effect (still required) because the user sets the values himself at the beginning, however defval will be used when user set inputs to default at the bottom of the input window

// input.-type-(): receives inputs of the specified -type- (12 possible types)
var boolInput       = input.bool     (defval=true,                              title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var colorInput      = input.color    (defval=color.red,                       title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var floatInput      = input.float    (defval=3.14,                              title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var float2Input     = input.float    (defval=4.76,                              title=title, minval=1, maxval=10, step=0.1,                   tooltip=tooltip, inline=inline, group=group, confirm=confirm) // defval should be between minval and maxval
var float3Input     = input.float    (defval=1.2,                               title=title, options=[1.2, 2.3, 3.4, 4.5, 5.6],               tooltip=tooltip, inline=inline, group=group, confirm=confirm) // defval should be in options
var intInput        = input.int      (defval=21,                                title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var int2Input       = input.int      (defval=30,                                title=title, minval=5, maxval=40, step=5,                     tooltip=tooltip, inline=inline, group=group, confirm=confirm) // defval should be between minval and maxval
var int3Input       = input.int      (defval=9,                                 title=title, options=[9, 18, 27, 36],                         tooltip=tooltip, inline=inline, group=group, confirm=confirm) // defval should be in options
var priceInput      = input.price    (defval=20222.58,                          title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm) // confirm acts different: asks user to choose price from chart while the tooltip is shown in blue box
var sessionInput    = input.session  (defval='1730-2100',                       title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var session2Input   = input.session  (defval='0100-0200',                       title=title, options=['0100-0200', '1100-1900', '0500-0400'], tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var sourceInput     = input.source   (defval=close,                             title=title,                                                  tooltip=tooltip, inline=inline, group=group)                  // no confirm argument
var stringInput     = input.string   (defval='defval',                          title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var string2Input    = input.string   (defval='a',                               title=title, options=['a', 'b', 'c'],                         tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var symbolInput     = input.symbol   (defval='BTCUSDT',                         title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm) // if the exchange prefix is not provided, the first choice in the list will be selected
var text_areaInput  = input.text_area(defval="text\ntext\ntext",                title=title,                                                  tooltip=tooltip,                group=group, confirm=confirm) // no inline argument, next inputs move upward to be inline with others, tooltip question mark is shown next to title
var timeInput       = input.time     (defval=timestamp('Feb 01 2020 22:10:05'), title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm) // confirm acts different: asks user to choose time from chart while the tooltip is shown is blue box
var timeframeInput  = input.timeframe(defval='D',                               title=title,                                                  tooltip=tooltip, inline=inline, group=group, confirm=confirm)
var timeframe2Input = input.timeframe(defval='3S',                              title=title, options=['3S', '3', '3D','3W', '3M'],            tooltip=tooltip, inline=inline, group=group, confirm=confirm)
// either (options) or (minval, maxval, step) can be in one input parameters not both and defval should meet the limits they constraint
// if the script contains only one source input, then the user can also select an output from another indicator on their chart as the source

// if several inputs have the same inline string, one tooltip will be shown at the end of all inputs and the tooltip text will be the tooltip input of the last input having the same inline
var price2Input = input.price(defval=20222.58,                          title=title, tooltip='***THIS-TOOLTIP-WONT-BE-SHOWN***', inline=inline, group='one group for inline inputs', confirm=true)
var time2Input  = input.time (defval=timestamp('Feb 01 2020 22:10:05'), title=title, tooltip='this tooltip will be shown'      , inline=inline, group='one group for inline inputs', confirm=true)
// however, if text_area input be among inputs having the same inline argument, inputs will break in to 3 parts with three tooltips: 
//   1. part before the text area with tooltip text of the last input in the part
//   2. part containing the text area with tooltip text of the text area input
//   3. part after the text area with tooltip text of the last input in the part
// note: the parts in the input window are not placed in the same order as they are in the script so the groups might be different than what expected

// getting multiple price inputs
price1mInput = input.price(defval=19700, title='price1', tooltip='enter price 1', inline='', group='multiple price inputs', confirm=true)
price2mInput = input.price(defval=29800, title='price2', tooltip='enter price 2', inline='', group='multiple price inputs', confirm=true)
price3mInput = input.price(defval=39900, title='price3', tooltip='enter price 3', inline='', group='multiple price inputs', confirm=true)

// getting multiple time inputs
time1mInput = input.time(defval=timestamp('Sep 16 2020 12:58:09'), title='time1', tooltip='enter time 1', inline='', group='multiple time inputs', confirm=true)
time2mInput = input.time(defval=timestamp('Sep 16 2020 12:58:09'), title='time2', tooltip='enter time 2', inline='', group='multiple time inputs', confirm=true)
time3mInput = input.time(defval=timestamp('Sep 16 2020 12:58:09'), title='time3', tooltip='enter time 3', inline='', group='multiple time inputs', confirm=true)

// getting a time and price input on two requests
pricedInput = input.price(defval=39900                            , title='price double', tooltip='enter price (double)', inline='', group='multiple price inputs', confirm=true)
timedInput  = input.time (defval=timestamp('Sep 16 2020 12:58:09'), title='time double' , tooltip='enter time (double)' , inline='', group='multiple time inputs' , confirm=true)
// the order of receiving price or time inputs: if the first price or time is price, all price inputs will be received (regardless of their further order) and if the first one is time then the time inputs will be received first
// the above double price, time input will be received individually because they do not have the same inline

// getting a time and price input on a single request (same inline and same group, horizintal and vertical position of ONE specified point on chart determines both inputs at once)
price2dInput = input.price(defval=49900                            , title='price2 double', tooltip='enter price 2 (double)', inline='single request', group='single request group', confirm=true)
time2dInput  = input.time (defval=timestamp('Sep 16 2020 13:26:09'), title='time2 double' , tooltip='enter time 2 (double)' , inline='single request', group='single request group', confirm=true)

// input(): automatically detects the input type using the defval argument (only supports: bool, color, int, float, string and price-related source like close, hl2, hl3, etc.)
auto2Input = input(defval='some text 1', title='title argumant in input func', tooltip='this text is shown when hovering on question mark next to the input')

// Uncomment the code below and it gives error (no defval input)
//auto_input1 = input(title='title_in_input_func', tooltip='this text is shown when hovering on question mark next to the input')

// if title argument is not set the variable name is used instead 
variableNameInput = input(defval='some text 2')
// however, if the title is set to empty string ('') for any input the variable name will not be shown for it
// this  is helpful in order to let the user more easily identify the thing which to color is related (using inline is recommended at this case)
sourcecInput = input.source(defval=close,       title='source for color test', tooltip='select source', inline='color line', group='color title test')
colorcInput  = input.color (defval=color.red, title='',                      tooltip='select color',  inline='color line', group='color title test', confirm=false)

// Inputs user manual     : https://www.tradingview.com/pine-script-docs/en/v5/concepts/Inputs.html
// Inputs reference manual: https://www.tradingview.com/pine-script-reference/v5/#fun_input{dot}bool

// Inputs user manual keypoints: 
// 1.  4 ways to open settings of an indicator
// 2.  flow of script's execution when user changes inputs of an indicator that is already on chart
// 3.  all input parameters must be of 'const' type meaning they should be known at compile time and can't change during scripts execution
// 4.  when using dynamic (or series) color componenets the color widgets will not appear in style settings of indicator (example of dynamic color: bbHiColor = color.new(color.gray, high > bbHi ? 60 : 0)) and
//     this is one use case for color input (we usually set color in style settings of indicator and in those cases there is no need to receive the color by input*() functions)
// 5.  if symbol input has defval='' and user don't give it a value, code will call request.security() where the symbol input variable name is used to fill its value (gets current symbool and use it as symbol input)
// 6.  place the inputs in code in the order suggested by pinescript user manual style guide
// 7.  to vertically align the inputs add spaces inside the '' not between '' and , in order to not just vertically align the code but also vertically align inputs in inputs window so user will have better experience
//     these space should be Unicode EN spaces (U+2002). Unicode spaces are necessary because ordinary spaces would be stripped from the label
// 8.  we use the group parameter to distinguish between the two sections of inputs. we use a constant to hold the name of the groups. this way, if we decide to change the name of the group,
//     we only need to change it in one place


plot(na)