Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Code Snippet: ATM Call and ATM Put calculation from Spot Prices: Amibroker AFL

34 sec read

Here is a simple prototype code with a display dashboard for the System traders who want to calculate ATM Call or ATM Put from the underlying spot price/future price for options backtesting or automated execution purpose.

ATM CE/PE strikes displayed on a dashboard

It is a simple straight forward calculation derived from underlying spot or futures data. Hence, Amibroker data subscription is required to compute ATM CE or ATM PE strikes. However, when it comes to backtesting one need an array of ATM CE & ATM PE strike price and hence static arrays are used to create & store an array of ATM CE & ATM PE symbols which can be further extended to the backtest or automate option trading ideas.

Once ATM CE & PE strikes are calculated it can be even further elongated to calculated ITM or OTM CE or PE strikes.

ATM Calculation – Amibroker AFL Code

https://gist.github.com/a622480bcb87ddf6cb3cf1d576ab0668

Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

Algomojo Index Straddle/Strangle Execution Module with Intraday Stoploss

This tutorial focus on how to automate your index straddle/strangle strategy with intraday stop-loss levels with time-based entry and exits using Algomojo Platform and...
Rajandran R
7 min read

Learn How to Login into Algomojo Account using Amibroker

In the last tutorial, we learn how to automate the algomojo login process and in this video tutorial, we are going to learn with...
Rajandran R
1 min read

Amibroker Execution Module – Hedged Index Futures for Directional…

In the last tutorial, we learn the importance of Hedging Futures Position with OTM Options for Reduced Margin. This tutorial focus on how to...
Rajandran R
14 min read

4 Replies to “Code Snippet: ATM Call and ATM Put calculation from…”

  1. Sorry, but absolutely rotten way to write the code. Bad choice of variable name also. Interval implies time. better name would be StrikeGap

    ///////////////////// SCALAR VALUE CREATION
    paramStrikeGap = Param(“Strike Interval”,50,1,5000,1);

    rootStrike = int( ( LastValue(Close) / paramStrikeGap ) ) * paramStrikeGap;

    callStrike = rootStrike – paramStrikeGap;
    putStrike = rootStrike + paramStrikeGap;

    //…. All code necesssary for display
    ///////////////////// VECTOR VALUE CREATION
    paramStrikeGap = Param(“Strike Interval”,50,1,5000,1);

    rootStrike = int( Close / paramStrikeGap ) * paramStrikeGap;

    callStrike = rootStrike – paramStrikeGap;
    putStrike = rootStrike + paramStrikeGap;

    //…. All code necesssary for display

    1. What we provided is a code snippet to built an array of ATM symbols (strings) for option backtesting purposes.
      Not just to display ATM CE or ATM PE strikes which one can do with simple math.

  2. Storing StaticVarSetText inside the loop slow down the whole process i have expanded this code to calculate OTM and ITM and its very slow, instead of storing StaticVarSetText inside the loop i simply call convert it to NumtoStr to print the output its 1000 times faster than above code, example if you calculate ATM,OTM,ITM in above manner it takes minimum 8 to 9 sec to execute where as numtostr way deliver the same result in 0.14 sec.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More