Hi Pratap, Happy Singh and other experienced members
I am trying to create MTF Super Trend as mentioned in previous threads. I was able to get the trend line from HTF to LTF as mentioned by happy Singh (i.e. from 30 min to 10 min).
I want the cancle color for the following condition.
In 10 min chart -
candle color Blue when C > Trend Line based on HTF i.e. 30 min
candle color Red when C < Trend Line based on HTF i.e. 30 min
Also how can I get Buy and Sell arrow for above mentioned condition?
Following is the code I have.
_SECTION_BEGIN("SuperTrend");
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
= 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;
}
}
}
UP = trend==1;
DN = trend==-1;
kol=IIf(UP,colorBlue,colorRed);
Plot( C, "Close", kol, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
//////////////////////////////////////////////
myTF = in1Minute*Param("Time Frame Minutes",30,15,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 = 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;
}
}
}
UP = trend==1;
DN = trend==-1;
TimeFrameRestore();
HTF_UP = TimeFrameExpand(UP,myTF);
HTF_DN = TimeFrameExpand(DN,myTF);
HTF_TU = TimeFrameExpand(TrendUp,myTF);
HTF_TD = TimeFrameExpand(TrendDown,myTF);
Plot(TimeFrameExpand(TrendDown,myTF),"",colorRed,styleThick|styleNoRescale);
Plot(TimeFrameExpand(TrendUp,myTF),"",colorBlueGrey,styleThick|styleNoRescale);
GfxSetBkMode(0);
GfxSetOverlayMode(1);
x=Param("X",5,0,1500,10);
y=Param("Y",175,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();
Thanks
Amruta