How to run chart based trade on ATM Strikes?

I am using the below codes to calculate ATM CE/PE. Now I want to run a simple crossover strategy on charts of ATM CE/PE. I have to apply the above strategy on the chart of Nifty Option.
I have to trade in options only. I will explain my requirement with an example.
Suppose at 9.15am Nifty is trading at 15000. So ATM CE/PE at that moment would be 15000CE and 15000PE. Now I want my above defined Buy and Sell to be run on charts of both 15000CE and 15000PE. Suppose, at 9.30am nifty is at 15020 and on the chart of 15000CE Buy = Cross(ema1,ema2) happens. I entered this trade here at 9.30am. As long as my trade is running on 15000CE I don't want any other entry nor I want to look for an entry neither interested in calculating ATM strikes of Nifty. Further at 10.00am Nifty is at 15060 and on the chart of 15000CE Sell = Cross(ema2,ema1) takes place.
So my trade on 15000CE will exit. The moment I exit my trade I again want to check ATM CE/PE. So at 10.00am since nifty is at 15060 so ATM CE/PE would be 15050CE and 15050PE . Now I want to run the same above-mentioned condition on charts of 15050CE and 15050PE . Suppose at 10.15am Nifty comes around 15030 and Buy = Cross(ema1,ema2) happens in 15050PE so will enter the trade here and again since I entered the trade do not want to look for other trade or calculate ATM CE/PE till the running trade exit. Need to repeat the same once trade exit. Any clue or code would be helpful. Thanks

_SECTION_BEGIN("ATM CE and ATM PE Caclulation");
spot = ParamStr("Spot Symbol","NIFTY");
expiry = ParamStr("Expiry Date","29APR21");
iInterval= Param("Strike Interval",50,1,5000,1);

for (i=0; i < BarCount; i++)

ltp = C[i];
if(ltp%iInterval > iInterval/2)
iCE = ltp - (ltp%iInterval) + iInterval;
iPE = iCE;


if(ltp%iInterval < iInterval/2)
iCE = ltp - (ltp%iInterval) ;
iPE = iCE;



//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());


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 ) ; 

symCE = spot+expiry+CE;
symPE = spot+expiry+PE;

GfxTextOut( "ATM Call : " +symCE,13,y-130);
GfxTextOut( "ATM Put : " +symPE,13,y-110);
GfxTextOut("LTP - "+close,13,y-90);
GfxTextOut("Strike Interval - "+iInterval,13,y-70);


1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.