Simple Coding Help - No Promise.

DSM

Well-Known Member
Hi Pratap,

My attention was drawn to this post which I had responded as a reply to a query. 150 and 365 EMA hourly chart which I divided by 8 hours to be 18 and 45 EMA (should have been divided by 6 and hence should have been 60 and 25 EMA on a daily basis) The reason ofcourse is that with the charting platform that I use, (TradeTiger) it is not possible to get 365 and 150 Hours EMA and hence converted into daily. Just to clarify.....BTW I don't have Amibroker or use AFL.


the thread then converts 150 and 365 to 18 and 45EMAs? confused :confused:
 

pratapvb

Well-Known Member
Hi Pratap,

My attention was drawn to this post which I had responded as a reply to a query. 150 and 365 EMA hourly chart which I divided by 8 hours to be 18 and 45 EMA (should have been divided by 6 and hence should have been 60 and 25 EMA on a daily basis) The reason ofcourse is that with the charting platform that I use, (TradeTiger) it is not possible to get 365 and 150 Hours EMA and hence converted into daily. Just to clarify.....BTW I don't have Amibroker or use AFL.
ok thanks....was just curious about those 2 sets of numbers as had not gone through more posts during live mkt...I was looking it more from the pt of view of answering the person's AFL query but got curious :)

btw I use 20EMA and 50MA for fast and slow MAs in higher TFs as mentioned in my diary

which is currently shoing a bundle of res between 6750-56

 

Nehal_s143

Well-Known Member
Hi

I am looking to pick the swing correctly with help of afl code

I have tried using swing based afl but not able to pick swing correctly, below afl shows all minor swing also, I want to use afl on 15 min chart with only major swings, which can be deteced by naked eyes

please help

Code:
//This swing is NOT based on percentage OR logarithmic changes of the Price. 
//Swing segments are triggered by the current Price (Close) > OR < than an average Price (Close) for a specified Period.
//Additionally, a minimum number of bars can be set to make a swing segment valid.
//Triggers can be turned on/ off (small triangles above High OR Low).
//Swing Pivots can be annotated (on/off) with:  change in value, % change, AND length of the swing segment in bars.
//Swing color is NOT based on segments. 
//If the resistance is taken out (previous Peak) the Trend is up. If the support is taken out (previous Trough) the Trend is down.

RequestTimedRefresh(1);

Len=Param("Period Length ?",13,1,100);
Min_Bars=Param("Minimum No of Bars in a Swing Segment ?",3,1,10,1);
Up_Color = ParamColor("Trend Up Color ?",colorBrightGreen);
Dn_Color = ParamColor("Trend Dn Color",colorRed);
Style = ParamStyle("Up Style",styleNoLabel|styleThick);
Annotate =  ParamToggle("Annotate Pivots ?",  "No|Yes",defaultval=1 );
Anno_color = ParamColor("Annotation Color ?", colorBlue);
Top_Pct=Param("Start Top Annotation as % of Y axis",5,1,100,1);
Bottom_Pct=Param("Start Bottom Annotation as % of Y axis",5,1,100,1);
Triggers =  ParamToggle("Mark Swing Pivot Trigger Bars ?",  "No|Yes",defaultval=1 );
Trigger_color = ParamColor("Trigger Color ?", colorYellow);


Min_Y = Status("axisminy");
Max_Y = Status("axismaxy");
Top_start = Max_Y - (Max_Y - Min_Y) * Top_Pct * 0.01;
Bottom_Start = Min_Y + (Max_Y - Min_Y) * Bottom_Pct * 0.01;

Dir = MA(Close,Len);

First_Visible_Bar =Status("FirstVisibleBar");
Last_Visible_Bar = Status("LastVisibleBar");
Pivot_No = 0;
Direction = 0;
Trend = 0;
Current_running_pivot_Bar = 0;
Current_running_pivot_Val = Close[0];	
Last_Top_Val = H[0];
Last_Top_Bar = 0;
Last_Bottom_Bar = 0;
Last_Bottom_Val = L[0];
Swing_Array = Null;
Trend_Array = 1;
Trigger_Dn = 0;
Trigger_Up = 0;

