AFL coding help needed

velmont86

Active Member
Joined
Jun 19, 2012
Messages
143
Likes
31
#11
add this lines below..buy sell condition
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);
Short=ExRem(Short,Cover);


shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);
 

srichakra

Active Member
Joined
Dec 3, 2008
Messages
102
Likes
37
Location
chennai
#12
one line added.:)( dynacolor=IIf(trendup,colorGreen,colorRed);
SetBarFillColor(dynacolor);)

Code:
 n= Param("No. of Bars",4,2,8,1);
 TrendUp = C > Ref(HHV(H,n),-1);
 TrendDn = C < Ref(LLV(L,n),-1);
 TrendUp = ExRem(TrendUp,TrendDn);
 TrendDn = ExRem(TrendDn,TrendUp);

 Buy= TrendUp;
 Sell = TrendDn;
 Short=TrendDn;
 Cover= TrendUp;

 PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, layer = 0,yposition = Low, offset = -20);
 PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, layer = 0, yposition = High, offset = -20); 

 TrendUp = Flip(TrendUp,TrendDn);
 TrendDn = Flip(TrendDn,TrendUp);
 dynacolor=IIf(trendup,colorGreen,colorRed);
[B] SetBarFillColor(dynacolor);[/B]
 Plot(C,"CLose",IIf(trendup,colorGreen,colorRed),64);

Further to the above, I am trying to combine additional indicators to generate the signal. I am trying to mix TRIX and WMA for generating signals.

_SECTION_BEGIN("TEMA");


B=C>WMA(H,7);
S=C<WMA(L,7);
B=ExRem(B,S);
S=ExRem(S,B);
shape = B * shapeUpArrow + S * shapeDownArrow;
PlotShapes( shape, IIf( B, colorBlue, colorRed ),0, IIf( B, Low, High ),-20 );




b1=Bull_Trend=Trix(12) > EMA(Trix(12),3);
s1=Bear_Trend=Trix(12)<EMA(Trix(12),3);
Bull_trend= Flip(Bull_trend,Bear_Trend);
Bear_Trend= Flip(Bear_trend,Bull_Trend);
Ribbon_kol=IIf(Bull_Trend,colorGreen, IIf(Bear_Trend,colorRed, colorBlack));
Plot(4, "ribbon", Ribbon_kol, styleOwnScale|styleArea|styleNoLabel, -0.5,100);

n= Param("No. of Bars",4,2,8,1);
Impulse_UP = C > Ref(HHV(H,4),-1);
Impulse_Down = C < Ref(LLV(L,4),-1);
Impulse_UP = ExRem(Impulse_UP,Impulse_Down);
Impulse_Down = ExRem(Impulse_Down,Impulse_UP);

Impulse_Up = Flip(Impulse_Up,Impulse_down);
Impulse_down = Flip(Impulse_down,Impulse_up);

bar_kol=IIf(Impulse_UP,colorGreen,colorRed);
SetBarFillColor(bar_kol);
Plot(C,"CLose",IIf(Bar_kol,colorGreen,colorRed),64);


Buy= (B AND Bull_Trend) OR (B AND bar_kol==colorGreen) OR (B AND Bull_Trend AND bar_kol==colorGreen);
Sell=(S AND Bear_Trend) OR (S AND bar_kol==colorRed) OR ( S AND Bear_Trend AND bar_kol==colorRed) ;
Short= (S AND Bear_Trend) OR (S AND bar_kol==colorRed) OR ( S AND Bear_Trend AND bar_kol==colorRed) ;
Cover= (B AND Bull_Trend) OR (B AND bar_kol==colorGreen) OR (B AND Bull_Trend AND bar_kol==colorGreen);
Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);


_SECTION_END();
_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 ) ) ));

_SECTION_END();


This is my attempt at CUT and PASTE of codes as my ami programming skills are negligible.

I am attempting to do this

1. Buy / sell arrows based on close crossing WMA 7
2. Bar volour based on the 4 day high /low as per the code modified by Veera/Sr114.
3. Ribbon colour based on TRIX 12.

All individually seems to work. My requirement is
1. BUY when any two conditions are met. My problem is when a buy arrow is printed and it has red bar and red ribbon, no BUY. But in next bar,if the bar or Ribbon turns green , a buy needs to be shown( not arrow- a dot should do. )

2. reverse for Sell/short.


CAn somebody help me in this . Sorry for troubling .

Thanks in advance.
 

mastermind007

