_SECTION_BEGIN("SuperTrend");
myTF = in1Minute*Param("Time Frame Minutes",60,30,60*60*24,15);
TimeFrameSet(myTF);
Factor=Param("Factor",4,1,10,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 <BarCount-1; i++) {
TrendUp[i] = Null;
TrendDown[i] = Null;
trend[i]=1;
if (Close[i]>Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}
else if (Close[i]<Dn[i-1]) {
trend[i]=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}
if (trend[i]<0 && trend[i-1]>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]<Dn[i-1]){
Dn[i]=Dn[i-1];
}
if (trend[i]<0 && Up[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;
}
}
}
UP = trend==1;
DN = trend==-1;
TimeFrameRestore();
HTF_UP = TimeFrameExpand(UP,myTF);
GfxSetBkMode(0);
GfxSetOverlayMode(1);
x=Param("X",20,0,1500,10);
y=Param("Y",20,0,1000,10);
GfxSelectFont( "Arial", 15, 700, False );
GfxSetTextColor( colorWhite);
if (SelectedValue(HTF_UP))
{
GfxSelectSolidBrush( colorBlue );
GfxRoundRect( x, y, x+270, y+80,0,0);
GfxTextOut( ( "Supertrend on "+ myTF/60 +" Minutes"),x+5,y+5);
GfxTextOut( "THE TREND IS UP", x+35, y+45);
}
else
{
GfxSelectSolidBrush( colorRed );
GfxRoundRect( x, y, x+270, y+80 , 7, 7 ) ;
GfxTextOut( ( "Supertrend on "+ myTF/60 +" Minutes"),x+5,y+5);
GfxTextOut( "THE TREND IS DOWN", x+25, y+45);
}
_SECTION_END();