dear bait plz test this apply it on 3m and 5m tf test on both and try to vary the parameters (factor of both line) there are two supertrend lines one is with higher factor param and another is lower factor param there are buy ,sell and cover signals any help with the system pm me,
_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
HaClose = (O + H + L + C)/4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
xDiff = (HaHigh - Halow) * 10000;
barcolor = IIf(HaClose >= HaOpen,colorBrightGreen,colorRed);
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "", barcolor, styleCandle );
_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",4,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",colorBlue);
Plot(TrendDown,"Down",colorRed);
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
TrendMode = ParamToggle("TrendMode","Off|On",1);
Factor1=Optimize("Factor1",1.5,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",colorWhite);
Plot(TrendDown1,"Down",colorWhite);
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
/*========================================================================================================================================================================*/
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=-40);
PlotShapes(IIf(Sell==1, shapeStar, shapeNone), colorRed, 0,High, Offset=30);
PlotShapes(IIf(Short==1, shapeDownArrow, shapeNone), colorRed, 0,High, Offset=-40);
PlotShapes(IIf(Cover==1, shapeStar, shapeNone), colorGreen, 0,Low, Offset=-30);
_SECTION_END();