AFL HELP REQUIRED...

#1
Hi I am new to Traderji and Trading.. I need help in coding AFL..i have a simple condition if macd crosses signal line and rsi above 30 i should get a signal.. but what if rsi was above 30 in yesterdays 15 min chart and Macd crosses signal line todays morning.. I am not getting signal..

is there any specific formula or method that.. when rsi crosses above 30 , the afl should check if Macd is above signal line and i should get a buy signal..

i don't know whether i am able to express myself
 
#3
_SECTION_BEGIN("ADX + RSI + MACD");
// This combines three indicators into one timing Signal
//function ParamOptimize( description, default, minv, maxv, step )
// { return Optimize(description, Param(description,default, minv, maxv, step ), minv, maxv, step ); }
tgl = ParamToggle("Result", "AND logic|Compare");
SetPositionSize( 100, spsShares );
// rsi
RSI1= RSI(14)>30;
RSI2= RSI (14)<70;
// adx di lines
range = Param("ADX Periods", 10, 2, 200, 1 );
myPdi = PDI(range );
myMdi = MDI(range );
upAdx = IIf( myPdi > myMdi, 1, 0);
// macd
r1 = Param( "Macd Fast avg", 12, 2, 200, 1 );
r2 = Param( "Macd Slow avg", 26, 2, 200, 1 );
r3 = Param( "Macd Signal avg", 9, 2, 200, 1 );
myMacd = MACD(r1,r2);
mySignal = Signal(r1,r2,r3);
upMacd = IIf(myMacd > mySignal, 1, 0);
// switch test calculation and compare the results
if(tgl)
{
myBuy = RSI1 AND upAdx AND upMacd;
myShort = !RSI1 AND !upAdx AND !upMacd;
}
else
{
myBuy = IIf(RSI1 AND myMacd > mySignal AND myPdi > myMdi,1,0);
myShort = IIf(RSI2 AND myMacd < mySignal AND myPdi < myMdi,1,0);
}
Buy = Cover = ExRem(myBuy, myShort);
Short = Sell = ExRem(myShort, myBuy);
PlotShapes(Buy*shapeUpArrow,colorWhite,0,H,Offset=-40);
PlotShapes(Sell*shapeDownArrow,colorYellow,0,L,Offset=-40);

The above afl i found on internet..i want to have new position everydayd.. means no carryover position from yesterday.fresh intraday signal for buy and sell.. but it not giving fresh signals everytime macd get crossover..

can there be modification in the afl which checks if macd get crossed with signal and RSI>70 then it should generate fresg signal after confiriming two to three bars back.
 

Attachments

travi

Well-Known Member
#4
The problem is you need to read the AFL documention first, atleast a bit to know how to use AB.

1. Goto window of open analysis > Settings > Periodicty
Select the timeframe in which you want to run the scan. (I bet you will have daily there and you have no clue what its doing)
and
2. in the bars in range option, select 1 recent bar(s)
These two will ensure you get the most recent result on the Timeframe that your trading
 
#5
First of all thanks for your advice.. i have changed the settings and checked..

i have further doubt..

please refer the part of the AFL..

myBuy = IIf(RSI1 AND myMacd > mySignal AND myPdi > myMdi,1,0);
here .. I am getting a signal when there is cross of Macd, Signal line and RSI has risen above 30.. at the same time..

What i want to say that can there be some modification in the AFL which makes the AFL..like if Macd has crossed signal line it should verify whether RSI has risen above 30 level and if both conditions are met then i should get a signal.

i hope iam clear,, if i have two or three conditions then the afl should verify whether previous conditions are fulfilled,, may it be two or three bars back..

thanks in advance
 

travi

Well-Known Member
#6
RSI1= RSI(14)>30;

This line is already checking if RSI is above 30 so code is fine.
 
#7
but the code
RSI1= RSI(14)>30;
is checking when rsi(14) simultaneusly with MACD cross.. if MACD line has crossed the signal line earlier it will not give signal...
is there any code which checks previous instances of a condition ..say 3-5 candles back if 1 condition is met.. and after 3-5 candles the 2nd condition is fulfilled it will give signal..
 

LOVEENAJYOTHI

Well-Known Member
#8
but the code
RSI1= RSI(14)>30;
is checking when rsi(14) simultaneusly with MACD cross.. if MACD line has crossed the signal line earlier it will not give signal...
is there any code which checks previous instances of a condition ..say 3-5 candles back if 1 condition is met.. and after 3-5 candles the 2nd condition is fulfilled it will give signal..
Code:
RSI1= RSI(14)>30;
RSI2= RSI (14)<70;
Replace the above 2 lines with the following
Code:
RSI1= Sum((RSI(14)>30),5)>=1;
RSI2= Sum((RSI(14)<70),5)>=1;
 
#9
Thanks a lot
LOVEENAJYOTH....

I tried the above afl..

I am attaching a PIC.. if you can go through it pls...

Here i have highlighted the areas where i should get the signals..which I am not getting because the MACD has crossed the signal line prevoius day and and it is still up on the next day..that's why im not getting signal..( my afl gives signal only when both rsi and macd singal condition are met simultaneusly) is there any changes needed in afl which checks ..like if MACD has crossed the singal previous day itself and if the rsi condition has met today i should get the signal.


thanks..
 

Attachments

LOVEENAJYOTHI

Well-Known Member
#10
Thanks a lot
LOVEENAJYOTH....

I tried the above afl..

I am attaching a PIC.. if you can go through it pls...

Here i have highlighted the areas where i should get the signals..which I am not getting because the MACD has crossed the signal line prevoius day and and it is still up on the next day..that's why im not getting signal..( my afl gives signal only when both rsi and macd singal condition are met simultaneusly) is there any changes needed in afl which checks ..like if MACD has crossed the singal previous day itself and if the rsi condition has met today i should get the signal.

thanks..
Ya, may need more modifications.
The Replaced lines look for ur "RSI condition fulfilment" within the last 5 bars.
And so, ur AFL now gives signals only when ur MACD condition is fulfilled in the current bar And RSI condition is fulfilled in any of the last 5 bars, NOT THE OTHER WAY ROUND.

Tell us whats ur requirement (about signal events) in exact terms ,in mathematical expressions or in AFL itself, then we can rectify/modify.
Use "AND" ,"OR" ,"+" etc to express ur requirements.

Whats ur Amibroker version ?
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

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