# Non Repainting Super Trend Indicator with Time Bar Left AFL code

This is a new implementation of the SuperTrend indicator for Metatrader 4. The SuperTrend indicator is an application of the concept of MAE (maximum adverse excursion), which was introduced by John Sweeney in the mid-nineties.

The Non Repainting SuperTrend is particularly stable and has a few advantages over older version of SuperTrend indicators:

-It uses a moving (statistical) median of the arithmetic mean (High + Low)/2 of the bars instead of a moving average. The (statistical) median is known to be more robust than any average.

-It calculates both the Median and the ATR (average true range) 1 bar ago, whereas the original SuperTrend indicator takes the ATR and moving average of the current bar. If you use the current bar’s ATR, the current bar’s breakout is partly measured against its own range. This is particularly true, if the ATR period is short.

– Signals: The Non Repaiting SuperTrend indicator gives a reversal signal, when the bar closes on the other side of the stop line.

– Magnified Market Price added for instant check of current market price

– Time Bar Left code is added to the AFL code( No of seconds left for the new bar to begin)

Now Download Non Repainting Super Trend Indicator with the new feature seconds left for the new bar to begin.

I would like each and everyone to go thro the nature of SuperTrend Optimized trading system

– To be honest the trading system accuracy is currently at 42% means out of 100 trades only 42 trades are profitable.

Then how does your wealth is created?
It created with discipline and proper money management to catch those 42% of Winning Trades and Exiting properly at Stop Loss Hits.

What is the maximum continuous losses the trading system can yield?
Since 2010 after backtesting with 5min data it is inferred that till to date 9 consecutive losses had occurred. Refer with Bactest results.

What is the Best Parameters to fine tune the system to eliminate more whipsaws?
Optimized Parameters are Multiplier =2 and ATR=11. However the default values of trading system are Multiplier =3 and ATR=10.

For Which Instrument the Trading System is Optimized?
The Trading system is optimized for 5min Nifty Futures charts

Can i trade with Any other stocks/indices?
Strictly No. As the Trading system is optimized for 5min Nifty future charts only.

How to Enter and Exit?

Entry should be based on the completion of the close of 5min Bar Candle. Trade should be executed with 5secs once the 5min candle complete. Trade should not be executed before the completion of 5min bars.

Trade Should be taken only if you see the next bar open. And Strictly not at the intermediate points between the signals.

How many Nifty Future Lots is required to Trade the Trading system?
2 Lots (100 shares) of Nifty at any trades. Size of the trade should not vary throughout the trading system and it is fixed.

Charts shown in marketcalls is to study the nature of the trading system to improve your knowledge on trading system. If you are trading based on these buy and sell signals then do it at your own risk. marketcalls wont be responsible for the losses incurred.

```/* Done      by    Rajandran R */
/* Author of www.marketcalls.in  */

_SECTION_BEGIN("SuperTrend");
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(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close[i]0) {
flag=1;
}
else {
flag=0;
}

if (trend[i]>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend[i]>0 && Dn[i]Up[i-1])
{ Up[i]=Up[i-1];
}

if (flag==1)
{  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
}
if (flagh==1)
{ Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
}
if (trend[i]==1) {
TrendUp[i]=Dn[i];
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDown[i]=Up[i];
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

Plot(TrendUp,"Trend",colorGreen);
Plot(TrendDown,"Down",colorRed);

Sell=trend==-1;

Short=Sell;

SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);

Title = EncodeColor(colorWhite)+ "Super Trend AFL code from 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 Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"n"+EncodeColor(colorYellow)+

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
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);

TrendSL=IIf(trend==1,TrendUp,TrendDown);

for(i=BarCount-1;i>1;i--)
{
{
entry = C[i];
sl = TrendSL[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);

bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = C[i];
sl = TrendSL[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);

bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorLime, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

//Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorDarkRed, styleLine|styleLine, Null, Null, Offset);
//Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorGreen, styleLine|styleLine, Null, Null, Offset);

/*
for (i=bars; i
Backtest Results
Super Trend Optimized Backtest Results from 1st Jan 2010 - 25th March 2012
Download Non Repainting Super Trend Indicator with time bar left AFL code

```

## [Free Course] Mini Certification on Amibroker AFL Programming

Interested in getting to know the basics of Amibroker AFL Programming then here is a free live training course to access hands-on training on...

This Algomojo Button trading module provides 4 modes of the button to place orders with a single click directly from Amibroker using simple smart...

## AlphaTrend – Amibroker AFL Code to Manage Sideways Markets

Very simple and interesting trend following strategy which could manage sideways markets to a greater extent while following the trend. Recently I got inspired...

## 66 Replies to “Non Repainting Super Trend Indicator with Time Bar Left…”

1. meena says:

Rajandran sir,
In your earlier post under ‘Optimised ST post ‘ , you mentioned accuracy to be 42%.

But i feel with introduction of Non-repaint feature, accuracy and/or profit percentage is bound to inrease.

