Simple Coding Help - No Promise.

Nehal_s143

Well-Known Member
hi

I came across very good thread SH Swing trading system

Its very big thread 100+ pages, I am slow reader still at page 10, SH has given summary
at https://docs.google.com/file/d/0BwQT...QQQ/edit?pli=1

I was trying this method on Nifty future, I was surprised to see the chart,


I am trying to make afl for the same, but dont know how to write condition of last swing high/low broken for trend reversal and pullback to 15 ema.



Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 17, 2, 300, 1 );
Width = Param("Width%", 1.5, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style", styleLine | styleNoLabel );
CenterLine = MA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color, Style ); 
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color, Style ); 
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("ZIG - Zig");
P = ParamField( "Price field" );
change = Param("% change",0.3,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
Please help me to write trend reversal code and pullback code

Thanks
 

amitrandive

Well-Known Member
hey fxarun /amitrandive or any other experts

can you make this AFL atleast show 2 consecutive days of pivots? it would be even better if you could modify it in 2 AFL ............1 showing 2 days pivots and 1 showing continuous pivots for all time frames and add weekly monthly options in both of new AFL too :) :thumb:
No need to reinvent the wheel.
This code is already present here.
:thumb:

http://www.traderji.com/amibroker/34069-pivot-points-intraday-chart-afl-needed.html#post461527
 
hey fxarun /amitrandive or any other experts

can you make this AFL atleast show 2 consecutive days of pivots? it would be even better if you could modify it in 2 AFL ............1 showing 2 days pivots and 1 showing continuous pivots for all time frames and add weekly monthly options in both of new AFL too :) :thumb:
Try this one.

Code:
_SECTION_BEGIN("Multi Pivots");
//Modified and added extended floor pivots  from ("Multi Pivots -StockManiacs") by fxarun;

SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
Plot(C,"Close",IIf(C>Ref(C,-1),colorWhite ,IIf(C<Ref(C,-1),colorSkyblue ,colorYellow )),64);

RColor= ParamColor("Resistance Color",colorOrange );//
SColor= ParamColor("Support Color",colorBrightGreen );//
PColor= ParamColor("Pivot Color",colorYellow );//
style = ParamStyle("Style", 0, maskDefault);

T_F =ParamList("Pivot T_F","iDay|Hourly|2_Hrs|3_Hrs|4_Hrs|EOD|Weekly|Monthly");

if (T_F=="iDay")
{
H_1 = TimeFrameGetPrice( "H", inDaily, -1 );
L_1 = TimeFrameGetPrice( "L", inDaily, -1 );
C_1 = TimeFrameGetPrice( "C", inDaily, -1 );
O = TimeFrameGetPrice("O", inDaily); // current day's open
}
else if (T_F == "Hourly")
{
H_1 = TimeFrameGetPrice( "H", inHourly, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly, -1 );
O = TimeFrameGetPrice( "O", inHourly );
}
else if (T_F == "2_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*2, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*2, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*2, -1 );
O = TimeFrameGetPrice( "O", inHourly*2);
}
else if (T_F == "3_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*3, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*3, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*3, -1 );
O = TimeFrameGetPrice( "O", inHourly*3);
}
else if (T_F == "4_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*4, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*4, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*4, -1 );
O = TimeFrameGetPrice( "O", inHourly*4 );

}
else if (T_F == "EOD")
{
H_1 = TimeFrameGetPrice( "H", inDaily, 0 );
L_1 = TimeFrameGetPrice( "L", inDaily, 0 );
C_1 = TimeFrameGetPrice( "C", inDaily, 0 );
O = TimeFrameGetPrice( "O", inDaily );

}
else if (T_F == "Weekly")
{
H_1 = TimeFrameGetPrice( "H", inWeekly, -1 );
L_1 = TimeFrameGetPrice( "L", inWeekly, -1 );
C_1 = TimeFrameGetPrice( "C", inWeekly, -1 );
O = TimeFrameGetPrice( "O", inWeekly );
}
else if (T_F == "Monthly")
{
H_1 = TimeFrameGetPrice( "H", inMonthly, -1 );
L_1 = TimeFrameGetPrice( "L", inMonthly, -1 );
C_1 = TimeFrameGetPrice( "C", inMonthly, -1 );
O = TimeFrameGetPrice( "O", inMonthly );
}

