Rajandran R FollowFounder 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.

Zero Lag EMA 15min Strategy for Nifty and Bank Nifty

1 min read

Today we are going to discuss about Zero Lag EMA 15min strategy for Nifty and Bank Nifty and how effective it is in terms of generating returns and smoothing your equity curve. Almost all smoothing filters and moving averages have lag because smoothing is done using past data.

Zero Lag is a new concept in adaptive technical analysis. Here in Zero lag EMA we show you the effects of lag removal in a indicator and then how to use the filter in a very effective way. The picture shows the simple ZeroLag EMA strategy over the 15min Nifty Charts. The thick yellow line is nothing but the Zero lag EMA and the red line is the normal EMA.Since minimization of lag is crucial to the effectiveness of indicators,several authors have devised ways to make the EMA smoothing factor vary with volatility in price.

httpv://www.youtube.com/watch?v=A5lWR0PhG3c

The first relationship between the lag of an EMA and the length of a Simple Moving Average (SMA) is

alpha = 2/(Length+1)

We call the new filter EC (for Error Correcting) i.e Zero Lag EMA instead of EMA. So the equation for the EC filter is:

The equation is simple, but its results are profound. If the gain is zero, the EC becomes just an EMA. If the gain is sufficiently large the error term causes EC to exactly track the price for all practical purposes. That is, there is virtually no lag and virtually no smoothing. Therefore, we seek a value of gain that is a happy medium between tracing out the price and tracing out the EMA. We do this by limiting the maximum amount of allowable gain. If the difference between the price and the previous value of EC is small we do not want a large value of gain. Further, the previous value of EC can be either greater than or less than the current price. Therefore, to properly apply the error correction the gain must swing both positive and negative.

Rajandran R FollowFounder 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.

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...

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

44 Replies to “Zero Lag EMA 15min Strategy for Nifty and Bank…”

Hi
Rajan,
Thankyou for putting up this brilliant formula.
I have tried to copy the file into the formula folder but for some reason its not working on my amibroker.

Thanks in advance.

What error you are getting? Make sure that you are using 5.7 and the code is not compatible with versions less than 5.5 i guess.

Sir, AFL code showing error !

Which version of amibroker you are using i tested in Amibroker 5.7 and it works fine. Make sure that you are using 5.7.
Yes verfied their data is Tick by Tick

Option Symbol Format e.g NIFTYCE6200.0030-01-2014
0030-01-2014 – represents the options expiry date.

Im using 5.7….the errors are in lines 45,47,53,54,55,57,61 & 62… pls help

I am using AmiBroker 5.7 version.
I am getting number of errors in lines
Ln 45,47,53,54,55,57,61,62, about variables missing , syntax errors .I have already sent the screenshots of the errors on rajandran@marketcalls.in.

Please advise and help.

Hi Rajandran,

I recently started trading, went though these, i downloaded your backtested result, and added 10pt stop loss to each trade, results are too good to be true, can you verify the same, kindly share ur mail id, so that i can send the file.

Regards
Deepak

Sure deepak will definitely look into it and thanks for your input.

I tried this AFL this morning and I’m getting errors. I use Ami 5.7

Ln 45, Col, 10, Error 31 == ” Error = abs( Close[ bar ] – EC ); ”
Ln 47, Col 14, Error 31 == “if( Error < LeastError ) "
Then, on this line == "iEC[ bar ] = BestEC; " and " iLeastError[ bar ] = LeastError; "
And on this == "Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick ); "

Can you check these errors and upload the corrected AFL ?

Thank you.
G

Few of them are facing such issues will test again will try to post the modified AFL.