Will u please share stats with non-repaint feature.If u mention in words with approx figures, it will also suffice instaed of Amibroker’s analysis.

thanks

1. @Meena : Even i case of non repainting indicator the accuracy is going to remain the same because to older version also takes decision based on the close of the bar. May be the Month of may is much trendier which gives a higher winning ratio and the sample size is very low when compared to a 3 year of backtesting period

2. Devansh says:

Hi , The Part about entry and exit based on these signals is clear, but what is not clear to me is, is this a Positional System , Intraday System is there a fixed Stop Loss and a Fixed Target price any clarity would help ?

1. @Devansh.
Currently it is just a buy when buy signal and sell when sell signal kind of trading system. So the risk are always carry forwarded for the next day. Iam trying to come up with a system which reduces carry forwarding risk.

1. Harjot singh says:

Sir,

I am new follower and with in a weektime study i have become your fan. Sir You have mentioned that you are working to come up with a system which reduces carry forwarding risk can you inform if that is out now.

God Bless,

Regards,
Harjot

3. Mitch says:

Hi Rajandara,

Any such indicator for GCI MT4 instead of amibroker.

Thanks

Mitch

4. Mangta Sidhu says:

Sir ji if it is available forGCI MT 4 please …

5. satheesh mukundan says:

dear raj
If the entry rule is like entering on the break of the high/low of the signal candle several flop chances can be
avoided. pl excuse me if am wrong
for eg. on 18-5-2012 two such cases are there

6. ghost says:

I tried your afl to load in Amibroker 5.2 version, but it is showing lot of errors, can you help to sort it out.
it shows variable”entry” used being initialised, too many arguments etc, nearly 35 errors in total, why is it so?
regards

7. D Chowdhury says:

Would like to know whether the AFL is applicable for both Nifty Future and Bank Nifty Future? If not, please share the respective AFLs. Thank you in advance

8. Ravi says:

Good Day
Dear Rajandran
Thanks a million for sharing this wonderful AFL
Further Is it possible to identify and include sideways market condition in your.AFL.
This will make your AFL supreme.
Thx again and Best Wishes
Ravi

9. Naga says:

Hello Rajandran, nice work…..but i am using Metatrader platform……is that possible for you to post your Indicator in Mt4 format.

10. MOIN says:

hi kindly place old version too.

11. Dexter says:

Hi Rajandran,

If it is not too much to ask, can you help me in initial parameters for ATR and Multiplier that could be useful for EOD.

12. Narasimhan.S.Pai says:

Since 2 to 3 days I am not able to see the NIFTY & BANK NIFTY live charts. Whether it is under modification. I used to trade depending on that signals. Will you please guide me.

1. Currently Live Signals doesnt Supports < Internet Explorer Browser. Its better to use Mozilla Firexfox, Chrome, Opera, Safari (Mobile&Desktop) , Android Browsers

13. Stock Jock says:

Rajandran,

I loaded your indicator into AmiBroker, compiled it before saving it and I get a lot of errors.

14. noumann says:

Hi Rajandran,
i would like to use your non repainting supertrend indicator but i use Metastock.Is there a way to translate it into MS language?

15. man says:

does u have this indicator for metatrader also( super trend as show in figure above withlevels )

16. man says:

dear sirm

does u have this indicator for metatrader also( super trend as show in figure above withlevels )

17. vjay says:

Dear rajendar,
Thanks for sharing your supertrend indicator with us free…..can you please share multi trend box which appear in same afl?

18. boopalan says:

Dear sir,

how to use Non Repainting Super Trend Indicator with Time Bar Left AFL code

19. Terry Tosan says:

Why you are not responding to people who are asking for mt4 version of this indicator, simply let them know whether you have it or not?

20. Terry Tosan says:

21. suraj says:

Hi RAjandran bro,,,,

Not working your latest supertrend indicator for amibroker , number of times triend, pls check it and tell me step step instruction so if anything mistake , will try to correct and like to use this indicator with box indication..

Thanks
Srj

22. SANJAY AGARWALLA says:

dear rajendran its sanjay here i m purely new for marketcalls, 2 weeks i will observer ur calls then i will think to enter into this commodity trade
hope ur software works for me
sanjay

23. kaps says:

i tried to add Non Repainting Super Trend Indicator charts but its not working…help me

24. OSK says:

Dear Mr. Rajendran,

Recently I visited AB on yahoogroup and read few messages. Few messages about getting Email alerts when a BUY/SELL signal is generated attracted my attention. But when went through all those messages, really could not get conclusive answer.

Since we all know you are a genius, can you please shed some light on how one can get email alerts whenever signal is generated?

Regards,
OSK

25. Subbugentleman says:

Hi Rajendar,
Thanks for sharing this AFL. I appreciate your effort on clarifying our questions.

