help needed to code the system

bunti_k23

Well-Known Member
#1
hello guys,
iam thinking to make a mechanical system by improvising supertrend ,as we all know supertrend is a best indi.if there any coder available plz take my idea and make the system pm me iam also watsapp:thumb:
 

bunti_k23

Well-Known Member
#3
how to make the line stle thick in edit formula option
 

bunti_k23

Well-Known Member
#4
hello guys,hws u all .my system is ready and has been coded by purusharth. for that i give personal thanks to them , iam posting it for the purpose of testing and further development of the system ,so senior guys plz take a luk at it test it tell me the drawbacks to improvise it. i learnt so much from this forum and now i feel like to give it back whatever new thing i learn for all the newbie traders ,i ll always try to post gud and valuable stuff frm myside advance thanxx to all the senior guyzz who generously reply and give valuable suggestions.:)
this is wat i made :D

/* Done by amitkawale23


_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

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


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

PositionSize = 350000;

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor=Optimize("Factor",2,0.1,10,0.1);
Pd=Optimize("ATR Periods",5,1,20,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 <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;

trend=1;


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

}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}

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

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

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

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

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

Plot(TrendUp,"Trend",colorWhite);
Plot(TrendDown,"Down",colorWhite);


/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/

TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",0.6,5,10,2);
Pd1=Optimize("ATR Periods1",5,1,10,1);
Up1=(H+L)/2+(Factor1*ATR(Pd1));
Dn1=(H+L)/2-(Factor1*ATR(Pd1));
iATR1=ATR(Pd1);
TrendUp1=TrendDown1=Null;
trend1[0]=1;
changeOfTrend1=0;
flag1=flagh1=0;

for (i = 1; i <BarCount; i++) {
TrendUp1 = Null;
TrendDown1 = Null;

trend1=1;


if (Close>Up1[i-1]) {
trend1=1;
if (trend1[i-1] == -1) changeOfTrend1 = 1;

}
else if (Close<Dn1[i-1]) {
trend1=-1;
if (trend1[i-1] == 1) changeOfTrend1 = 1;
}
else if (trend1[i-1]==1) {
trend1=1;
changeOfTrend1 = 0;
}
else if (trend1[i-1]==-1) {
trend1=-1;
changeOfTrend1 = 0;
}

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

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

if (trend1>0 && Dn1<Dn1[i-1]){
Dn1=Dn1[i-1];
}

if (trend1<0 && Up1>Up1[i-1])
{ Up1=Up1[i-1];
}

if (flag1==1)
{ Up1=(H+L)/2+(Factor1*iATR1);;
}
if (flagh1==1)
{ Dn1=(H+L)/2-(Factor1*iATR1);;
}
if (trend1==1) {
TrendUp1=Dn1;
if (changeOfTrend1 == 1) {
TrendUp1[i-1] = TrendDown1[i-1];
changeOfTrend1 = 0;
}
}
else if (trend1==-1) {
TrendDown1=Up1;
if (changeOfTrend1 == 1) {
TrendDown1[i-1] = TrendUp1[i-1];
changeOfTrend1 = 0;
}
}
}

Plot(TrendUp1,"Trend",colorBlue);
Plot(TrendDown1,"Down",colorRed);


/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/

Buy = trend==1 AND trend1==1 ;
Short=trend==-1 AND trend1==-1;
Sell=trend1==-1;
Cover=trend1==1;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);



BuyPrice=ValueWhen(Buy,C);
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)+
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==1, shapeUpArrow , shapeNone), colorGreen, 0,Low, Offset=-20);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-20);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);


_SECTION_END();

/* Done by amitkawal23
 
Last edited:

bunti_k23

Well-Known Member
#5
here are the simple rules ,how to trade the system.:thumb:
1-above the white lines only buy signals will appear hence take buy trades and when asterisk(*) sign appears book the profits,vice versa for short side trades.

2-the system is fully mechanical hence buy sell signals and profit booking is clearly given but as we know every mechanical systems fails in certain situations so to eliminate this probablity use it with some discretion ,means just try to take the high probablity trades.

3-the main aim of this system is profit booking at successive levels as we know profitability depends upon where u book the profit ,so this system will never leave you wit dissapointments in aspect wit profit booking.

4-the white line is the default trend line ,and the fast line which appears near the price is trailling stoploss line.

5-in case u miss the entry either buy or sell u can take the trade when the asterisk appears means take the opposite trade .but this works only in few cases as this level is for profit booking only not for taking entries...

enjoy:clap::clap::clap:
 

dell

Well-Known Member
#6
amit , nice efforts by purusharth and good idea by u ....
but it needs further filteration , one cannot trade only taken this idea as there are many whips trades which deviate one from trading next trade or u may say it can shake ur confidence ,

in which script u r trading this idea and in which tf ?
on backtesting nothing is coming , is there any error in coding , plz chk .....
by discussion and testing we can arrive at some valid solution ....
 

bunti_k23

Well-Known Member
#7
amit , nice efforts by purusharth and good idea by u ....
but it needs further filteration , one cannot trade only taken this idea as there are many whips trades which deviate one from trading next trade or u may say it can shake ur confidence ,

in which script u r trading this idea and in which tf ?
on backtesting nothing is coming , is there any error in coding , plz chk .....
by discussion and testing we can arrive at some valid solution ....
yes bro backtesting is not happening on that i dont know why ,maybe there is sum error in coding,and yes this is the concept of my system there r sum flaws which i have to think of them ,you can also try to improvise it by your own idea ,i dont have intraday data so i have applied it on eod data only and on gud nifty scripts like axisbank icicibank ,dlf etc etc
 

aimer

Well-Known Member
#8
yes bro backtesting is not happening on that i dont know why ,maybe there is sum error in coding,and yes this is the concept of my system there r sum flaws which i have to think of them ,you can also try to improvise it by your own idea ,i dont have intraday data so i have applied it on eod data only and on gud nifty scripts like axisbank icicibank ,dlf etc etc
Backtest happening...just put */ after the name....
Also u can use ADX and or MACD with this supertrend...this will filter out most of the unwanted trades...just check...
I have limited knowledge abt coding otherwise would have put ADX and Supertrend together to decide the trades...
 

bunti_k23

Well-Known Member
#9
Can sumbody add adx filters to this and post here thank you
 

bunti_k23

Well-Known Member
#10
Backtest happening...just put */ after the name....
Also u can use ADX and or MACD with this supertrend...this will filter out most of the unwanted trades...just check...
I have limited knowledge abt coding otherwise would have put ADX and Supertrend together to decide the trades...
Bro plz tell specifically where shd i add the */ for backtesting
 

Similar threads