Skip to content

Instantly share code, notes, and snippets.

@marketcalls
Last active September 19, 2021 10:10
Show Gist options
  • Save marketcalls/a622480bcb87ddf6cb3cf1d576ab0668 to your computer and use it in GitHub Desktop.
Save marketcalls/a622480bcb87ddf6cb3cf1d576ab0668 to your computer and use it in GitHub Desktop.
ATM CE and ATM PE Caclulation - Amibroker AFL
//Coded by Paris Kamal - Python Data Analyst
//website - www.marketcals.in
//Version 1.0.0.0
//Coded Date : 9-Dec-2019
_SECTION_BEGIN("ATM CE and ATM PE Caclulation");
iInterval= Param("Strike Interval",50,1,5000,1);
//ATM Calculation using Static Variables
//iCE & iPE temporary variables
for (i=0;i<BarCount;i++)
{
latest_price = C[i];
iPE = latest_price-(latest_price%iInterval);
iCE = iPE;
if((latest_price%iInterval) > 0 ){
iCE = iPE+iInterval;
}
//ATM CE and ATM PE Symbol String formation
StaticVarSetText("CE"+i,StrFormat("%.0f",iCE)+"CE");
StaticVarSetText("PE"+i,StrFormat("%.0f",iPE)+"PE");
//For Debugging Purpose
//_TRACE("CE "+iCE+" PE "+iPE);
}
//CE and PE variables stores only the recent value or selected value from the static arrays
CE = StaticVargetText("CE"+BarIndex());
PE = StaticVargetText("PE"+BarIndex());
//Dasboard
GfxSelectFont( "BOOK ANTIQUA", 12, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor ( colorWhite );
GfxSelectSolidBrush( colorDarkGrey );
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
GfxSelectPen( colorLightBlue, 1); // border color
GfxRoundRect( x, y - 155, x2, y-30 , 7, 7 ) ;
GfxTextOut( "ATM Call " +CE,13,y-130);
GfxTextOut( "ATM Put " +PE,13,y-110);
GfxTextOut("LTP - "+close,13,y-90);
GfxTextOut("Strike Interval - "+iInterval,13,y-70);
_SECTION_END();
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment