Scalper's toolkit - ATR Widget
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © xAverageJoex

//@version=5

indicator(title="Risk Value Calculator", shorttitle="Risk Calculator", overlay=true)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
// --------  ATR Section --------- //
/////////////////////////////////////

/////////////////////////////////////
// -----  Global  Variables  ----- //
/////////////////////////////////////
float atrMultiple1 = 0
float atrMultiple2 = 0
string atrPipPointDesc = ""
float atr = 0
float cleanATR = 0
float atrSL = 0
float atrTP = 0
int frameSize = 0

/////////////////////////////////////
// -------   ATR  Inputs   ------- //
/////////////////////////////////////

atrPeriod = input.int(defval = 14, minval = 2, step = 1, title = "Period", group = "------------- ATR Settings -------------", inline = "ATRW1")
atrPipPoint = input.string(defval = "Pips", options = ["Points", "Pips", "Standard ATR"], title = "Pip/Point", tooltip = "Period : ATR length, using a period of 1 yields True Range. Pip/Point: Show values as Pips, directly in Points, or as Standard ATR Values. (Change if widget does not show correct values)", group = "------------- ATR Settings -------------", inline = "ATRW1")
int atrStylePipPoint = switch atrPipPoint
    "Points" => 1
    "Pips" => 2
    "Standard ATR" => 3
//

if atrStylePipPoint == 2
    atrPipPointDesc := "(Pips)"
else if atrStylePipPoint == 1
    atrPipPointDesc := "(Point)"
else
    atrPipPointDesc := "(Std.)"
//

/////////////////////////////////////
// -----    Risk Settings    ----- //
/////////////////////////////////////
atrRisk = input.bool(defval = true, title = "Calculate R:R ", group = "------------- Risk : Reward Settings -------------", tooltip = "Make trade stop/target calculations. Must be enabled to have values calculated below.")

atrStopStyle = input.string( defval = "ATR Multiple", title = "Stop Calculation Style", options = ["ATR Multiple", "Fixed Size"], tooltip = "Use a multiple of the ATR, or use a fixed value for stop size calculation", group = "------------- Risk : Reward Settings -------------")

stopSizeFixed = input.int(defval = 300, minval = 1, step = 1, title = "ATR Fixed Stop Size/Points", group="------------- Risk : Reward Settings -------------", tooltip = "Used with \"Fixed Size\" Style for using a fixed Stop Loss Size, **Must be in points ** For Forex: (Pips / 10)")
atrMultiple1 := input.float(defval = 2, minval = 0.1, step = 0.1, title = "ATR Multiple Stop Size", group="------------- Risk : Reward Settings -------------", tooltip = "Used with \"ATR Multiple\" Style: Sets Stop Loss Size by an ATR multiplier factor, 2 default")
atrMultiple2 := input.float(defval = 3, minval = 0.1, step = 0.1, title = "Reward Ratio 1 : ", group="------------- Risk : Reward Settings -------------", tooltip = "Ratio : Creates a Reward Ratio target value for a target based on the Stop Loss size used")

/////////////////////////////////////
// ---------- R:R  Math ---------- //
/////////////////////////////////////

//Inputs <==
atr := ta.atr(atrPeriod)
atrSL := atr * atrMultiple1
atrTP := atrSL * atrMultiple2

//Conversion factor
convertMultiple = 1 / syminfo.mintick

// Outputs ==>
atrString = str.tostring (atr, format.mintick)
atrSLString = str.tostring (atrSL, format.mintick)
atrTPString = str.tostring (atrTP, format.mintick)

pointValueATR = int(str.tonumber(atrString) * convertMultiple)

// ---------- Convert to Pip or Point
if atrStylePipPoint == 1 or atrStylePipPoint == 2
    cleanATR := int(str.tonumber(atrString) * convertMultiple)
    if atrStylePipPoint == 2 // Pips
        cleanATR := cleanATR / 10
        if atrStopStyle == "ATR Multiple"
            atrSL := cleanATR * atrMultiple1
            atrTP := atrSL * atrMultiple2
        if atrStopStyle == "Fixed Size"
            atrSL := stopSizeFixed / 10
            atrTP := atrSL * atrMultiple2
    else // Points
        atrSL := cleanATR * atrMultiple1
        atrTP := atrSL * atrMultiple2
    //
    atrString := str.tostring(cleanATR)
    atrSLString := str.tostring(atrSL)
    atrTPString := str.tostring(atrTP)
