[5-2-2023] MNQ CALC
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © perrysrich

//@version=5
indicator("MNQ Calc", overlay=true)

risking = input.int(title="Dollar Risk", defval = 100, minval = 100)

location_table(type) =>
    switch type
        "Top Right" => position.top_right
        "Top Left" => position.top_left
        "Bottom Right" => position.bottom_right
        "Bottom Left" => position.bottom_left

position = input.string(title="Table Position?", defval = "Bottom Right", options = ["Bottom Right", "Top Right", "Top Left", "Bottom Left"])
final_location = location_table(position)

prevCandleSize = (math.abs(high[1] - low[1]))


stopLoss = input.float(title="Price of Stop Loss:", defval = 0, minval = 0)

contractsNeeded = math.round(risking / ((math.abs(close[1] - stopLoss)) * 2))


var mnqTable = table.new(position = final_location, columns = 4, rows = 4, bgcolor = color.white, border_color = color.rgb(0, 0, 0), border_width = 4)

if barstate.islast
    table.cell(table_id = mnqTable, column = 0, row = 0, text="Prev Candle Size: " + str.tostring(prevCandleSize) + " Pts")
    table.cell(table_id = mnqTable, column = 0, row = 1, text="Reccommended Contracts:  " + str.tostring(contractsNeeded))
    table.cell(table_id = mnqTable, column = 1, row = 0, text="Current Risk:  $" + str.tostring(risking))
    table.cell(table_id = mnqTable, column = 1, row = 1, text="Stop Loss: " + str.tostring(stopLoss))

// if account is risking this amount, stop loss should be at what yloc.price