_SECTION_BEGIN(“Zero-Lag EMA Indicator for AmiBroker “);
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor(“bkcolor”,ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor(“Candle UP Color”, colorGreen),IIf(CO,ParamColor(“Wick UP Color”, colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);
Length = Param("Length", 69, 20, 100,1 );
GainLimit = Param("Gain limit", 22, 1, 100);

I am Aryan from tradecatcher.blogspot.in .
I find your website really very useful for the
trading community. Full credit for your hardwork.

I wish you all the best for your endeavors in life.

Regards.

Thanks Aryan

hello sir can you make a comparison of annually returns if i deposit 10000 in a bank…or follow this zero lag strategy…which will give me more returns..?

hello sir can you tell me how to increase number of shares for back testing your afl…?
thanks in advance

Hi Rajandran,

Can you tell me the best brokers to start with trading F&O. I have been using Scottrade and optionsxpress. I am new to trading the NSE/BSE

Thanks
Deepak

You can try with discount brokers like zerodha, tradejini, compositedge

hello Rajendran sir,
I am following your strategies and afl, indeed your work is very beneficial to many like me.
Here I am also finding error with this afl, zero lag ema, can you please guide me on same.
Looking forward for your guidance.

Thank you sir.

I am also have errors on these mentioned lines
Ln 45, Col, 10, Error 31 == ” Error = abs( Close[ bar ] – EC ); ”
Ln 47, Col 14, Error 31 == “if( Error < LeastError ) "
Then, on this line == "iEC[ bar ] = BestEC; " and " iLeastError[ bar ] = LeastError; "
And on this == "Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick ); "

Could you please check. Thanks for your effort.

Hi, Rajandran R I am Also Using Ami 5.7 and getting Error and mjust Say a Great Work Done By you In Sort of This website

Hello Rajandran sir,
Thanks for the afl code but i am too getting error.
It says iec not initialized.

Can I get it for spider or Market view?

You need to custom code it in Spider.

Hi, thank you for this information.. I’ll try to do this in NSDT.

Regards,
Claudio

What does NSDT means?

NSDT = Neuroshell Day Trader … you can create .dll in powerbasic or c++

can zero lag EMA strategy be used for futures. where ca i subscrble the 5 min chart you show free for nift,bank nifty,futures. I want a subscription for 5 10 15 30 i hour qnd i day chart

Thanks for sharing the information.
– What other means of self corrections are being utilized by other authors.
– At what point do we reach a stage where the system is curve fitted and becomes unsuable over longer period of times.

Just curious , have you tried it longer than 4 year time frame.

My Way of understanding curve fitting is

1)If you are using more than 3+ input parameters for Optimization
2)If you data sample size is very less and you are doing optimization with the limited dataset

And I hope iam not doing both.

Thanks for the quick reply,

Do you have any information on what other correction factors used by system developers? ( i am still trying to figure out how you arrived at the ‘alpha’ factor formula)

&

In your back testing settings you have used the lot size is 1, do you have specified in your symbol description in AMI for the lot size to be 50shares for Nifty? Have you tried with minimum tick at 0.05?

Hi Sir,

Please help, I am getting errors on below Lines
Ln:45
Ln:47
Ln:53
Ln:54
Ln:55
Ln:57
Ln:61
Ln:62

Please help to provide me AFL, I have ambibroker 5.7
Thanks in advance

Hi Make sure you have enough backfill in your database otherwise Amibroker will throw errors.

HI I think Error is because you have used ‘ Error’ which is a keyword . replace it with some other , it works

Hi Rajendran,
Thanks a lot (ton!!) for so much of free content that you have posted.
Most of your AFL codes has got back testing results also in AFL. For those who do not have Amibroker, it is not possible to see those results. It will be helpful, if you post those results in excel.
Thanks
Vijay

I am also getting error From line no 45 , 47 , 53 , 54

I am using Amibroker 5.7

Is this same code ZLEMA ?

I want for intraday and mostly all our alfs are positional and we are trying in intraday hence asking to put in parameters if we sqf in traday whats the result……

Thanks and once again than for wonderful knowledge base website and platform created and helpful to us.

Thanks

Viral.

SIR INTERESTED IN ZERO LAG INDICATOR PLZ HELP

sir plz help zero lag indicator

Hey Rajendran

I have just started to learn amibroker and kind of comfortable with writing code and baktesting. I took your AFL ( modified it with ERROR to iERROR) and now i have a error free code But when i try to test this on 2017-2018 data i get no results. I have the NIFTY 2017-2018 data which i imported in CSV format and has 1 minute data.

I mean to say that nothing comes back at all and its a blank screen. ( and no error on analysis window )

Any settings that i need to do either on testing window setting? or database setting?
Appreciate your help !

Hi

Rajan,

Thankyou for putting up this brilliant formula.

I have tried to copy the file into the formula folder but for some reason its not working on my amibroker.

Thanks in advance.

What error you are getting? Make sure that you are using 5.7 and the code is not compatible with versions less than 5.5 i guess.

Sir, AFL code showing error !

Which version of amibroker you are using i tested in Amibroker 5.7 and it works fine. Make sure that you are using 5.7.

