Simple Coding Help - No Promise.

VJAY

Well-Known Member
Hello

There was a request to show the trend of SuperTrend system on lower time frame charts, we can do this with any system in 3 simple steps

First wrap your system inside higher time frame

1. use TimeFrameSet(myTF);

>>>>>>>>>>>>>> Your System Goes Here <<<<<<<<<<<<<

2. use TimeFrameRestore();

now expand the values from HTF to your current TF

3. HTF_TEND = TimeFrameExpand(TREND, myTF);

Use them on Lower TF

Sample code for ST . . . Any other requests for the same thing should use the tips and code on this post and try doing on their own

Its easy and also fun :)

Code:
_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();
Thanks happy singhji......:clapping:
Is it possible to view s/l line of higher trend(60) on lower tf ?as horizontal line....
 
If its available in HTF can be plotted on LTF . . . just remember to expand it before using . . .

Code:
HTF_TD = TimeFrameExpand(TrendDown,myTF);
HTF_TU = TimeFrameExpand(TrendUp,myTF);
Now you can plot the above 2 . . .


Tip: As the values from HTF & LTF can have vast difference use StyleNoRescale while plotting


:) Happy
 

VJAY

Well-Known Member
If its available in HTF can be plotted on LTF . . . just remember to expand it before using . . .

Code:
HTF_TD = TimeFrameExpand(TrendDown,myTF);
HTF_TU = TimeFrameExpand(TrendUp,myTF);
Now you can plot the above 2 . . .


Tip: As the values from HTF & LTF can have vast difference use StyleNoRescale while plotting


:) Happy
:confused: I can't understand it ...may be due to my ignorance of codings :(
 
One question ,

If i set the market start time as 9:00 hrs then ,,as i need to have Hourly charts as 9-10, 10-11 and so on at present the chart is 9:15 to 10:15

what i need to ask is will it make any difference to the indicators
 

pratapvb

Well-Known Member
One question ,

If i set the market start time as 9:00 hrs then ,,as i need to have Hourly charts as 9-10, 10-11 and so on at present the chart is 9:15 to 10:15

what i need to ask is will it make any difference to the indicators
It will make diff to 30min and hourly MAs etc as their OHLC values will be different
 
:confused: I can't understand it ...may be due to my ignorance of codings :(

Code:
Plot(TimeFrameExpand(TrendDown,myTF),"",colorRed,styleThick|styleNoRescale);
Plot(TimeFrameExpand(TrendUp,myTF),"",colorBlueGrey,styleThick|styleNoRescale);
use this
 
A very special "Thank You" note to Pratap. After trying out several suggestions given here by Happy and Kelvin and Pratap(which could not be brought to a logical end due to some residual mistakes from me) I just copied Pratap's code, which was essentially complete, into my afl. The signals improved immediately.

Really big help, Pratap! Kudos to you! I also tried to PM you but perhaps it is not activated.

:thanx:
 
Hello

In the Amibroker section on this forum most of the new threads that are started are for asking for some specific AFL/Code or system.

There are also some very old threads with lots of information, just that many of the external links would be broken, specially the urls about data utilities . . .



Cheers

:) Happy
 

Similar threads