for (barnum = Len+1; barnum < BarCount; barnum++)
{
   	if (Direction >= 0 ) 
   	{
       if (H[barnum] > H[Current_running_pivot_Bar] AND Direction > 0) 
		{
         	Current_running_pivot_Bar = barnum;
         	Current_running_pivot_Val = H[barnum];
      	}

		if (Close[barnum] < Dir[barnum-1] AND (barnum - Current_running_pivot_Bar) >= Min_Bars)
		{
			if (direction == 0)
			{
				Direction = -1;
				Current_running_pivot_Bar = barnum;
				Current_running_pivot_Val = Low[barnum];
			}
			else
			{
				Direction = -1;
				Pivot_No++;
				Prev_Top_Val = Last_Top_Val;
				Prev_Top_Bar = Last_Top_Bar;
				y1 = Last_Top_Val = Current_running_pivot_Val;
				x1 = Last_Top_Bar = Current_running_pivot_Bar;
				Current_running_pivot_Bar = barnum;
				Current_running_pivot_Val = Low[barnum];
				y0 = Last_Bottom_Val;
				x0 = Last_Bottom_Bar;
				a = (y1 - y0) / (x1 - x0);
				b = (y0 * x1 - y1 * x0) / (x1 - x0);
				Trigger_Dn[barnum] = 1;
				if (barnum >= First_Visible_Bar AND barnum <= Last_Visible_Bar AND Annotate)
				{
					no_of_bars = x1 - x0;
					delta_val = y1 - y0;
					delta_pct = 100  * delta_val / y0;
					PlotText(NumToStr(delta_val,1.2) + "\n" + NumToStr(delta_pct,1.1) + "%\n"+NumToStr(no_of_bars,1.0) +"b",x1,Top_start,Anno_color,bkcolor = colorDefault);
				}
				for (j = x0;j <= x1;j++) 
				{
					Swing_Array[j]= a * j + b;
					if (Pivot_No == 1)
						Trend = 1;
					else
						if (Swing_Array[j] > Prev_Top_Val)
							Trend = 1;
					Trend_Array[j] = Trend;
				}
			}
   		}
	}

   	if (Direction <= 0) 
   	{
      	if (L[barnum] < L[Current_running_pivot_bar] AND direction < 0) 
		{
         	Current_running_pivot_Bar = barnum;
         	Current_running_pivot_Val = L[barnum];
     	}

		if (Close[barnum] > Dir[barnum-1] AND (barnum - Current_running_pivot_Bar) >= Min_Bars)	
		{
			if (direction == 0)
			{
				Direction = 1;
				Current_running_pivot_Bar = barnum;
				Current_running_pivot_Val = High[barnum];
			}
			else
			{
				Pivot_No++;
				Direction = 1;
				Prev_Bottom_Val = Last_Bottom_Val;
				y1 = Last_Bottom_Val = Current_running_pivot_Val;
				x1 = Last_Bottom_Bar = Current_running_pivot_Bar;
				Current_running_pivot_Bar = barnum;
				Current_running_pivot_Val = High[barnum];
				y0 = Last_Top_Val;
				x0 = Last_Top_Bar;
				a = (y1 - y0) / (x1 - x0);
				b = (y0 * x1 - y1 * x0) / (x1 - x0);
				Trigger_Up[barnum] = 1;
				if (barnum >= First_Visible_Bar AND barnum <= Last_Visible_Bar AND Annotate)
				{
					no_of_bars = x1 - x0;
					delta_val = y1 - y0;
					delta_pct = 100  * delta_val / y0;
					PlotText(NumToStr(delta_val,1.2) + "\n" + NumToStr(delta_pct,1.1) + "%\n"+NumToStr(no_of_bars,1.0) +"b",x1,Bottom_start,Anno_color,bkcolor = colorDefault);
				}
				for (j = x0;j <= x1;j++) 
				{
					Swing_Array[j]= a * j + b;
					if (Pivot_No == 1)
						Trend = -1;
					else
						if (Swing_Array[j] < Prev_Bottom_Val)
							Trend = -1;
					Trend_Array[j] = Trend;
				}
			}
   		}
	}
} 

