BINANCE_Minimum_qty_for_trading
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © potatoshop

//@version=5
indicator("BINANCE_Minimum_qty_for_trading",precision=5)


ceil_truncate(float number, float min_unit = 1.0) =>
    getDecimals =  math.abs(math.log(min_unit) / math.log(10))
    factor = math.pow(10, getDecimals)
    math.ceil(number * factor) / factor
    
truncate(float number, float min_unit = 1.0) =>
    getDecimals =  math.abs(math.log(min_unit) / math.log(10))
    factor = math.pow(10, getDecimals)
    int(number * factor) / factor
////////////////////////////////////////////////////////////////////////////////
var min_unit_str=""

var m = matrix.new<string>(158,2)

matrix.set(m, 0,	0,"0.001"),matrix.set(m, 0,	1,"BCH")
matrix.set(m, 1,	0,"0.001"),matrix.set(m, 1,	1,"BTC")
matrix.set(m, 2,	0,"0.001"),matrix.set(m, 2,	1,"BTCDOM")
matrix.set(m, 3,	0,"0.001"),matrix.set(m, 3,	1,"COMP")
matrix.set(m, 4,	0,"0.001"),matrix.set(m, 4,	1,"DASH")
matrix.set(m, 5,	0,"0.001"),matrix.set(m, 5,	1,"DEFI")
matrix.set(m, 6,	0,"0.001"),matrix.set(m, 6,	1,"ETH")
matrix.set(m, 7,	0,"0.001"),matrix.set(m, 7,	1,"LTC")
matrix.set(m, 8,	0,"0.001"),matrix.set(m, 8,	1,"MKR")
matrix.set(m, 9,	0,"0.001"),matrix.set(m, 9,	1,"XMR")
matrix.set(m, 10,	0,"0.001"),matrix.set(m, 10,1,"YFI")
matrix.set(m, 11,	0,"0.001"),matrix.set(m, 11,1,"ZEC")
matrix.set(m, 12,	0,"0.01"),matrix.set(m, 12,	1,"ATOM")
matrix.set(m, 13,	0,"0.01"),matrix.set(m, 13,	1,"BNB")
matrix.set(m, 14,	0,"0.01"),matrix.set(m, 14,	1,"ETC")
matrix.set(m, 15,	0,"0.01"),matrix.set(m, 15,	1,"LINK")
matrix.set(m, 16,	0,"0.01"),matrix.set(m, 16,	1,"LTC")
matrix.set(m, 17,	0,"0.01"),matrix.set(m, 17,	1,"NEO")
matrix.set(m, 18,	0,"0.1"),matrix.set(m, 18,	1,"AAVE")
matrix.set(m, 19,	0,"0.1"),matrix.set(m, 19,	1,"ALGO")
matrix.set(m, 20,	0,"0.1"),matrix.set(m, 20,	1,"ALICE")
matrix.set(m, 21,	0,"0.1"),matrix.set(m, 21,	1,"ANT")
matrix.set(m, 22,	0,"0.1"),matrix.set(m, 22,	1,"APE")
matrix.set(m, 23,	0,"0.1"),matrix.set(m, 23,	1,"API3")
matrix.set(m, 24,	0,"0.1"),matrix.set(m, 24,	1,"AR")
matrix.set(m, 25,	0,"0.1"),matrix.set(m, 25,	1,"AUCTION")
matrix.set(m, 26,	0,"0.1"),matrix.set(m, 26,	1,"AVAX")
matrix.set(m, 27,	0,"0.1"),matrix.set(m, 27,	1,"BAL")
matrix.set(m, 28,	0,"0.1"),matrix.set(m, 28,	1,"BAND")
matrix.set(m, 29,	0,"0.1"),matrix.set(m, 29,	1,"BAT")
matrix.set(m, 30,	0,"0.1"),matrix.set(m, 30,	1,"BNX")
matrix.set(m, 31,	0,"0.1"),matrix.set(m, 31,	1,"CELO")
matrix.set(m, 32,	0,"0.1"),matrix.set(m, 32,	1,"CRV")
matrix.set(m, 33,	0,"0.1"),matrix.set(m, 33,	1,"CVX")
matrix.set(m, 34,	0,"0.1"),matrix.set(m, 34,	1,"DAR")
matrix.set(m, 35,	0,"0.1"),matrix.set(m, 35,	1,"DOT")
matrix.set(m, 36,	0,"0.1"),matrix.set(m, 36,	1,"DYDX")
matrix.set(m, 37,	0,"0.1"),matrix.set(m, 37,	1,"EGLD")
matrix.set(m, 38,	0,"0.1"),matrix.set(m, 38,	1,"ENS")
matrix.set(m, 39,	0,"0.1"),matrix.set(m, 39,	1,"EOS")
matrix.set(m, 40,	0,"0.1"),matrix.set(m, 40,	1,"ETC")
matrix.set(m, 41,	0,"0.1"),matrix.set(m, 41,	1,"FIL")
matrix.set(m, 42,	0,"0.1"),matrix.set(m, 42,	1,"FLOW")
matrix.set(m, 43,	0,"0.1"),matrix.set(m, 43,	1,"FTT")
matrix.set(m, 44,	0,"0.1"),matrix.set(m, 44,	1,"GMT")
matrix.set(m, 45,	0,"0.1"),matrix.set(m, 45,	1,"GTC")
matrix.set(m, 46,	0,"0.1"),matrix.set(m, 46,	1,"ICP")
matrix.set(m, 47,	0,"0.1"),matrix.set(m, 47,	1,"IOTA")
matrix.set(m, 48,	0,"0.1"),matrix.set(m, 48,	1,"KAVA")
matrix.set(m, 49,	0,"0.1"),matrix.set(m, 49,	1,"KLAY")
matrix.set(m, 50,	0,"0.1"),matrix.set(m, 50,	1,"KSM")
matrix.set(m, 51,	0,"0.1"),matrix.set(m, 51,	1,"LDO")
matrix.set(m, 52,	0,"0.1"),matrix.set(m, 52,	1,"LINK")
matrix.set(m, 53,	0,"0.1"),matrix.set(m, 53,	1,"LIT")
matrix.set(m, 54,	0,"0.1"),matrix.set(m, 54,	1,"LPT")
matrix.set(m, 55,	0,"0.1"),matrix.set(m, 55,	1,"NEAR")
matrix.set(m, 56,	0,"0.1"),matrix.set(m, 56,	1,"OMG")
matrix.set(m, 57,	0,"0.1"),matrix.set(m, 57,	1,"ONT")
matrix.set(m, 58,	0,"0.1"),matrix.set(m, 58,	1,"OP")
matrix.set(m, 59,	0,"0.1"),matrix.set(m, 59,	1,"QTUM")
matrix.set(m, 60,	0,"0.1"),matrix.set(m, 60,	1,"RAY")
matrix.set(m, 61,	0,"0.1"),matrix.set(m, 61,	1,"RLC")
matrix.set(m, 62,	0,"0.1"),matrix.set(m, 62,	1,"SAND")
matrix.set(m, 63,	0,"0.1"),matrix.set(m, 63,	1,"SNX")
matrix.set(m, 64,	0,"0.1"),matrix.set(m, 64,	1,"SXP")
matrix.set(m, 65,	0,"0.1"),matrix.set(m, 65,	1,"THETA")
matrix.set(m, 66,	0,"0.1"),matrix.set(m, 66,	1,"TRB")
matrix.set(m, 67,	0,"0.1"),matrix.set(m, 67,	1,"UNFI")
matrix.set(m, 68,	0,"0.1"),matrix.set(m, 68,	1,"UNI")
matrix.set(m, 69,	0,"0.1"),matrix.set(m, 69,	1,"WAVES")
matrix.set(m, 70,	0,"0.1"),matrix.set(m, 70,	1,"XRP")
matrix.set(m, 71,	0,"0.1"),matrix.set(m, 71,	1,"XTZ")
matrix.set(m, 72,	0,"0.1"),matrix.set(m, 72,	1,"ZEN")
matrix.set(m, 73,	0,"0.1"),matrix.set(m, 73,	1,"ZRX")
matrix.set(m, 74,	0,"1"),matrix.set(m, 74,1,"000LUNC")
matrix.set(m, 75,	0,"1"),matrix.set(m, 75,1,"000SHIB")
matrix.set(m, 76,	0,"1"),matrix.set(m, 76,1,"000XEC")
matrix.set(m, 77,	0,"1"),matrix.set(m, 77,1,"INCH")
matrix.set(m, 78,	0,"1"),matrix.set(m, 78,1,"DA")
matrix.set(m, 79,	0,"1"),matrix.set(m, 79,1,"LPHA")
matrix.set(m, 80,	0,"1"),matrix.set(m, 80,1,"NC")
matrix.set(m, 81,	0,"1"),matrix.set(m, 81,1,"NKR")
matrix.set(m, 82,	0,"1"),matrix.set(m, 82,1,"PE")
matrix.set(m, 83,	0,"1"),matrix.set(m, 83,1,"RPA")
matrix.set(m, 84,	0,"1"),matrix.set(m, 84,1,"TA")
matrix.set(m, 85,	0,"1"),matrix.set(m, 85,1,"UDIO")
matrix.set(m, 86,	0,"1"),matrix.set(m, 86,1,"VAX")
matrix.set(m, 87,	0,"1"),matrix.set(m, 87,1,"XS")
matrix.set(m, 88,	0,"1"),matrix.set(m, 88,1,"AKE")
matrix.set(m, 89,	0,"1"),matrix.set(m, 89,1,"EL")
matrix.set(m, 90,	0,"1"),matrix.set(m, 90,1,"LZ")
matrix.set(m, 91,	0,"1"),matrix.set(m, 91,1,"TS")
matrix.set(m, 92,	0,"1"),matrix.set(m, 92,1,"98")
matrix.set(m, 93,	0,"1"),matrix.set(m, 93,1,"ELR")
matrix.set(m, 94,	0,"1"),matrix.set(m, 94,1,"HR")
matrix.set(m, 95,	0,"1"),matrix.set(m, 95,1,"HZ")
matrix.set(m, 96,	0,"1"),matrix.set(m, 96,1,"OTI")
matrix.set(m, 97,	0,"1"),matrix.set(m, 97,1,"TK")
matrix.set(m, 98,	0,"1"),matrix.set(m, 98,1,"TSI")
matrix.set(m, 99,	0,"1"),matrix.set(m, 99,1,"VC")
matrix.set(m, 100,	0,"1"),matrix.set(m, 100,1,"DENT")
matrix.set(m, 101,	0,"1"),matrix.set(m, 101,1,"DGB")
matrix.set(m, 102,	0,"1"),matrix.set(m, 102,1,"DODO")
matrix.set(m, 103,	0,"1"),matrix.set(m, 103,1,"DOGE")
matrix.set(m, 104,	0,"1"),matrix.set(m, 104,1,"DUSK")
matrix.set(m, 105,	0,"1"),matrix.set(m, 105,1,"ENJ")
matrix.set(m, 106,	0,"1"),matrix.set(m, 106,1,"FLM")
matrix.set(m, 107,	0,"1"),matrix.set(m, 107,1,"FTM")
matrix.set(m, 108,	0,"1"),matrix.set(m, 108,1,"GAL")
matrix.set(m, 109,	0,"1"),matrix.set(m, 109,1,"GALA")
matrix.set(m, 110,	0,"1"),matrix.set(m, 110,1,"GMT")
matrix.set(m, 111,	0,"1"),matrix.set(m, 111,1,"GRT")
matrix.set(m, 112,	0,"1"),matrix.set(m, 112,1,"HBAR")
matrix.set(m, 113,	0,"1"),matrix.set(m, 113,1,"HNT")
matrix.set(m, 114,	0,"1"),matrix.set(m, 114,1,"HOT")
matrix.set(m, 115,	0,"1"),matrix.set(m, 115,1,"ICX")
matrix.set(m, 116,	0,"1"),matrix.set(m, 116,1,"IMX")
matrix.set(m, 117,	0,"1"),matrix.set(m, 117,1,"IOST")
matrix.set(m, 118,	0,"1"),matrix.set(m, 118,1,"IOTX")
matrix.set(m, 119,	0,"1"),matrix.set(m, 119,1,"JASMY")
matrix.set(m, 120,	0,"1"),matrix.set(m, 120,1,"KNC")
matrix.set(m, 121,	0,"1"),matrix.set(m, 121,1,"LEVER")
matrix.set(m, 122,	0,"1"),matrix.set(m, 122,1,"LINA")
matrix.set(m, 123,	0,"1"),matrix.set(m, 123,1,"LRC")
matrix.set(m, 124,	0,"1"),matrix.set(m, 124,1,"LUNA2")
matrix.set(m, 125,	0,"1"),matrix.set(m, 125,1,"MANA")
matrix.set(m, 126,	0,"1"),matrix.set(m, 126,1,"MASK")
matrix.set(m, 127,	0,"1"),matrix.set(m, 127,1,"MATIC")
matrix.set(m, 128,	0,"1"),matrix.set(m, 128,1,"MTL")
matrix.set(m, 129,	0,"1"),matrix.set(m, 129,1,"NEAR")
matrix.set(m, 130,	0,"1"),matrix.set(m, 130,1,"NKN")
matrix.set(m, 131,	0,"1"),matrix.set(m, 131,1,"OCEAN")
matrix.set(m, 132,	0,"1"),matrix.set(m, 132,1,"OGN")
matrix.set(m, 133,	0,"1"),matrix.set(m, 133,1,"ONE")
matrix.set(m, 134,	0,"1"),matrix.set(m, 134,1,"PEOPLE")
matrix.set(m, 135,	0,"1"),matrix.set(m, 135,1,"REEF")
matrix.set(m, 136,	0,"1"),matrix.set(m, 136,1,"REN")
matrix.set(m, 137,	0,"1"),matrix.set(m, 137,1,"ROSE")
matrix.set(m, 138,	0,"1"),matrix.set(m, 138,1,"RSR")
matrix.set(m, 139,	0,"1"),matrix.set(m, 139,1,"RUNE")
matrix.set(m, 140,	0,"1"),matrix.set(m, 140,1,"RVN")
matrix.set(m, 141,	0,"1"),matrix.set(m, 141,1,"SAND")
matrix.set(m, 142,	0,"1"),matrix.set(m, 142,1,"SFP")
matrix.set(m, 143,	0,"1"),matrix.set(m, 143,1,"SKL")
matrix.set(m, 144,	0,"1"),matrix.set(m, 144,1,"SOL")
matrix.set(m, 145,	0,"1"),matrix.set(m, 145,1,"SRM")
matrix.set(m, 146,	0,"1"),matrix.set(m, 146,1,"STMX")
matrix.set(m, 147,	0,"1"),matrix.set(m, 147,1,"STORJ")
matrix.set(m, 148,	0,"1"),matrix.set(m, 148,1,"SUSHI")
matrix.set(m, 149,	0,"1"),matrix.set(m, 149,1,"TLM")
matrix.set(m, 150,	0,"1"),matrix.set(m, 150,1,"TOMO")
matrix.set(m, 151,	0,"1"),matrix.set(m, 151,1,"TRX")
matrix.set(m, 152,	0,"1"),matrix.set(m, 152,1,"UNI")
matrix.set(m, 153,	0,"1"),matrix.set(m, 153,1,"VET")
matrix.set(m, 154,	0,"1"),matrix.set(m, 154,1,"WOO")
matrix.set(m, 155,	0,"1"),matrix.set(m, 155,1,"XEM")
matrix.set(m, 156,	0,"1"),matrix.set(m, 156,1,"XLM")
matrix.set(m, 157,	0,"1"),matrix.set(m, 157,1,"ZIL")

