Simple Coding Help - No Promise.

I want to create a afl for Historical major turning points on daily chart (eod chart) which can also if used on hourly chart if required.

AFL should mark all historical major turning points and draw line at historical point

...

Please help
Here is an attempt - presuming that all HHs & LLs need to be marked. But if we visually inspect the charts - there are cases where these HHs & LLs need not be a major turning point and there are other points that would qualify. I suppose that is the power of human brain.

There seems to be quite a few methods to draw a horizontal line and 2 methods given here seem to be the simplest. Feel free to change the shape, color and width of the horizontal lines.

Code:
_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
	if ( HH[i] ){
		PlotText( "HH", i, H[ i ] + dist[i], colorRed );
		PlotText( "=======================", i, H[i], colorRed);
	}
	if ( LH[i] )
		PlotText( "LH", i, H[ i ] + dist[i], colorRed );

	if ( HL[i] )
		PlotText( "HL", i, L[ i ] - dist[i], colorBrightGreen );

	if ( LL[i] ) {
		PlotText( "LL", i, L[ i ] - dist[i], colorBrightGreen );
		PlotText( "=======================", i, L[i], colorBrightGreen);
	}
}

/*
width=5;

for ( j = 0; j > width*-1; j--) {
	PlotShapes( IIf(Ref(HH,j),shapeStar,shapeNone), colorRed, layer=0, yposition=Ref(H,j), Offset=0 );
	PlotShapes( IIf(Ref(LL,j),shapeStar,shapeNone), colorBrightGreen, layer=0, yposition=Ref(L,j), Offset=0 );
}

*/

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
Plot( IIf(HL==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-1)==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-2)==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-3)==1,Close,Null), "Close", colorPink, styleLine );


_SECTION_END();
 
So is there a possible way if I can optimize it in time factor as well?
Yes. You want to know how? Ask yourself ...
I am capable of doing it myself.

I would say 'yes'. I want the optimization report to do it for me instead of me changing the time-frame every time from settings to re-optimize the AFL. The time-frames would be 1min, 3min, 5min, 7min, 10min, 12min, 15min, 20min, 30min, 45min, hourly, daily, weekly.
Anyway here is a hint to one possible solution. For example use multiple AddToComposite in one code or ATC in loop to clone your symbol to different Base Time Intervals and move all your cloned symbols to a WL. Then do individual optimization of your whole WL. In periodicity set lowest base time interval of your clones. In your case it is 1min.


I am capable of doing it myself.
It didn't work. I am not sure what I did was right or wrong
It was wrong of course. What else?

I am capable of doing it myself.

Are these details enough?
Probably not since your code is unknown. And don't expect others doing the programming for you if you can't simulate your issue with a simple code.

I am capable of doing it myself.
P.S I think my post was quite informative and gave all the details. And in case you had a confusion there was actually no need for this rant.
You just needed to read it more carefully.
Your first post wasn't informative at all so my "rant" was quite justified. Take a look at confirmation by KelvinHand who is a more experienced coder than the general user to be found in this forum. So it seems I'm not alone.

I am capable of doing it myself.
You just needed to read it more carefully.
Read your first post again yourself (without knowing what exactly you want from yourself)

I am capable of doing it myself.
 
Last edited:

Nehal_s143

Well-Known Member
Nehal Sir!

Do the following.

Plot it first on a EOD chart. Note the shape and dates and Zoom Out as far back as possible!!!

Next, Plot 15 min chart and it will show a straight line. Again Zoom out as far as possible.
yes sir, this way its working fine :) as indicator is based on legends logic, i thought it will give good result in trading, but in this case not able to make out much use of this indicator.....
 

Nehal_s143

Well-Known Member
Here is an attempt - presuming that all HHs & LLs need to be marked. But if we visually inspect the charts - there are cases where these HHs & LLs need not be a major turning point and there are other points that would qualify. I suppose that is the power of human brain.

There seems to be quite a few methods to draw a horizontal line and 2 methods given here seem to be the simplest. Feel free to change the shape, color and width of the horizontal lines.

Code:
_SECTION_BEGIN("HH");
Q = Param( "% Change", 2, 0.1, 10, 0.1 );
Z = Zig( C , q ) ;
HH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( z, q, 1 ) > Peak( Z, q, 2 ) ) );
LH = ( ( Z < Ref( Z, -1 ) AND Ref( Z, -1 ) > Ref( Z, -2 ) ) AND (Peak( Z, q, 1 ) < Peak( Z, q, 2 ) ) );
HL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) > Trough( Z, q, 2 ) ) );
LL = ( ( Z > Ref( Z, -1 ) AND Ref( Z, -1 ) < Ref( Z, -2 ) ) AND (Trough( Z, q, 1 ) < Trough( Z, q, 2 ) ) );
GraphXSpace = 5;
dist = 0.5 * ATR( 20 );

for ( i = 0; i < BarCount; i++ )
{
	if ( HH[i] ){
		PlotText( "HH", i, H[ i ] + dist[i], colorRed );
		PlotText( "=======================", i, H[i], colorRed);
	}
	if ( LH[i] )
		PlotText( "LH", i, H[ i ] + dist[i], colorRed );

	if ( HL[i] )
		PlotText( "HL", i, L[ i ] - dist[i], colorBrightGreen );

	if ( LL[i] ) {
		PlotText( "LL", i, L[ i ] - dist[i], colorBrightGreen );
		PlotText( "=======================", i, L[i], colorBrightGreen);
	}
}

