Help needed with Afl

R

ratan jain

Guest
#1
Hi ,

My first attempt at writing an Afl.
I have tried to write an afl that will show an arrow when the highest high of last 5 bars is crossed and when the lowest low of last 5 bars is crossed.

This is based on 1 minute charts.
The code shows blan, its not plotting.
Where am I going wrong?

Please guide this new programmer :)


_SECTION_BEGIN("myfirstafl");
TimeFrameSet (in1Minute );
Buy = High > HHV(Close,-5);
PlotShapes(shapeUpArrow*Buy,colorGreen);
Sell = Low < LLV(Close,-5);
PlotShapes(shapeDownArrow*Sell,colorRed);
Short = Sell;
Cover = Buy;
_SECTION_END();
 
#2
Hi Ratan,

You should use the Cross() function, which gives you single point where it crossed. If you use High > HHV(), it will give true signal for all days, after your Buy signal, till that condition is met.

Secondly, pass positive numbers to HHV(). ie HHV(close, 5) to mean highest close since 5 days.

Thirdly, we needn't worry about the chart interval. ie 1min, 5min, EOD etc. TimeFrameSet() and TimeFrameRestore() is needed only when you want to plot one intervals signal on another interval chart.

To conclude, the correct code should be like this:
Buy = Cross(Close, HHV(High, 5)); // When the close takes out highest high of last 5 days.
Sell = Cross(Close, LLV(Low, 5));
No need for TimeFrameSet() in this case.

All the best,
Praveen.
 
R

ratan jain

Guest
#5
Dear Bvpraveen,
I have tried the below,
There seem to be 2 places where I am stuck.
First is that only sell arrows are shown,
and second, the signals are not proper.
I mean, the arrows seem random.....
Can u please help?


_SECTION_BEGIN("BVP");
Plot(C,"Close",colorBlack,styleBar|styleThick);
Buy = Cross(Close, HHV(High, 5)); // When the close takes out highest high of last 5 days.
PlotShapes(shapeUpArrow*Buy,colorGreen);
Sell = Cross(Close, LLV(Low, 5));
PlotShapes(shapeDownArrow*Sell,colorRed);
_SECTION_END();

Enclosed please see the chart. I have circled the point where I think i may be doing something wrong.
PS: I have made change to sell signal, I have changed it to cross of low of last 5 bars.
Also, without the change also, signals were not matching.
Hope you can help.
 

Attachments

Last edited by a moderator:
R

ratan jain

Guest
#8
BVPraveen!!!!!!!!!

Help me out :)

You are the AFL GURU on Traderji........

I need your support :)
 

kkseal

Well-Known Member
#9
Why did you erase the BUY part? Keep everything as it is in the BVP code Just change the SELL line (4th line after SECTION_BEGIN)

Regards,
Kalyan.
 

Similar threads