var bool is_right = false
for i=0 to 157
    if syminfo.basecurrency == matrix.get(m,i,1) and syminfo.prefix == "BINANCE"
        min_unit_str := matrix.get(m,i,0)
        is_right := true
if is_right == false
    runtime.error("hey~~!! it,s not Binance, check the exchange" )
    
min_notional_value = input.float(5,"min_notional_value") // Binance have chaged their Minimum notion value from 10 USD to 5 USD.  
min_unit = str.tonumber(min_unit_str)                    // The minimum Limit Order amount for the contract.
maker_fee = input.float(0.02, "maker_fee %")             // %
taker_fee = input.float(0.04, "taker_fee %")             // %
cost = input.float(100.0,"your investing money")         // dollar
maker_taker = input.string("M",title="maker_taker",options=["M","T"])

fee = maker_taker == "M"? maker_fee : taker_fee

min_qty = ceil_truncate(min_notional_value*(1+fee/100)/close,min_unit) // base coin
min_cost = (min_qty*close)*(1+fee/100)
posible_qty = truncate(cost/close,min_unit) >= min_qty? truncate(cost/close,min_unit) : 0 // Amount 
how_many_unit = posible_qty/min_unit
how_much_cost = posible_qty*close
how_much_costwithfee = (posible_qty*close)*(1+fee/100)

plot(min_qty,"min_Q",color.blue) 
plot(min_cost,"min_C",color.yellow)
plot(posible_qty,"posible_qty",color.white)
plot(how_many_unit,"how_many_min_unit",color.lime)
plot(how_much_cost,"just Q x C",color.gray)
plot(how_much_costwithfee,"real invest cost with fee",color.white)