if (Direction == 1 AND Current_running_pivot_Bar > Last_Bottom_Bar)
{
	x0 = Last_Bottom_Bar;
	y0 = Last_Bottom_Val;
	x1 = Current_running_pivot_Bar;
	y1 = Current_running_pivot_Val;
	Prev_Top_Val = Last_Top_Val;
	a = (y1 - y0) / (x1 - x0);
	b = (y0 * x1 - y1 * x0) / (x1 - x0);
	if (barnum >= First_Visible_Bar AND barnum <= Last_Visible_Bar AND Annotate)
	{
		no_of_bars = x1 - x0;
		delta_val = y1 - y0;
		delta_pct = 100  * delta_val / y0;
		PlotText(NumToStr(delta_val,1.2) + "\n" + NumToStr(delta_pct,1.1) + "%\n"+NumToStr(no_of_bars,1.0) +"b",x1,Top_start,Anno_color,bkcolor = colorDefault);
	}
	for (j = x0;j <= x1;j++) 
	{
		Swing_Array[j]= a * j + b;
		if (Pivot_No == 0)
			Trend = 1;
		else
			if (Swing_Array[j] > Prev_Top_Val)
				Trend = 1;
		Trend_Array[j] = Trend;
	}
}

if (direction == -1 AND Current_running_pivot_Bar > Last_Top_Bar )
{
	x0 = Last_Top_Bar;
	y0 = Last_Top_Val;
	x1 = Current_running_pivot_Bar;
	y1 = Current_running_pivot_Val;
	Prev_Bottom_Val = Last_Bottom_Val;
	a = (y1 - y0) / (x1 - x0);
	b = (y0 * x1 - y1 * x0) / (x1 - x0);
	if (barnum >= First_Visible_Bar AND barnum <= Last_Visible_Bar AND Annotate)
	{
		no_of_bars = x1 - x0;
		delta_val = y1 - y0;
		delta_pct = 100  * delta_val / y0;
		PlotText(NumToStr(delta_val,1.2) + "\n" + NumToStr(delta_pct,1.1) + "%\n"+NumToStr(no_of_bars,1.0) +"b",x1,Bottom_start,Anno_color,bkcolor = colorDefault);
	}
	for (j = x0;j <= x1;j++) 
	{
		Swing_Array[j]= a * j + b;
		if (Pivot_No == 0)
			Trend = -1;
		else
			if (Swing_Array[j] < Prev_Bottom_Val)
				Trend = -1;
		Trend_Array[j] = Trend;
	}
}


Color = IIf(Trend_Array == 1,Up_Color,Dn_Color);
Plot(Swing_Array,"",Color,Style);
if (Triggers)
{
	PlotShapes(shapeSmallDownTriangle * Trigger_Dn,Trigger_Color,0,High);
	PlotShapes(shapeSmallUpTriangle * Trigger_Up,Trigger_Color,0,Low);
}
 
Help needed from seniors like Happy ji and pratap ji..n others


i need a explorer for

Every candle going out of 3EMA(away from 3EMA) n 15 EMA Crossoever..

Just need to explorer to find out such stocks which goes away from 3EMA
(not touching 3 EMA)

hope you got my point.

help would be really appreciated.

Thanx you
 
Last edited:
Help needed from seniors like Happy ji and pratap ji..n others


i need a explorer for

Every candle going out of 3EMA(away from 3EMA) n 15 EMA Crossoever..

Just need to explorer to find out such stocks which goes away from 3EMA
(not touching 3 EMA)

hope you got my point.

help would be really appreciated.

Thanx you

try this

Filter = H < ema3 OR L > ema3;


Happy :)
 

Similar threads