0

I am trying to plot the close price of the ATM Call of the selected script In the code below, I can successfully get the correct ticker ID and add a label on the chart.

//@version=6
indicator("My script")
import protradingart/pta_plot/12 as pta
// Strike width of NIFTY
strikeWidth = 50
// finding ATM Strike
atmStrike = strikeWidth * (math.round(close / strikeWidth))
// getting the expiry date for FNO (From imported Library)
expDate = pta.getExpiry("Monthly", "Thursday", 0, "yyMMdd")
// Converting to string
string atmCallTicker = syminfo.tickerid + expDate + 'C' + str.tostring(atmStrike)
// adding label
if barstate.islast
 label.new(time + 1, close, atmCallTicker, xloc.bar_time, color = color.gray, style = label.style_label_left, force_overlay = true)

When I use the request.security function, it gives an error, and the ticker ID is entirely different in the error message (screenshot attached).

// Requesting the cmp of the ATM Ticker
atmCallPrice = request.security(atmCallTicker, '1D', close)
// Plotting the ATM Ticker
plot(atmCallPrice)

Lavel value and the runtime error symbol value are different

If I manually add the ticker ID (to check), then I can get the correct plot

// Requesting the cmp of the ATM Ticker
atmCallPrice = request.security('NSE:NIFTY250424C22850', '1D', close)
// Plotting the ATM Ticker
plot(atmCallPrice)

I am not able to understand why the expDate and atmStrike values are getting changed when passing them in the request.security function.

asked Apr 14, 2025 at 23:38
2
  • I suggest you ask the people you bought this indicator from, here nobody has this indicator most likely Commented Apr 16, 2025 at 9:39
  • @August1328 sir, I didn't buy it. I wrote my own code and just used the public library which I came across on YouTube. He aslo was just adding the label, I want to take it a step further Commented Apr 17, 2025 at 8:59

1 Answer 1

2

Your script will be executed from the very first bar on.

This means, all those functions and variables will be called/created from the very first bar and on.

The very first bar on NIFTY on the daily timeframe is somewhere in July, 1990. That's what you see in your error message NSE:NIFTY900726 -> 26.07.1990

Your label is only created on the last bar, that's why they do not match.

So, there is no valid ticker for you in 90s.

You can add ignore_invalid_symbol = true to your security() call but then you will have another problem. You will be requesting more than 40 unique security.request() calls. Because as the date changes, your ticker name will change. And you can only make 40 unique security.request() calls in a script.

answered Apr 17, 2025 at 14:23
Sign up to request clarification or add additional context in comments.

1 Comment

Correct. I used if barstate.islast before calling the request.security function with ignore_invalid_symbol = true This way, I can not access the historical data, but I can at least get the requested data's last close price. I could work with it now, but I would appreciate it if there were a way to get all the data. Thank you so much for your response, it made me come to a temporary solution for now.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.