//

/////////////////////////////////////
// -------- END ATR VALUE -------- //
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////
// ------ Display  Settings ------ //
/////////////////////////////////////
tableSize = input.string(defval = "Normal", options = ["Tiny", "Small", "Normal", "Large", "Huge"], title="Size", group="------------- Widget Display Style Settings -------------", inline = "DSS")
string widgetSize = switch tableSize
    "Tiny" => size.tiny
    "Small" => size.small
    "Normal" => size.normal
    "Large" => size.large
    "Huge" => size.huge
//

tableRowStr = input.string(defval = "3 x 3", title = "Style", options = ["3 x 3", "Single Column", "Box", "Single Row", "Double Row"], group = "------------- Widget Display Style Settings -------------", inline = "DSS")

tableLocation = input.string(defval="Top Right", options=["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], title="Location on Chart:", group="------------- Widget Display Style Settings -------------")//, inline = "DSS"
string tablePos = switch tableLocation
    "Top Left" => position.top_left
    "Top Center" => position.top_center
    "Top Right" => position.top_right
    "Middle Left" => position.middle_left
    "Middle Center" => position.middle_center
    "Middle Right" => position.middle_right
    "Bottom Left" => position.bottom_left
    "Bottom Center" => position.bottom_center
    "Bottom Right" => position.bottom_right

//

tableColor = input.color(color.rgb(255, 255, 255), title = "Main Text", group = "Color:", inline = "C")
bgColor = input.color(color.rgb(30, 34, 45), title = "Background", group = "Color:", inline = "C")

frColor = input.color(color.yellow, title = "Main Frame", group = "Color:", inline = "C1")
frameSizeSet = input.int(defval = 3, minval = 0, step = 1, title = "Size", group = "Color:", inline = "C1")

borderColor1 = input.color(color.rgb(0, 0, 0), title = "Cell Divider", group = "Color:", inline = "C2")
borderSize1 = input.int(defval = 2, minval = 0, step = 1, title = "Size", group = "Color:", inline = "C2")

tableRowCheck = str.contains(tableRowStr, "Row")

atrDisplay = ""
atrSLDisplay = ""
atrTPDisplay = ""

if tableRowCheck == true
    atrDisplay := "ATR " + atrPipPointDesc + "     " + atrString
    if atrStopStyle == "ATR Multiple"
        atrSLDisplay := "     SL (" + str.tostring(atrMultiple1) + "x) " +  atrSLString
    if atrStopStyle == "Fixed Size"
        atrSLDisplay := "     SL (Fixed)" +  atrSLString
    atrSLDisplay := "     SL (" + str.tostring(atrMultiple1) + "x) " +  atrSLString
    atrTPDisplay := "     TP (1:" + str.tostring(atrMultiple2) + ")        " +  atrTPString
else
    atrDisplay := "ATR " + atrPipPointDesc + "     " + atrString
    if atrStopStyle == "ATR Multiple"
        atrSLDisplay := "SL (" + str.tostring(atrMultiple1) + "x)          " +  atrSLString
    if atrStopStyle == "Fixed Size"
        atrSLDisplay := "SL (Fixed)          " +  atrSLString
    atrTPDisplay := "TP (1:" + str.tostring(atrMultiple2) + ")        " +  atrTPString

// ATR Display Outputs ==>>
//   atrPipPointDesc pip point or standard atr
//   atrDisplay = atrString
//   atrSLDisplay = atrSLString
//  atrTPDisplay = atrTPString

// Conversion outputs to make pip Value ==>>
float convertATRPipValue = int(str.tonumber(atrString) * convertMultiple)
convertATRPipValue := convertATRPipValue/10
convertATRPipValueSL = convertATRPipValue * atrMultiple1
convertATRPipValueTP = convertATRPipValueSL * atrMultiple2

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
//---- Extra Option Calculation ---//
/////////////////////////////////////

/////////////////////////////////////
// --- Account Currency Setup ---- //
/////////////////////////////////////

// ==== Global Variables ==>> Account Currency
accountCurrency =input.string(defval = "USD", title = "Currency", inline = "Currency1", group = "Trading Account Currency")
accountSymbol = input.string(defval = "$", title = "Symbol", inline = "Currency1", group = "Trading Account Currency", tooltip = "Use the 3 Letter Currency code for your account currency, *** Must Be 3 Capital Letters(EUR, CHF, AUD, GBP, NZD,...) *** Symbol is optional. How to show a number as money ($, €, £, ¥, ₣, ₹,...)") // ==>> Round Currency that is not USD // options = ["USD", "AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD"],
accountDecimal = input.string(defval = "0.00", title = "Decimals", options = ["0", "0.0", "0.00", "0.000", "0.0000", "0.00000", "0.000000", "0.0000000", "0.00000000"], tooltip = "Currency Rounding for account currency values", inline = "Currency2", group = "Trading Account Currency")
accountSize = input.float(defval = 1000, title = "Account Size: ", tooltip = "Used for risk calculation by percentages if used", group = "Trading Account Currency", inline = "Currency3")
showAccount = input.bool(defval = false, title = "Show?", tooltip = "Show the account value on the widget", inline = "Currency3", group = "Trading Account Currency")
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

riskType = input.string(defval = "% Based", title = "Max Risk Calculation:", options = ["% Based", "Fixed Amount"], group = "Risk Calulation Style", tooltip = "How to use the Max Rsik Amount below.")
riskSizeMax = input.float(defval = 3, minval = 0.01, step = 0.01, title = "Risk Tolerance (% or Money Amount)", group="Risk Calulation Style", inline = "Lots2", tooltip = "Set Max Risk in % or as a money value for a single trade.")  //, tooltip = "Lot Size - Only used for 'Fixed Lot' Calculations Maximum Risk - Set to your maximum risk per trade Value, always used"
riskSizeMaxSet = 0.0
riskSymbol = "%"

if riskType == "% Based"
    riskSizeMaxPercent = riskSizeMax / 100
    riskSizeMaxSet := accountSize * riskSizeMaxPercent
    riskSymbol := str.tostring(riskSizeMax) + "%"
else
    riskSizeMaxSet := riskSizeMax
    riskSymbol := "Fixed"
//

warningColor = input.color(color.rgb(255, 0, 0), title = "Over Risk Warning Color: ", group = "Risk Calulation Style", inline = "Lots3", tooltip = "Changes the background of the Values and Size Areas if the current Stop Loss Value exceeds Risk Tolerance")  //, tooltip = "Used for Fixed Lot Mode, will change the background of the widget if current lot size is too great for the ATR"

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
//-----------  Agreement ----------//
/////////////////////////////////////

agreement = input.bool(defval = false, title = "I agree", tooltip = "Must be chacked for value calculation to work, otherwise displays basic ATR, Stop And Target distance calculations without money values", group = "RISK WARNING: Due to rounding and other factors, values are for reference only, and not guaranteed 100% accurate. Developer is not responsible for the outcome from use of this information, good or bad:")

/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pipOrPointValueDesc = " "
pointOption = input.string(defval = "Forex", title = "Calculate Method: ", options = ["Stocks", "Forex"], tooltip = "Forex: Enable to make Lot Calculations", inline = "Extras1", group = "*************      Enable Extra Calculations      *************")
if pointOption == "Forex"
    pipOrPointValueDesc := "Pip Value: "
else
    pipOrPointValueDesc := "Point Value: "
//
string lotModeDesc = ""
lotModeOption = input.string(defval = "Automatic", title = "Calculation Mode: ", options = ["Automatic", "Manual"], inline = "Extras2", group="*************      Enable Extra Calculations      *************", tooltip = "Automatic Mode: Caluclate the most efficient size to use for risk tolerance. Manual Mode: for fixed size trading")
if lotModeOption == "Automatic"
    lotModeDesc := "(Auto)"
else
    lotModeDesc := "(User)"
//

/////////////////////////////////////
// ------ Lot Sizing Section ----- //
/////////////////////////////////////

float lotSizeFull = 0
float lotSizeShort = 0.01   //  ==>> The User Lot Size
lotSizeShortUser = input.float(defval = 0.01, title = "Manual Lot Size", minval = 0.01, step = 0.01, tooltip = "If using manual calculation mode, set this for the intended size to use for value calculations", group = "------------- Forex Settings -------------")
if lotModeOption == "Manual"
    lotSizeShort := lotSizeShortUser
else
    lotSizeShort := 0.01
//

pipValueFormat = input.string(defval = "0.0000",title = "Pip Value Rounding", options = ["0", "0.0", "0.00", "0.000", "0.0000", "0.00000", "0.000000", "0.0000000", "0.00000000"],tooltip = "Round the Pip Value Displayed in the Widget", group = "------------- Forex Settings -------------" )
rateSettingOption = input.string(defval = "Real-Time Rate", title = "Rate Based on:", options = ["Real-Time Rate", "Daily Exchange"], group = "------------- Forex Settings -------------", tooltip = "Which rate does your broker use for cross currency/non account currency exchange rate. Real-Time is default")

/////////////////////////////////////
// ---- Pip Value Calculation ---- //
/////////////////////////////////////
// ==== Global Variables ==>> Pip Value
float pointValue = 0
float pipValue = 0    // Used to make caluculations on lot size


//if quote = account set to pip value = 0.10 * (lotSizeShort * 100)
converterBaseCurrency = syminfo.basecurrency
converterQuoteCurrency = syminfo.currency
// Temp Values for checking exchange, bypass for error issues with request.secutrity when trading an istrument where the account piar is one of the quote or base pair currencies. You can't trade a recipricol of the same pair....
converterBaseCurrency2 = syminfo.basecurrency
accountCurrency2 = accountCurrency
if converterBaseCurrency2 == accountCurrency or pointOption != "Forex"  // Can't put request() calls inside ifs, so make a known ticker for it if not needed and avoid the unknown ticker issue (you must be trading the base and recirocal, or not using a forex chart, so not needed for the current instrument...)
    converterBaseCurrency2 := currency.EUR
    accountCurrency2 := currency.USD
//
dailyRate = request.currency_rate(converterBaseCurrency2, accountCurrency2)
realrate = request.security(converterBaseCurrency2 + accountCurrency2,"", close)
rateSetting = 0.0
if rateSettingOption == "Daily Exchange"
    rateSetting := dailyRate
else
    rateSetting := realrate
//
//Determine how to exchange the rates
if accountCurrency == converterQuoteCurrency and pointOption == "Forex"
    pipValue := 0.10 * (lotSizeShort * 100)
else if accountCurrency == converterBaseCurrency  and pointOption == "Forex"
    //Direct Pip Value ==>>
    lotSizeFull := lotSizeShort * 100000
    pointValue := ((syminfo.mintick / close) * lotSizeFull)
    pipValue := pointValue * 10
else if pointOption == "Forex"  // convert account to compared quote pair exchange ////  core pip value * base to quote price of account
    //Account Currency Pip Value ==>>
    lotSizeFull := lotSizeShort * 100000
    pointValue := ((syminfo.mintick / close) * lotSizeFull)
    pipValue := (pointValue * 10) * rateSetting
else// Must not be Forex, cast as stock value
    //Account Currency Pip Value ==>>
    pipValue := 0.01  //cast as USD Stock Value
    pipOrPointValueDesc := "Point Value: "   //cast as USD Stock Value
//
if converterQuoteCurrency == accountCurrency  and pointOption == "Forex"
    pipValueFormat := accountDecimal
if pointOption == "Stocks"
    pipValueFormat := "0.00"
//
/////////////////////////////////////
// -------- END PIP VALUE -------- //
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Pip Value Outputs for Display ==>>
slValueDisplay = ""
tpValueDisplay =  ""
lotSizeDisplay = ""
pipValueDisply = ""

/////////////////////////////////////
// ----- Output Calculations ----- //
/////////////////////////////////////
pointValueCalculation = pipValue / 10

atrValue = pointValueATR * pointValueCalculation
slValue = 0.0
if atrStopStyle == "ATR Multiple"
    slValue := atrValue * atrMultiple1
if atrStopStyle == "Fixed Size"
    slValue := stopSizeFixed * pointValueCalculation
//
tpValue = slValue * atrMultiple2

slBGColor = bgColor
tpBGColor = bgColor
maxRiskBGColor = bgColor
lotSizeBGColor = bgColor

autoLots = 0.0
if lotModeOption == "Automatic" and pointOption == "Forex"
    autoLots := int(riskSizeMaxSet/slValue)
    if autoLots == 0
        autoLots := 1
    //
    pipValue := pipValue * autoLots
    slValue := slValue * autoLots
    tpValue := tpValue * autoLots
    lotSizeShort := autoLots /100

    slValueDisplay := "Stop " + accountSymbol + " " + str.tostring(slValue, accountDecimal)
    tpValueDisplay :=  "Profit " + accountSymbol + " " + str.tostring(tpValue, accountDecimal)

    // Pip Value Outputs for Display ==>>
    lotSizeDisplay := "Lot Size " + lotModeDesc + " : " + str.tostring(lotSizeShort, '0.00')
    pipValueDisply := pipOrPointValueDesc + accountSymbol + " " + str.tostring(pipValue, pipValueFormat)

//

if lotModeOption == "Manual"
    slValueDisplay := "Stop " + accountSymbol + " " + str.tostring(slValue, accountDecimal)
    tpValueDisplay :=  "Profit " + accountSymbol + " " + str.tostring(tpValue, accountDecimal)

    // Pip Value Outputs for Display ==>>
    lotSizeDisplay := "Lot Size " + lotModeDesc + " : " + str.tostring(lotSizeShort, '0.00')
    pipValueDisply := pipOrPointValueDesc + accountSymbol + " " + str.tostring(pipValue, pipValueFormat)
//

float shares = 0.0
float shareCost = 0.0
sharesSet = input.int(defval = 1, title = "# of Shares", minval = 1, step = 1, tooltip = "If using manual mode, set this for the intended size to use for value calculations", group = "------------- Stock Settings -------------")
tickerSymbol = close

if pointOption == "Stocks"
    lotSizeShort := 0.01
    pipValue := 0.01
    slValue := slValue * 10
    tpValue := tpValue * 10

    if lotModeOption == "Automatic" and pointOption == "Stocks"
        shares := int(riskSizeMaxSet/tickerSymbol)
        if shares == 0
            shares := 1
    if lotModeOption == "Manual" and pointOption == "Stocks"
        shares := sharesSet
        shareCost := tickerSymbol * sharesSet
    //
    slValue := slValue * shares
    tpValue := tpValue * shares
    pipValue := pipValue *shares
    slValueDisplay := "Stop " + accountSymbol + " " + str.tostring(slValue, accountDecimal)
    tpValueDisplay :=  "Profit " + accountSymbol + " " + str.tostring(tpValue, accountDecimal)
    // Pip Value Outputs for Display ==>>str.tostring(tickerSymbol)
    lotSizeDisplay := "@ $ " + str.tostring(tickerSymbol) + " / Share " + lotModeDesc + " : " + str.tostring(shares, '0')
    pipValueDisply := pipOrPointValueDesc + accountSymbol + " " + str.tostring(pipValue, pipValueFormat)
//

if slValue > riskSizeMaxSet or (tickerSymbol * shares) > riskSizeMaxSet or (tickerSymbol * shares) > accountSize or shareCost > accountSize
    slBGColor := warningColor
    tpBGColor := warningColor
    maxRiskBGColor := warningColor
    lotSizeBGColor := warningColor
else
    slBGColor := bgColor
    tpBGColor := bgColor
    maxRiskBGColor := bgColor
    lotSizeBGColor := bgColor
//

riskSizeMaxDisplay = "Max Risk (" + riskSymbol + ") : " + accountSymbol + " " + str.tostring(riskSizeMaxSet, accountDecimal)

/////////////////////////////////////
// ---------- Grid Fill ---------- //
/////////////////////////////////////
// Table Layout ==>>
//  00  10  20
//  01  11  21
//  02  12  22

grid00 = atrDisplay
grid01 = atrSLDisplay
grid02 = atrTPDisplay
grid10 = lotSizeDisplay  //lotSizeBGColor = bgColor
grid11 = slValueDisplay  //slBGColor = bgColor
grid12 = tpValueDisplay  //tpBGColor = bgColor
grid20 = pipValueDisply
grid21 = riskSizeMaxDisplay  //maxRiskBGColor = bgColor
grid22 = ""
grid23 = ""

if showAccount == true
    if tableRowStr == "Box" or tableRowStr == "Double Row"
        grid22 := "Account Size : "
        grid23 := accountSymbol + " " + str.tostring(accountSize, accountDecimal)
    else
        grid22 := "Account Size : " + accountSymbol + " " + str.tostring(accountSize, accountDecimal)
else
    grid22 := ""
    grid23 := ""
//

/////////////////////////////////////
// -- Calculate Table Plotting --- //
/////////////////////////////////////

//Plot The Table ==>> tableRowStr                     "3 x 3", "Single Column", "Box", "Single Row", "Double Row"

if tableRowStr == "Single Column"
    var table displayTable = table.new(tablePos, 1, 9, frame_width = frameSizeSet, frame_color = frColor, border_color = borderColor1, border_width = borderSize1)

    table.cell(displayTable, 0, 0, grid00, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//ATR = 00 (00)
    if atrRisk == true
        table.cell(displayTable, 0, 1, grid01, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//SL = 01 (01)
        table.cell(displayTable, 0, 2, grid02, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//TP = 02 (02)
        if agreement == true
            table.cell(displayTable, 0, 3, grid10, bgcolor = lotSizeBGColor, text_color=tableColor, text_size = widgetSize)// Lot Size = 04 (10) //lotSizeBGColor = bgColor
            table.cell(displayTable, 0, 4, grid20, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//Pip Value = 03 (20)
            table.cell(displayTable, 0, 6, grid11, bgcolor = slBGColor, text_color=tableColor, text_size = widgetSize)// SL Value = 05  (11) //slBGColor = bgColor
            table.cell(displayTable, 0, 5, grid21, bgcolor = maxRiskBGColor, text_color=tableColor, text_size = widgetSize)// Max Risk = 07 (21)  //maxRiskBGColor = bgColor
            table.cell(displayTable, 0, 7, grid12, bgcolor = tpBGColor, text_color=tableColor, text_size = widgetSize)// TP Value = 06  (12) //tpBGColor = bgColor
            
            if showAccount == true
                table.cell(displayTable, 0, 8, grid22, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)// Account Value = 08 (22)
//

if tableRowStr == "Box"
    var table displayTable = table.new(tablePos, 2, 5, frame_width = frameSizeSet, frame_color = frColor, border_color = borderColor1, border_width = borderSize1)

    table.cell(displayTable, 0, 0, grid00, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
    if atrRisk == true
        table.cell(displayTable, 0, 1, grid01, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
        table.cell(displayTable, 0, 2, grid02, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
        if agreement == true
            table.cell(displayTable, 0, 3, grid10, bgcolor = lotSizeBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 0, grid20, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 1, grid11, bgcolor = slBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 2, grid12, bgcolor = tpBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 3, grid21, bgcolor = maxRiskBGColor, text_color=tableColor, text_size = widgetSize)
            if showAccount == true
                table.cell(displayTable, 0, 4, grid22, bgcolor = bgColor, text_halign = text.align_right, text_color=tableColor, text_size = widgetSize)
                table.cell(displayTable, 1, 4, grid23, bgcolor = bgColor, text_halign = text.align_left, text_color=tableColor, text_size = widgetSize)
//

if tableRowStr == "Single Row"
    var table displayTable = table.new(tablePos, 9, 1, frame_width = frameSizeSet, frame_color = frColor, border_color = borderColor1, border_width = borderSize1)

    table.cell(displayTable, 0, 0, grid00, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//ATR = 00 (00)
    if atrRisk == true
        table.cell(displayTable, 1, 0, grid01, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//SL = 01 (01)
        table.cell(displayTable, 3, 0, grid02, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//TP = 02 (02)
        if agreement == true
            table.cell(displayTable, 5, 0, grid10, bgcolor = lotSizeBGColor, text_color=tableColor, text_size = widgetSize)// Lot Size = 04 (10) //lotSizeBGColor = bgColor
            table.cell(displayTable, 6, 0, grid20, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//Pip Value = 03 (20)
            table.cell(displayTable, 2, 0, grid11, bgcolor = slBGColor, text_color=tableColor, text_size = widgetSize)// SL Value = 05  (11) //slBGColor = bgColor
            table.cell(displayTable, 7, 0, grid21, bgcolor = maxRiskBGColor, text_color=tableColor, text_size = widgetSize)// Max Risk = 07 (21)  //maxRiskBGColor = bgColor
            table.cell(displayTable, 4, 0, grid12, bgcolor = tpBGColor, text_color=tableColor, text_size = widgetSize)// TP Value = 06  (12) //tpBGColor = bgColor
            
            if showAccount == true
                table.cell(displayTable, 8, 0, grid22, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)// Account Value = 08 (22)
//

if tableRowStr == "Double Row"
    var table displayTable = table.new(tablePos, 5, 2, frame_width = frameSizeSet, frame_color = frColor, border_color = borderColor1, border_width = borderSize1)

    table.cell(displayTable, 0, 0, grid00, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//ATR = 00 (00)
    if atrRisk == true
        table.cell(displayTable, 1, 0, grid01, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//SL = 01 (01)
        table.cell(displayTable, 2, 0, grid02, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//TP = 02 (02)
        if agreement == true
            table.cell(displayTable, 3, 0, grid10, bgcolor = lotSizeBGColor, text_color=tableColor, text_size = widgetSize)// Lot Size = 04 (10) //lotSizeBGColor = bgColor
            table.cell(displayTable, 0, 1, grid20, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)//Pip Value = 03 (20)
            table.cell(displayTable, 1, 1, grid11, bgcolor = slBGColor, text_color=tableColor, text_size = widgetSize)// SL Value = 05  (11) //slBGColor = bgColor
            table.cell(displayTable, 3, 1, grid21, bgcolor = maxRiskBGColor, text_color=tableColor, text_size = widgetSize)// Max Risk = 07 (21)  //maxRiskBGColor = bgColor
            table.cell(displayTable, 2, 1, grid12, bgcolor = tpBGColor, text_color=tableColor, text_size = widgetSize)// TP Value = 06  (12) //tpBGColor = bgColor
            
            if showAccount == true
                table.cell(displayTable, 4, 0, grid22, bgcolor = bgColor, text_halign = text.align_center, text_color=tableColor, text_size = widgetSize)
                table.cell(displayTable, 4, 1, grid23, bgcolor = bgColor, text_halign = text.align_center, text_color=tableColor, text_size = widgetSize)
//

// 3 x 3
if tableRowStr == "3 x 3"
    var table displayTable = table.new(tablePos, 3, 3, frame_width = frameSizeSet, frame_color = frColor, border_color = borderColor1, border_width = borderSize1)

    table.cell(displayTable, 0, 0, grid00, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
    if atrRisk == true
        table.cell(displayTable, 0, 1, grid01, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
        table.cell(displayTable, 0, 2, grid02, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
        if agreement == true
            table.cell(displayTable, 1, 0, grid10, bgcolor = lotSizeBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 1, grid11, bgcolor = slBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 1, 2, grid12, bgcolor = tpBGColor, text_color=tableColor, text_size = widgetSize)

            table.cell(displayTable, 2, 0, grid20, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 2, 1, grid21, bgcolor = maxRiskBGColor, text_color=tableColor, text_size = widgetSize)
            table.cell(displayTable, 2, 2, grid22, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize) //table.cell(displayTable, 2, 2, grid22, bgcolor = bgColor, text_color=tableColor, text_size = widgetSize)
//