// To calculate the Pivot Levels

R = H_1 - L_1; // Range
_N(Pivot =ParamList("Pivot Type ", "Classical|Woodies|Fibonacci|WF|FloorPivots"));

if (Pivot =="Classical" )
{
PP = (H_1 + L_1 + C_1) / 3;
r1 = (2 * PP) - L_1 ;
s1 = (2 * PP) - H_1 ;
r2 = PP - s1 + r1;
s2 = PP - (r1 - s1) ;
r3 = 2 * (PP - L_1) + H_1 ;
s3 = L_1 - (2 * (H_1 - PP));
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if(Pivot =="Woodies" )
{
PP = (H_1 + L_1 + C_1 + O) / 4;
r1 = (2 * PP) - L_1;
r2 = PP + R;
r3 = H_1 + 2 * (PP - L_1);
r4 = r3 + R;
s1 = (2 * PP) - H_1;
s2 = PP - R;
s3 = L_1 - 2 * (H_1 - PP);
s4 = S3 - R;
bc = Null;
tc = Null;
}

else if(Pivot =="Fibonacci" )
{
PP = (H_1 + L_1 + C_1) / 3;
r3 = PP + 1.000 * R;
r2 = PP + 0.618 * R;
r1 = PP + 0.382 * R;
s1 = PP - 0.382 * R;
s2 = PP - 0.618 * R;
s3 = PP - 1.000 * R;
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if (Pivot == "WF")
{
PP = (H_1 + L_1 + O + O) / 4;
s1 = PP - (R * 0.38);
s2 = PP - (R * 0.62);
s3 = PP - (R * 1.272);
r1 = PP + (R * 0.38);
r2 = PP + (R * 0.62);
r3 = PP + (R * 1.272);
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if (Pivot == "FloorPivots")
{
PP = (H_1 + L_1 + C_1) / 3;
r1 = ( 2*PP ) - L_1  ; 
s1 = ( 2*PP ) - H_1; 
r2 = PP + R; 
s2 = PP - R; 
r3 = R1 + R; 
s3 = S1 - R; 
r4 = R3 + (R2-R1); 
s4 = S3 - (S1-S2);
bc = (H_1 + L_1)/2;
tc = ( PP - bc ) + PP;
}
//Defining TF on charts
procedure AddT_fParam(defaultvalue)
{
global T_F;
T_F = ParamList("Time Frame", List = "iDay|Hourly|2_Hrs|3_Hrs|4_Hrs|EOD|Weekly|Monthly" , defaultvalue);

if(T_F == "iDay") T_F = inDaily;
else if(T_F == "Hourly") T_F = inHourly;
else if(T_F == "2_Hrs") T_F = inHourly*2;
else if(T_F == "3_Hrs") T_F = inHourly*3;
else if(T_F == "4_Hrs") T_F = inHourly*4;
else if(T_F == "EOD") T_F = inDaily;
else if(T_F == "Weekly") T_F = inWeekly;
else if(T_F == "Montly") T_F = inMonthly;
}

// Plot Pivot Levels in the charts

Plot (PP,"PP",Pcolor,style);
Plot (r1,"R1",Rcolor,style);
Plot (r2,"R2",Rcolor,style);
Plot (r3,"R3",Rcolor,style);
Plot (s1,"S1",Scolor,style);
Plot (s2,"S2",Scolor,style);
Plot (s3,"S3",Scolor,style);
Plot (r4,"R4",Rcolor,style);
Plot (s4,"S4",Scolor,style);
Plot (tc,"TC",colorWhite,style);
Plot (bc,"BC",colorWhite,style);

_SECTION_END();
 

trash

Well-Known Member
Try this one.

Code:
_SECTION_BEGIN("Multi Pivots");
//Modified and added extended floor pivots  from ("Multi Pivots -StockManiacs") by fxarun;

SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
Plot(C,"Close",IIf(C>Ref(C,-1),colorWhite ,IIf(C<Ref(C,-1),colorSkyblue ,colorYellow )),64);

RColor= ParamColor("Resistance Color",colorOrange );//
SColor= ParamColor("Support Color",colorBrightGreen );//
PColor= ParamColor("Pivot Color",colorYellow );//
style = ParamStyle("Style", 0, maskDefault);

T_F =ParamList("Pivot T_F","iDay|Hourly|2_Hrs|3_Hrs|4_Hrs|EOD|Weekly|Monthly");

if (T_F=="iDay")
{
H_1 = TimeFrameGetPrice( "H", inDaily, -1 );
L_1 = TimeFrameGetPrice( "L", inDaily, -1 );
C_1 = TimeFrameGetPrice( "C", inDaily, -1 );
O = TimeFrameGetPrice("O", inDaily); // current day's open
}
else if (T_F == "Hourly")
{
H_1 = TimeFrameGetPrice( "H", inHourly, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly, -1 );
O = TimeFrameGetPrice( "O", inHourly );
}
else if (T_F == "2_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*2, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*2, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*2, -1 );
O = TimeFrameGetPrice( "O", inHourly*2);
}
else if (T_F == "3_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*3, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*3, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*3, -1 );
O = TimeFrameGetPrice( "O", inHourly*3);
}
else if (T_F == "4_Hrs")
{
H_1 = TimeFrameGetPrice( "H", inHourly*4, -1 );
L_1 = TimeFrameGetPrice( "L", inHourly*4, -1 );
C_1 = TimeFrameGetPrice( "C", inHourly*4, -1 );
O = TimeFrameGetPrice( "O", inHourly*4 );

}
else if (T_F == "EOD")
{
H_1 = TimeFrameGetPrice( "H", inDaily, 0 );
L_1 = TimeFrameGetPrice( "L", inDaily, 0 );
C_1 = TimeFrameGetPrice( "C", inDaily, 0 );
O = TimeFrameGetPrice( "O", inDaily );

}
else if (T_F == "Weekly")
{
H_1 = TimeFrameGetPrice( "H", inWeekly, -1 );
L_1 = TimeFrameGetPrice( "L", inWeekly, -1 );
C_1 = TimeFrameGetPrice( "C", inWeekly, -1 );
O = TimeFrameGetPrice( "O", inWeekly );
}
else if (T_F == "Monthly")
{
H_1 = TimeFrameGetPrice( "H", inMonthly, -1 );
L_1 = TimeFrameGetPrice( "L", inMonthly, -1 );
C_1 = TimeFrameGetPrice( "C", inMonthly, -1 );
O = TimeFrameGetPrice( "O", inMonthly );
}

// To calculate the Pivot Levels

R = H_1 - L_1; // Range
_N(Pivot =ParamList("Pivot Type ", "Classical|Woodies|Fibonacci|WF|FloorPivots"));

if (Pivot =="Classical" )
{
PP = (H_1 + L_1 + C_1) / 3;
r1 = (2 * PP) - L_1 ;
s1 = (2 * PP) - H_1 ;
r2 = PP - s1 + r1;
s2 = PP - (r1 - s1) ;
r3 = 2 * (PP - L_1) + H_1 ;
s3 = L_1 - (2 * (H_1 - PP));
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if(Pivot =="Woodies" )
{
PP = (H_1 + L_1 + C_1 + O) / 4;
r1 = (2 * PP) - L_1;
r2 = PP + R;
r3 = H_1 + 2 * (PP - L_1);
r4 = r3 + R;
s1 = (2 * PP) - H_1;
s2 = PP - R;
s3 = L_1 - 2 * (H_1 - PP);
s4 = S3 - R;
bc = Null;
tc = Null;
}

else if(Pivot =="Fibonacci" )
{
PP = (H_1 + L_1 + C_1) / 3;
r3 = PP + 1.000 * R;
r2 = PP + 0.618 * R;
r1 = PP + 0.382 * R;
s1 = PP - 0.382 * R;
s2 = PP - 0.618 * R;
s3 = PP - 1.000 * R;
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if (Pivot == "WF")
{
PP = (H_1 + L_1 + O + O) / 4;
s1 = PP - (R * 0.38);
s2 = PP - (R * 0.62);
s3 = PP - (R * 1.272);
r1 = PP + (R * 0.38);
r2 = PP + (R * 0.62);
r3 = PP + (R * 1.272);
r4 = Null;
s4 = Null;
bc = Null;
tc = Null;
}
else if (Pivot == "FloorPivots")
{
PP = (H_1 + L_1 + C_1) / 3;
r1 = ( 2*PP ) - L_1  ; 
s1 = ( 2*PP ) - H_1; 
r2 = PP + R; 
s2 = PP - R; 
r3 = R1 + R; 
s3 = S1 - R; 
r4 = R3 + (R2-R1); 
s4 = S3 - (S1-S2);
bc = (H_1 + L_1)/2;
tc = ( PP - bc ) + PP;
}
//Defining TF on charts
procedure AddT_fParam(defaultvalue)
{
global T_F;
T_F = ParamList("Time Frame", List = "iDay|Hourly|2_Hrs|3_Hrs|4_Hrs|EOD|Weekly|Monthly" , defaultvalue);

if(T_F == "iDay") T_F = inDaily;
else if(T_F == "Hourly") T_F = inHourly;
else if(T_F == "2_Hrs") T_F = inHourly*2;
else if(T_F == "3_Hrs") T_F = inHourly*3;
else if(T_F == "4_Hrs") T_F = inHourly*4;
else if(T_F == "EOD") T_F = inDaily;
else if(T_F == "Weekly") T_F = inWeekly;
else if(T_F == "Montly") T_F = inMonthly;
}

// Plot Pivot Levels in the charts

Plot (PP,"PP",Pcolor,style);
Plot (r1,"R1",Rcolor,style);
Plot (r2,"R2",Rcolor,style);
Plot (r3,"R3",Rcolor,style);
Plot (s1,"S1",Scolor,style);
Plot (s2,"S2",Scolor,style);
Plot (s3,"S3",Scolor,style);
Plot (r4,"R4",Rcolor,style);
Plot (s4,"S4",Scolor,style);
Plot (tc,"TC",colorWhite,style);
Plot (bc,"BC",colorWhite,style);

_SECTION_END();
You need to learn to code more intelligently/efficiently. Also why keeping code leftovers that are not used anywhere? It just makes code more unreadable.

Code:
_SECTION_BEGIN("Multi Pivots");
//Modified and added extended floor pivots  from ("Multi Pivots -StockManiacs") by fxarun;
// modified by trash

SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
Plot( C, "Close", IIf( C > Ref( C, -1 ), colorWhite , IIf( C < Ref( C, -1 ), colorSkyblue , colorYellow ) ), 64 );

RColor = ParamColor( "Resistance Color", colorOrange );//
SColor = ParamColor( "Support Color", colorBrightGreen );//
PColor = ParamColor( "Pivot Color", colorYellow );//
style = ParamStyle( "Style", 0, maskDefault );

T_F = ParamList( "Pivot T_F", "iDay|Hourly|2_Hrs|3_Hrs|4_Hrs|EOD|Weekly|Monthly" );

switch ( T_F )
{
	case "iDay":
		tmfrm = inDaily;
		delay = -1;
		break;
	case "Hourly":
		tmfrm = inHourly;
		delay = -1;
		break;
	case "2_Hrs":
		tmfrm = inHourly * 2;
		delay = -1;
		break;

	case "3_Hrs":
		tmfrm = inHourly * 3;
		delay = -1;
		break;

	case "4_Hrs":
		tmfrm = inHourly * 4;
		delay = -1;
		break;

	case "EOD":
		tmfrm = inDaily;
		delay = 0;
		break;

	case "Weekly":
		tmfrm = inWeekly;
		delay = -1;
		break;

	case "Monthly":
		tmfrm = inMonthly;
		delay = -1;
		break;

	default:
		break;
}

H_1 = TimeFrameGetPrice( "H", tmfrm, -delay );
L_1 = TimeFrameGetPrice( "L", tmfrm, -delay );
C_1 = TimeFrameGetPrice( "C", tmfrm, -delay );
O_1 = TimeFrameGetPrice( "O", tmfrm );


// To calculate the Pivot Levels
R = H_1 - L_1; // Range
_N(Pivot =ParamList("Pivot Type ", "Classical|Woodies|Fibonacci|WF|FloorPivots"));

switch ( Pivot )
{
	case "Classical":
		PP = ( H_1 + L_1 + C_1 ) / 3;
		r1 = ( 2 * PP ) - L_1 ;
		s1 = ( 2 * PP ) - H_1 ;
		r2 = PP - s1 + r1;
		s2 = PP - ( r1 - s1 ) ;
		r3 = 2 * ( PP - L_1 ) + H_1 ;
		s3 = L_1 - ( 2 * ( H_1 - PP ) );
		r4 = Null;
		s4 = Null;
		bc = Null;
		tc = Null;
		break;

	case "Woodies":
		PP = ( H_1 + L_1 + C_1 + O_1 ) / 4;
		r1 = ( 2 * PP ) - L_1;
		r2 = PP + R;
		r3 = H_1 + 2 * ( PP - L_1 );
		r4 = r3 + R;
		s1 = ( 2 * PP ) - H_1;
		s2 = PP - R;
		s3 = L_1 - 2 * ( H_1 - PP );
		s4 = S3 - R;
		bc = Null;
		tc = Null;
		break;

	case "Fibonacci":
		PP = ( H_1 + L_1 + C_1 ) / 3;
		r3 = PP + 1.000 * R;
		r2 = PP + 0.618 * R;
		r1 = PP + 0.382 * R;
		s1 = PP - 0.382 * R;
		s2 = PP - 0.618 * R;
		s3 = PP - 1.000 * R;
		r4 = Null;
		s4 = Null;
		bc = Null;
		tc = Null;
		break;

	case Pivot == "WF":
		PP = ( H_1 + L_1 + O_1 + O_1 ) / 4;
		s1 = PP - ( R * 0.38 );
		s2 = PP - ( R * 0.62 );
		s3 = PP - ( R * 1.272 );
		r1 = PP + ( R * 0.38 );
		r2 = PP + ( R * 0.62 );
		r3 = PP + ( R * 1.272 );
		r4 = Null;
		s4 = Null;
		bc = Null;
		tc = Null;
		break;

	case Pivot == "FloorPivots":
		PP = ( H_1 + L_1 + C_1 ) / 3;
		r1 = ( 2 * PP ) - L_1  ;
		s1 = ( 2 * PP ) - H_1;
		r2 = PP + R;
		s2 = PP - R;
		r3 = R1 + R;
		s3 = S1 - R;
		r4 = R3 + ( R2 - R1 );
		s4 = S3 - ( S1 - S2 );
		bc = ( H_1 + L_1 ) / 2;
		tc = ( PP - bc ) + PP;
		break;

	default:
		break;
}

// Plot Pivot Levels in the charts
Plot ( PP, "PP", Pcolor, style );
Plot ( r1, "R1", Rcolor, style );
Plot ( r2, "R2", Rcolor, style );
Plot ( r3, "R3", Rcolor, style );
Plot ( s1, "S1", Scolor, style );
Plot ( s2, "S2", Scolor, style );
Plot ( s3, "S3", Scolor, style );
Plot ( r4, "R4", Rcolor, style );
Plot ( s4, "S4", Scolor, style );
Plot ( tc, "TC", colorWhite, style );
Plot ( bc, "BC", colorWhite, style );
_SECTION_END();
 

Similar threads