help needed for afl coding-5bar pivot break buy-sell

rvlv

Active Member
#1
Friends

I read somewhere we can trade comfortably by trading upside or downside break of 5 bar pivot.

5bar pivot is the highest or lowest price in 5 bars.
when the close breaks above the high pivot ,we buy.
when the price breaks below low pivot,we sell.

timeframe =any

please help me generate this afl

regards
 

jagankris

Well-Known Member
#2
Here is the AFL.
Caution - on a range day this system sucks.

/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote.
no=Param( "Swing", 2, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
Buy=Cross(C,tsl) ;
Sell= Cross(tsl,C) ;

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
 

johnnypareek

Well-Known Member
#3
Friends

I read somewhere we can trade comfortably by trading upside or downside break of 5 bar pivot.

5bar pivot is the highest or lowest price in 5 bars.
when the close breaks above the high pivot ,we buy.
when the price breaks below low pivot,we sell.

timeframe =any

please help me generate this afl

regards

guess its what u want

HTML:
_SECTION_BEGIN("Price");

GraphXSpace=5;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{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", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

up=HHV(H,5);
dn=LLV(L,5);
Plot(Ref(up,-1),"5 day high",5,1);
Plot(Ref(dn,-1),"5 day low",4,1);
 

rvlv

Active Member
#4
Hi johnny bhai
you are right.
what you posted suits my need.

MA100 shows longer term direction.
Actually the the code also uses MA100 AND MA13 .
we look for long trades when ma13 >ma100.

The requirement is
everytime a high pivot forms a short horizontal line needs to be drawn to visibly clearly point out breakout occuring,though a bit late after 10 or 20 bars.

regards
rvlv

QUOTE
PROS trade after pull back or after test is over. Amateurs trade breakouts.
SAM SIEDEN trades price revisits to demand level or supply level.
 

rvlv

Active Member
#5
Hi Jagankris

Thanks for the code.
I just changed Swing =5 (default was 2)
It looks good specially on higher timeframes like 30min onwards.
The other change I liked to do is
give the swing line colorgreen in upmoving time and red in downmoving time.


Trading is a highly visual activity.
we see-understand-then decide what to do.
In view of this I like the chart to be simple,comfortable,easy to digest
market context.


best regards



Here is the AFL.
Caution - on a range day this system sucks.

/* my entry is very simple(daily data for trading)

kpl system for entry only & exit as follow:

1 st exit at x % from entry price only 1/3 quantity.(ie 1st profit target)
2 nd exit when exit Signal comes from kpl sys remaining 1/3 quantity.
3. scale-in to initial quantity if new kpl Buy Signal comes.
re-do above scaling-out & scaling-in till filal exit.
4. final exit all quantity when Close below 21 EMA.

kpl system code bellow :
*/
//AFL by Kamalesh Langote.
no=Param( "Swing", 2, 1, 55 );
tsl_col=ParamColor( "Color", colorCycle );

res=HHV(H,no);
sup=LLV(L,no);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
avn=ValueWhen(avd!=0,avd,1);
tsl=IIf(avn==1,sup,res);
Buy=Cross(C,tsl) ;
Sell= Cross(tsl,C) ;

Plot(tsl, _DEFAULT_NAME(), tsl_col, styleStaircase);
shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,tsl_col,tsl_col),0,IIf(Buy,Low,High));
SetPositionSize(300,spsShares);
ApplyStop(0,1,10,1);
 

Similar threads

Trade in Rs 20, No more % brokerage

Name:Phone:
Email:City:
State:
Are you a day trader?