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.

AllinOneAlerts – Amibroker Alerts Module for Algomojo Users

AllinOneAlerts is one of the most important and most requested modules is to bring all sorts of alerts with few lines of coding efforts....
Rajandran R
58 sec read

Stop and Reverse Cover Orders/Bracket Orders – Automated Chart…

Bracket Order and Cover Order are multi-legged orders which come with default protection with stop loss with reasonable intraday leverage. This tutorial focus...
Rajandran R
11 min read

Exiting Cover Order and Bracket Order for a Particular…

Bracket Order and Cover Order are multi legged orders and cancelling the bracket order and cover order for a particular trading instrument there are...
Rajandran R
1 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