Yes verfied their data is Tick by Tick

Option Symbol Format e.g

NIFTYCE6200.0030-01-20140030-01-2014 – represents the options expiry date.

Im using 5.7….the errors are in lines 45,47,53,54,55,57,61 & 62… pls help

can you send me the screenshot to rajandran@marketcalls.in

good system with potential of positive result.

Sir

I am using AmiBroker 5.7 version.

I am getting number of errors in lines

Ln 45,47,53,54,55,57,61,62, about variables missing , syntax errors .I have already sent the screenshots of the errors on rajandran@marketcalls.in.

Please advise and help.

Hi Rajandran,

I recently started trading, went though these, i downloaded your backtested result, and added 10pt stop loss to each trade, results are too good to be true, can you verify the same, kindly share ur mail id, so that i can send the file.

Regards

Deepak

Sure deepak will definitely look into it and thanks for your input.

I tried this AFL this morning and I’m getting errors. I use Ami 5.7

Ln 45, Col, 10, Error 31 == ” Error = abs( Close[ bar ] – EC ); ”

Ln 47, Col 14, Error 31 == “if( Error < LeastError ) "

Then, on this line == "iEC[ bar ] = BestEC; " and " iLeastError[ bar ] = LeastError; "

And on this == "Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick ); "

Can you check these errors and upload the corrected AFL ?

Thank you.

G

Few of them are facing such issues will test again will try to post the modified AFL.

_SECTION_BEGIN(“Zero-Lag EMA Indicator for AmiBroker “);

SetBarsRequired(100000,0);

GraphXSpace = 15;

SetChartOptions(0,chartShowArrows|chartShowDates);

SetChartBkColor(ParamColor(“bkcolor”,ColorRGB(0,0, 0)));

GfxSetBkMode(0);

GfxSetOverlayMode(1);

SetBarFillColor(IIf(C>O,ParamColor(“Candle UP Color”, colorGreen),IIf(CO,ParamColor(“Wick UP Color”, colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

Length = Param("Length", 69, 20, 100,1 );

GainLimit = Param("Gain limit", 22, 1, 100);

SetPositionSize(2,spsShares);

alpha = 2 / ( Length + 1 );

iEMA = AMA( Close, alpha );

EC = Close[ 0 ];

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

{

EC1 = EC;

LeastError = 1e9;

BestEC = 0;

for( gain = -0.1 * GainLimit; gain < 0.1 * GainLimit; gain += 0.1 )

{

EC = alpha * ( iEMA[ bar ] + gain * ( Close[ bar ] – EC1 ) ) +

( 1 – alpha ) * EC1;

iError = abs( Close[ bar ] – EC );

if( iError < LeastError )

{

LeastError = iError;

BestEC = EC;

}

}

iEC[ bar ] = BestEC;

iLeastError[ bar ] = LeastError;

}

Plot( iEMA, "EMA", colorRed );

Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick );

Plot( C, "Close", ParamColor("Color", colorGreen ), ParamStyle("Style") | GetPriceStyle() );

// strategy rules

Buy = Cross( iEC, iEMA );

Sell = Cross( iEMA, iEC );

Buy=ExRem(Buy,Sell);

Sell=ExRem(Sell,Buy);

Short=Sell;

Cover=Buy;

BuyPrice=ValueWhen(Buy,C);

SellPrice=ValueWhen(Sell,C);

ShortPrice=ValueWhen(Short,C);

CoverPrice=ValueWhen(Cover,C);

Title = EncodeColor(colorWhite)+ "ZL EMA code from http://www.marketcalls.in" + " – " + Name() + " – " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +

" – " + Date() +" – "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+

"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+

EncodeColor(colorLime)+

WriteIf (Buy , " GO LONG / Reverse sig at "+C+" ","")+

WriteIf (Sell , " EXIT LONG / Reverse sig at "+C+" ","")+"\n"+EncodeColor(colorYellow)+

WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+

WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);

PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

very usefull site thanks

Hi Rajandran,

I am Aryan from tradecatcher.blogspot.in .

I find your website really very useful for the

trading community. Full credit for your hardwork.

I wish you all the best for your endeavors in life.

Regards.

Thanks Aryan

hello sir can you make a comparison of annually returns if i deposit 10000 in a bank…or follow this zero lag strategy…which will give me more returns..?

hello sir can you tell me how to increase number of shares for back testing your afl…?

thanks in advance

Hi Rajandran,

Can you tell me the best brokers to start with trading F&O. I have been using Scottrade and optionsxpress. I am new to trading the NSE/BSE

Thanks

Deepak

You can try with discount brokers like zerodha, tradejini, compositedge

hello Rajendran sir,

I am following your strategies and afl, indeed your work is very beneficial to many like me.

Here I am also finding error with this afl, zero lag ema, can you please guide me on same.

Looking forward for your guidance.

Thank you sir.

I am also have errors on these mentioned lines

Ln 45, Col, 10, Error 31 == ” Error = abs( Close[ bar ] – EC ); ”

Ln 47, Col 14, Error 31 == “if( Error < LeastError ) "

Then, on this line == "iEC[ bar ] = BestEC; " and " iLeastError[ bar ] = LeastError; "

And on this == "Plot( iEC, "EC" + _PARAM_VALUES(), colorYellow, styleThick ); "

Could you please check. Thanks for your effort.

Hi, Rajandran R I am Also Using Ami 5.7 and getting Error and mjust Say a Great Work Done By you In Sort of This website

Hello Rajandran sir,

Thanks for the afl code but i am too getting error.

It says iec not initialized.

Can I get it for spider or Market view?

You need to custom code it in Spider.

Hi, thank you for this information.. I’ll try to do this in NSDT.

Regards,

Claudio

What does NSDT means?

NSDT = Neuroshell Day Trader … you can create .dll in powerbasic or c++

can zero lag EMA strategy be used for futures. where ca i subscrble the 5 min chart you show free for nift,bank nifty,futures. I want a subscription for 5 10 15 30 i hour qnd i day chart

Thanks for sharing the information.

– What other means of self corrections are being utilized by other authors.

– At what point do we reach a stage where the system is curve fitted and becomes unsuable over longer period of times.

Just curious , have you tried it longer than 4 year time frame.

My Way of understanding curve fitting is

1)If you are using more than 3+ input parameters for Optimization

2)If you data sample size is very less and you are doing optimization with the limited dataset