Could you clarify these questions:
1) There are “3142” trades generated in the back test results you have attached. Have you included commission and slippage. As this could impact the trade results, could you let me know on what value you are choosing for this.
2) As the signals are generated in 5 minutes charts, gap up and gap down against our position could erode the profit. If I understood your AFL correctly, it looks like you are carrying over positions to the next day. Will it be possible for you to modify the AFL to close the position at the end of the day.

Regards,
Subbugentleman

26. Kannan says:

Is targets are chosen arbitrary? what is the logic behind choosing the targets with 0.5%; 0.92% and 1.79% from the entry?

27. Ananthanankrish says:

non repainting super trend, I tried but no box of time left and traijing stop?

1. AnanthaKrish,

Goto tools->Preferences->Axis uncheck all the options and save it that will do

28. chandrashekar says:

Great master piece of Tec art Demostration from Rajan ,very much appricateable and its boom to inverstors

29. Kannan says:

Do you have matlab code for this non repainting super trend indicator?

1. No I dont have matlab code for non repainting supertrend.

30. OSK says:

We can see 3 message boxes for 5 mins, 15 mins & hourly charts. But same is not available for download. I would like to use 3 message boxes with 5 mins, 15 mins & 30 mins charts. Can you please make this AFL available for download?

31. kannan says:

Hi Raj, i tried super trend for nifty 60min yearwise and observed that it is highly sensitive to volatility. For example, the cumulative return in 2012 was good, but in 2013 the returns were pathetic (even negative); this is because 2012 was less volatile and 2013 was more volatile and hence the parameters 3,10 or 2,11 or any other combination always changes as per the volatility of the underlying and it is difficult to predict volatility and change parameters at the start of the year. I believe the same holds true for gold as well. How can I address this issue?

32. Jiten says:

Hi,
I used this afl and modified to write signal in file.
But signals are getting repeated every time.
Please suggest a way to avoid writing same signal again in file.
I want to write each signal one time in file.
How can i get this thing???

1. you can write to file with actionscan funtionality. So that whenever you do scan the buy or sell signals will be written to the file.

1. Jiten says:

I got solution by handling repeating bars…
1 thing is only remaining that how to write Bar closing time value along with signal???
I tried other function but that are writing Current time or Time where my mouse pointer is, not exact close time pf that particular bar….
Please suggest if any way or function to get Bar close time….

33. pranav says:

sir ur nifty live chart is on spot nifty or FUTURE NIFTY PLZ TELL ?

1. pranav says:

sir tell me the value of supertrend for
5 min chart
15 min chart
hourly chart

1. Currently we are using Factor=3 and Atr=7

1. pranav says:

for all time frame

2. pranav says:

what for hourly chart

34. Dharmesh Pandya says:

hi sir,
pls tell me how to put RIBBIN like Green or Red on Super Trend

35. krishna says:

sir alot of ths to u, abv charts r usefull to me , but u r delete stochastic charts. ple mentioned it . its to usefull to me

36. Ankita Stallion says:

Hi,

I tried this AFL. Looksgood.
But, when i tried with Multiple Sheets/Tabs, The POP alert works only on Active TAB.
May i know how to get alert from Inactive Sheets/TABs?

Regards
Ankita Stallion

1. Ankita Stallion says:

Hi,
is there anyway to achieve this?
Regards,
Ankita Stallion

rajandran R sir, pls tell me how can idownload supertrend afl code for amibroker 5.60 and install in amibroker.

38. chirag says:

sir i done as above but shows that not enoughbar for nifty pl advice

1. Make Sure the timeframe you are using contains atleast 300-400 bars so that the indicator works good!

39. dharmesh pandya says:

hi sir,
pls tell me how to put RIBBIN like Green or Red on non repainting super trend indicator with time bar left.
so pls help sir…

40. Nehal Suthar says:

i just tried to load this on my amibroker and i’m getting lots of errors. I use Amibroker 5.60 version. Please help. Thanks!

1. Hi,

Make sure you had enough data in your charts. The code is tested and worked fine for most of the people.

41. Cygi says:

I have the same problem that Nehal Suthar

42. mark says:

Hi …R
This doesnt seem to work for me…i get error 30…syntax error….unexpected identifier….

cheers

1. Make sure you are using Amibroker 5.5 above and having enough backfill data. Alleast 6 month of EOD data or 1 month of intraday data

43. ramana says:

can u please post last 5 to 8 ( profit / loss) trades in this afl please , its a going to be a good help

44. Amit Nanda says:

How have you considered contract expiry days for Nifty Futures? Do you rollover to the next contract?

45. saran says:

hi sir after drag and drop the file it shows that the link in not properly getting …like that ..and it is not getting by email and etc..i tried by the tool settings also..so if u can kindly send me that supertrend indicator link through my email..thanks in asvance

46. Nathulal D says:

Hello Sir,

In your supertrend indicators, is it possible to also draw the number of points each signal has made whether profit or loss. THis way it becomes easy to quickly glance the performance of the indicator directly on the chart without working out too much to capture data for backtesting. similar to https://www.mql5.com/en/forum/182267

1. Thanks for the suggestion looks interesting will try out!