/*
width=5;

for ( j = 0; j > width*-1; j--) {
	PlotShapes( IIf(Ref(HH,j),shapeStar,shapeNone), colorRed, layer=0, yposition=Ref(H,j), Offset=0 );
	PlotShapes( IIf(Ref(LL,j),shapeStar,shapeNone), colorBrightGreen, layer=0, yposition=Ref(L,j), Offset=0 );
}

*/

Filter=HH OR HL OR LH OR LL;
AddColumn(RSI(2),"RSI",1.2);
AddColumn(Close,"PRICE",1.2);
AddColumn(HH,"SHORT");
AddColumn(LH,"LH");
AddColumn(HL,"HL");
AddColumn(LL,"COVER");
AddColumn(V,"volume",1.0);
_SECTION_END();

_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
Plot( IIf(HL==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-1)==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-2)==1,Close,Null), "Close", colorPink, styleLine );
Plot( IIf(Ref(HL,-3)==1,Close,Null), "Close", colorPink, styleLine );


_SECTION_END();
thanks sir, I want line till end i.e till last data as shown manually in below Nifty1 hourly chart

sir, instead of using PlotText( "=======================" for limited space of line can we use Plot(pm,"",6,8|styleNoRescale); or similar

please suggest

 

Nehal_s143

Well-Known Member
Here is an attempt - presuming that all HHs & LLs need to be marked. But if we visually inspect the charts - there are cases where these HHs & LLs need not be a major turning point and there are other points that would qualify. I suppose that is the power of human brain.
sir logic is based on Naked Forex High-Probability Techniques for Trading Without Indicators by Alex Nekritin, book says that historical turning points are very crucial and always market respects historical major turning points.

with help of above afl I was trying to mark HH & LL swing as major turning points, as you said some place HH & LL is not major turning points and some major turning points are not HH & LL, is there any way to code major turning points. I have mq4 file for major turning point, will it be useful for coding AFL ???
 
PlotGrid would print a gridline to the end. Just comment out the PlotText and use PlotGrid as follows.

Code:
//		PlotText( "=======================", i, H[i], colorRed);
		PlotGrid( H[i], colorRed);
//		PlotText( "#######################", i, L[i], colorBrightGreen);
		PlotGrid( L[i], colorBrightGreen);
But on some charts, it was just too cluttered. On one hand more lines at a certain level could point to its strength but it really is ugly. I was looking at if we could find a way to reduce the grid lines - there is no point in having 3 lines at 720.15, 720.05 & 719.80. It should actually be 720. I would continue my research on this and am open to ideas.

I have just started off on Amibroker and I chose that as I think afl is easier than mql4. Anyway, it doesnt hurt to have a look at the code. Please do share it - I could probably learn something from it.
 
Hey happy singh,

I wanted to optimize my AFL on different time frame with some other parameters. How do I optimize it in time factor? Say for 1min, 3min, 5min, 7min, 10min, 12min, 15min, 20min, 30min, 45min, hourly, daily, weekly. Is it possible through an array working or someother method I do not know of?

P.S I have tried using timeframeset() and some other functions but didn't get the expected result. Please help.
FYI, out of curiosity I have made a code template that does what you are looking for and it works just as I have described and it works just fine.

If you don't get it done yourself then contact me.

Anyway here is a hint to one possible solution. For example use multiple AddToComposite in one code or ATC in loop to clone your symbol to different Base Time Interval names (all clones have same lowest base time frame) and move all your cloned symbols to a WL. Then do individual optimization of your whole WL. In periodicity set lowest base time interval of your clones. In your case it is 1min.
 
Last edited:

pratapvb

Well-Known Member
Hi Happy

I wanted to find big tail candles. The idea is to combine this with the TAZ (trader action zone) trading that I do.

a lot of times it provides amazing turning points for buying options and it explodes in next 2-4 candles.

so I wrote this AFL.


A = Ref( Close , -1 );
B = Ref( Low , -1 );
C= Ref(High, -1);

Filter= 100 * abs(A-B/A) > 5 ;

ideally it should give me all candles which have close vs low difference of more than 5%.

but there is some mistake somewhere, the filter gives a different output. can you PLEASE correct this.

Thanks and regards,

Manish Dhawan.
it needs to (A-B) / A

so
Filter= 100 * abs( (A-B)/A ) > 5 ;
 
The problem I am facing is when I optimize this AFL it gives me all the values as 0. The optimization factors used are periods for slow and fast ema and ADX range.
Problem seems to be with the parameter name Periods - its being used twice. Give them different names - something like

Code:
Periods1 = Param("Periods1", 3, 2, 15, 1);
Periods1 = Optimize("Periods1", Periods1, 2, 15, 1);
EMASlow = EMA( C, Periods1 );

Periods2 = Param("Periods2", 13, 10, 50, 1);
Periods2 = Optimize("Periods2", Periods2, 10, 50, 1);
EMAFast = EMA( C, Periods2 );
 

Similar threads