And I hope iam not doing both.

Thanks for the quick reply,

Do you have any information on what other correction factors used by system developers? ( i am still trying to figure out how you arrived at the ‘alpha’ factor formula)

&

In your back testing settings you have used the lot size is 1, do you have specified in your symbol description in AMI for the lot size to be 50shares for Nifty? Have you tried with minimum tick at 0.05?

Hi Sir,

Please help, I am getting errors on below Lines

Ln:45

Ln:47

Ln:53

Ln:54

Ln:55

Ln:57

Ln:61

Ln:62

Please help to provide me AFL, I have ambibroker 5.7

Thanks in advance

Hi Make sure you have enough backfill in your database otherwise Amibroker will throw errors.

HI I think Error is because you have used ‘ Error’ which is a keyword . replace it with some other , it works

Hi Rajendran,

Thanks a lot (ton!!) for so much of free content that you have posted.

Most of your AFL codes has got back testing results also in AFL. For those who do not have Amibroker, it is not possible to see those results. It will be helpful, if you post those results in excel.

Thanks

Vijay

You are welcome. Also try out our new NSE FNO web charting tool quite interactive though.

Dear Rajendra,

I am also getting error From line no 45 , 47 , 53 , 54

I am using Amibroker 5.7

Is this same code ZLEMA ?

I want for intraday and mostly all our alfs are positional and we are trying in intraday hence asking to put in parameters if we sqf in traday whats the result……

Can you atleast correct code and send me email also dalalviral@yahoo.com

Thanks and once again than for wonderful knowledge base website and platform created and helpful to us.

Thanks

Viral.

SIR INTERESTED IN ZERO LAG INDICATOR PLZ HELP

sir plz help zero lag indicator

Hey Rajendran

I have just started to learn amibroker and kind of comfortable with writing code and baktesting. I took your AFL ( modified it with ERROR to iERROR) and now i have a error free code But when i try to test this on 2017-2018 data i get no results. I have the NIFTY 2017-2018 data which i imported in CSV format and has 1 minute data.

I mean to say that nothing comes back at all and its a blank screen. ( and no error on analysis window )

Any settings that i need to do either on testing window setting? or database setting?

Appreciate your help !

HI Mr Rajendra,

This Code is not yet working.