1

I am trying to set the default value in the input field to be a certain starting value based on the marketcap of the security. I can't get it to work. There is a problem with the series and it's keeping the first constant definition fixed. Defining a variable also doesn't work. What is the correct way to do this? I want to be able to set "acc" to be a certain value based on the size of the marketcap. Here in this example I have simplified it to see if its working.

//@version=5
indicator("Factor", overlay=true, timeframe="", timeframe_gaps=true)
_Outstanding = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
_close = close
_mv = _Outstanding * _close
acc = 5.0

if _mv >= 1.0
    acc = 10.0
else
    acc = 2.0

atrfactor = input.float(acc, "factor", minval = 1.0, step = 0.1)
plotchar(_mv, "MV", "", location = location.top)
AndiAna
  • 854
  • 6
  • 26

2 Answers2

1

Since the above code is not working and I have found a way to solve this I am posting my answer here for the people in the future looking for the same solution to my problem.

Here is the code:

//@version=5
indicator("Testcode" ,"Testing", true)
TSO = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ", ignore_invalid_symbol = true)
MarketCap = TSO * close
megacap = input.float(2.0, "Mega Cap", minval = 0.0, step = 0.1)
bigcap = input.float(3.0, "Big Cap", minval = 0.0, step = 0.1)
myfactor = (MarketCap >= 1000000000000) ? megacap : (MarketCap >= 10000000000) ? bigcap : 5.0
plotchar(myfactor, "myfactor", "", location = location.top)

which updates the myfactor variable in the Data Window

datasheet

according to the type of stock you are looking at, here AAPL, SQ and TNDM for comparison

AAPL SQ TNDM

AndiAna
  • 854
  • 6
  • 26
0

You need to use the reassignment operator := to change the value of acc. You can't have the input value be set to 'acc' but you can change the input value based on the market cap.

Below I set your 'atrfactor' input to 5.0. by default and then use the reassignment operator to change the value of the 'atrfactor'. I added the label so you can see the value change. It will always be 10 though since every company has a market cap greater than 1.0

//@version=5
indicator("Factor", overlay=true)
atrfactor = input.float(5.0, "factor", minval = 1.0, step = 0.1)
_Outstanding = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ")
_close = close
_mv = _Outstanding * _close

if _mv >= 1.0
    atrfactor := 10.0
else
    atrfactor := 2.0

plotchar(_mv, "MV", "", location = location.top)
if barstate.islast
    label.new(bar_index, high, str.tostring(atrfactor), color=color.aqua)

enter image description here

smashapalooza
  • 932
  • 2
  • 2
  • 12
  • I have tried your code but the value still doesn't change its 5 still. The MV value is correct though and >1 so the atrfactor should be 10 and not 5 in the chart. – AndiAna Jun 23 '23 at 08:33
  • not sure what you are doing different than, see attached image of copy and pasted code from above in the label the value of atrfactor is 10 not 5 – smashapalooza Jun 23 '23 at 13:27