Well-Known Member
Joined
Dec 17, 2011
Messages
2,495
Likes
2,500
#13
All individually seems to work. My requirement is
1. BUY when any two conditions are met. My problem is when a buy arrow is printed and it has red bar and red ribbon, no BUY. But in next bar,if the bar or Ribbon turns green , a buy needs to be shown( not arrow- a dot should do. )
I could not understand your AFL code :). It will be better if you repost it in between Code tags. Nevertheless I can show you how you can get 2 out of 3.
Also, never use if conditions around comparing Colors. If for some reason, you change the parameter color, your afl will misbehave.

Code:
BCond1 = ..... // some condtion 
BCond2 = ..... // some condtion 
...
BCondN = ..... // some condtion 

Buy = (BCond1 + BCond2 + .... + BCondN) == MinimumMatchNeeded;
Sell = (BCond1 + BCond2 + .... + BCondN) == MinimumMatchNeeded;
...
 
Joined
Nov 7, 2006
Messages
757
Likes
782
#14
hi friends
can we have optimum number of bars for NIFTY INDEX on a 15min chart?
The formula uses 4 AS number of bars.
Is there something better number?

regards
ford
 

srichakra

Active Member
Joined
Dec 3, 2008
Messages
102
Likes
37
Location
chennai
#15
I could not understand your AFL code :). It will be better if you repost it in between Code tags. Nevertheless I can show you how you can get 2 out of 3.
Also, never use if conditions around comparing Colors. If for some reason, you change the parameter color, your afl will misbehave.

Code:
BCond1 = ..... // some condtion 
BCond2 = ..... // some condtion 
...
BCondN = ..... // some condtion 

Buy = (BCond1 + BCond2 + .... + BCondN) == MinimumMatchNeeded;
Sell = (BCond1 + BCond2 + .... + BCondN) == MinimumMatchNeeded;
...
I am a metatstock user and exposed to Amibroker only for few weeks. My attempt is to replicate what I use in Metastock and it is a cut and paste assembly of codes. That is the problem not knowing what each one does.

I will try your approach and see if I am able to get what i want. Thanks for you response
 
Joined
Dec 1, 2012
Messages
53
Likes
15
#16
helo my seniors and afl experts I have also a
problem regarding afl..
I want 1 simple afl with reminder in
amibrocker for only bullish and bearish
engulfing pattern ..only this 2 candle
sticks...nd also reconfirm this pattern with
just next third candle condition which means
3rd candle also close previous candle high
when bullish engulfing and vice versa..plz help
me all as soon as possible
thanks in advance
 

mastermind007

Well-Known Member
Joined
Dec 17, 2011
Messages
2,495
Likes
2,500
#17
helo my seniors and afl experts I have also a
problem regarding afl..
I want 1 simple afl with reminder in
amibrocker for only bullish and bearish
engulfing pattern ..only this 2 candle
sticks...nd also reconfirm this pattern with
just next third candle condition which means
3rd candle also close previous candle high
when bullish engulfing and vice versa..plz help
me all as soon as possible
thanks in advance
Try this

Code:
	a = CdBearishEngulfing(0.4,0.5);
	b = CdBullishEngulfing(0.4,0.5);
	Cond1 = (Ref(a,-1) == 1) AND (Ref(C,-2) > Ref(C,-1));
	Cond2 = (Ref(b,-1) == 1) AND (Ref(C,-2) < Ref(C,-1));
;
 

mastermind007

Well-Known Member
Joined
Dec 17, 2011
Messages
2,495
Likes
2,500
#18
hi friends
can we have optimum number of bars for NIFTY INDEX on a 15min chart?
The formula uses 4 AS number of bars.
Is there something better number?

regards
ford
Simple rule of thumb is that your bar count in Intraday should represent whole day. If your chart is 1 hour, use numbers like 4,5,6. If you are using 15 min candles, increase n to 16-24 (or rounding off 15-25).
 

mastermind007

Well-Known Member
Joined
Dec 17, 2011
Messages
2,495
Likes
2,500
#20
sir is it full afl??
No, it is not full afl. It is exactly what you had asked for!!!! Anyway, I made some improvement and relaxed its constraints to make it work for more scrips

Code:
	//bodyfactor = 0.1, rangefactor = 0.5
	a = CdBearishEngulfing(0.1,0.5);
	b = CdBullishEngulfing(0.1,0.5);
	Cond1 = (Ref(a,-1) == 1) AND (Ref(C,-1) > C);
	Cond2 = (Ref(b,-1) == 1) AND (Ref(C,-1) < C);
 

Similar threads

Broker Special Offers