Need Help with this AFL

Discuss Need Help with this AFL at the AmiBroker within the Traderji.com - Discussion forum for Stocks Commodities & Forex; Hi Guys, I have this swing chart AFL written by Tomasz Janeczko. I need to ...


Go Back   Traderji.com - Discussion forum for Stocks Commodities & Forex > TOOLS & RESOURCES > Software > AmiBroker
Register Blogs FAQ Chat Room Search Today's Posts Mark Forums Read


Welcome to the Traderji.com - Discussion forum for Stocks Commodities & Forex.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features.

By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please read the FAQ.

Reply
 
Thread Tools
Sponsored Links
  #1  
Old 6th March 2008, 02:45 PM
Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 15
deedeed is on a distinguished road
Default Need Help with this AFL



Hi Guys,

I have this swing chart AFL written by Tomasz Janeczko. I need to make one small change with this. Can you guys please help me with this code. I have no clue about AFL coding.
Thanks in advance.

Here are three images.

1.JPG - http://img256.imageshack.us/my.php?i...8526163zd2.jpg
This is how the swing charts look. The swing chart is overlayed on the candle chart here. The thing violet lines that are going in between the candle sticks are called swing charts.

2.JPG - http://img150.imageshack.us/img150/5580/45828959mz4.jpg
I have marked points 1,2,3 and 4.
Lets call Point 1 as swing low.
Point2 as swing high.
Point3 as swing low.
Point4 as swing high. Basically these are values at which a swing/change in price took place. I have also put the values at which the swing took place in the image. which is 2258, 2298,2285, 2318 respectively.

3.JPG - http://img155.imageshack.us/my.php?i...8935283ta8.jpg
This is the how I want the swing charts to look. Basically I want the swing range printed above/below the swing.
Example - Look at Point 2. Its replaced with 40 now.
Meaning Point 1 - Point 2 = 2258 - 2298 = -40. Remove the minus and just print the number.
Example 2 - Look at Point 3. Its replaced with 13.
Meaning Point 2 - Point 3 = 2298 - 2285 = 13
Similarly with Point 4.

Here is the original piece of code. Can you guys please make the changes for me.

/* Gann Swing chart v4 */
/* Last modified 24 Feb 2001 */
/* AFL implementation by */
/* (C)2001 Tomasz Janeczko */
/* one and two - bar reversal version */

/* Change this to 1 for two-bar mode */
twobarmode = 0;

outsidebar = Outside();
insidebar = H <= Ref( H, -1 ) AND L >= Ref( L, -1 ); // built-in inside() works with < > instead of <= >=

upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi = outsidebar AND Ref( insidebar, 1 );
Poo = outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii = Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );

upbar4 = upbar3 OR ( Poo AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR ( Pooi AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR ( Poio AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR ( Poii AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR (Poooi AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR ( Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR ( Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR ( Poioo AND Ref( upbar, 4 ) );

fupbar = upbar11;
fdownbar = downbar11;

// Two-bar mode handling
fupbar = IIf( twobarmode, fupbar AND Ref( fupbar, 1 ), fupbar );
fdownbar = IIf( twobarmode, fdownbar AND Ref( fdownbar, 1 ), fdownbar );

/* Barcount since most recent up and down swings */
Us = BarsSince( fupbar );
Ds = BarsSince( fdownbar ) ;

Sd1 =IIf( Us==0, 1, IIf( Ds==0, -1, 0) );

Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0),
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) );

g0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

/* shift back one bar, add one dummy swing at the end and shift forward */
/* to ensure proper handling of the last swing */
lastbar = Cum(1) == LastValue( Cum(1) );
swinglevel = IIf( g0 == -1, HighestSince( Sd2 == 1, H ), LowestSince( Sd2 == -1, L ) );
swinglevel = IIf( lastbar, IIf( g0 == -1, LowestSince( Sd2 == -1, L ), HighestSince( Sd2 == 1, H )), Ref( swinglevel, 1 ) );

/* Gann Swing chart drawn here */
Graph1 = Ref( ValueWhen( Ref( Sd2 != 0, 1 ) OR lastbar, swinglevel , 0 ), -1 );
Graph1Style = 512+1024;
GraphXSpace = 5;

/* Colourized price bars drawn here */
/* graph0 = close; */
/* graph0style = 128; */
/* barcolor = IIF( outsidebar, 1, IIF( downbar, 4, IIF( upbar, 5, 0 ) ) ); */
/* graph0barcolor = ValueWhen( barcolor != 0, barcolor ); */


Cheers
deedeed

Reply With Quote
  #2  
Old 7th March 2008, 04:39 PM
Member
 
Join Date: Jan 2007
Posts: 78
ashutosh.krsrivastava is on a distinguished road
Default Re: Need Help with this AFL

Quote:
Originally Posted by deedeed View Post
Hi Guys,

I have this swing chart AFL written by Tomasz Janeczko. I need to make one small change with this. Can you guys please help me with this code. I have no clue about AFL coding.
Thanks in advance.

Here are three images.

1.JPG - http://img256.imageshack.us/my.php?i...8526163zd2.jpg
This is how the swing charts look. The swing chart is overlayed on the candle chart here. The thing violet lines that are going in between the candle sticks are called swing charts.

2.JPG - http://img150.imageshack.us/img150/5580/45828959mz4.jpg
I have marked points 1,2,3 and 4.
Lets call Point 1 as swing low.
Point2 as swing high.
Point3 as swing low.
Point4 as swing high. Basically these are values at which a swing/change in price took place. I have also put the values at which the swing took place in the image. which is 2258, 2298,2285, 2318 respectively.

3.JPG - http://img155.imageshack.us/my.php?i...8935283ta8.jpg
This is the how I want the swing charts to look. Basically I want the swing range printed above/below the swing.
Example - Look at Point 2. Its replaced with 40 now.
Meaning Point 1 - Point 2 = 2258 - 2298 = -40. Remove the minus and just print the number.
Example 2 - Look at Point 3. Its replaced with 13.
Meaning Point 2 - Point 3 = 2298 - 2285 = 13
Similarly with Point 4.

Here is the original piece of code. Can you guys please make the changes for me.

/* Gann Swing chart v4 */
/* Last modified 24 Feb 2001 */
/* AFL implementation by */
/* (C)2001 Tomasz Janeczko */
/* one and two - bar reversal version */

/* Change this to 1 for two-bar mode */
twobarmode = 0;

outsidebar = Outside();
insidebar = H <= Ref( H, -1 ) AND L >= Ref( L, -1 ); // built-in inside() works with < > instead of <= >=

upbar = H > Ref( H, -1 ) AND L >= Ref( L, -1 );
downbar = L < Ref( L, -1 ) AND H <= Ref( H, -1 );

upbar2 = upbar OR ( outsidebar AND Ref( downbar, 1 ) ) ;
downbar2 = downbar OR ( outsidebar AND Ref( upbar, 1 ) );

Poi = outsidebar AND Ref( insidebar, 1 );
Poo = outsidebar AND Ref( outsidebar, 1 );
Pooi = Poo AND Ref( insidebar, 2 );
Poio = Poi AND Ref( outsidebar, 2 );
Poii = Poi AND Ref( insidebar, 2 );
Pooo = Poo AND Ref( outsidebar, 2 );
Poooi = Pooo AND Ref( insidebar, 3 );
Pooio = Pooi AND Ref( outsidebar, 3 );
Poioo = Poio AND Ref( outsidebar, 3 );

upbar3 = upbar2 OR ( Poi AND Ref( downbar, 2 ) );
downbar3 = downbar2 OR ( Poi AND Ref( upbar, 2 ) );

upbar4 = upbar3 OR ( Poo AND Ref( upbar, 2 ) );
downbar4 = downbar3 OR ( Poo AND Ref( downbar, 2 ) );

upbar5 = upbar4 OR ( Pooi AND Ref( upbar, 3 ) );
downbar5 = downbar4 OR ( Pooi AND Ref( downbar, 3 ) );

upbar6 = upbar5 OR ( Poio AND Ref( upbar, 3 ) );
downbar6 = downbar5 OR ( Poio AND Ref( downbar, 3 ) );

upbar7 = upbar6 OR ( Poii AND Ref( downbar, 3 ) );
downbar7 = downbar6 OR ( Poii AND Ref( upbar, 3 ) );

upbar8 = upbar7 OR ( Pooo AND Ref( downbar, 3 ) );
downbar8 = downbar7 OR ( Pooo AND Ref( upbar, 3 ) );

upbar9 = upbar8 OR ( Poooi AND Ref( downbar, 4 ) );
downbar9 = downbar8 OR (Poooi AND Ref( upbar, 4 ) );

upbar10 = upbar9 OR ( Pooio AND Ref( downbar, 4 ) );
downbar10 = downbar9 OR ( Pooio AND Ref( upbar, 4 ) );

upbar11 = upbar10 OR ( Poioo AND Ref( downbar, 4 ) );
downbar11 = downbar10 OR ( Poioo AND Ref( upbar, 4 ) );

fupbar = upbar11;
fdownbar = downbar11;

// Two-bar mode handling
fupbar = IIf( twobarmode, fupbar AND Ref( fupbar, 1 ), fupbar );
fdownbar = IIf( twobarmode, fdownbar AND Ref( fdownbar, 1 ), fdownbar );

/* Barcount since most recent up and down swings */
Us = BarsSince( fupbar );
Ds = BarsSince( fdownbar ) ;

Sd1 =IIf( Us==0, 1, IIf( Ds==0, -1, 0) );

Sd2 = IIf( Sd1 == 1, IIf( Ref( BarsSince(Sd1==1), -1) > Ref( BarsSince( Sd1 == -1), -1), 1, 0),
IIf( Sd1 == -1, IIf( Ref( BarsSince(Sd1==1),-1) < Ref( BarsSince( Sd1 == -1),-1), -1, 0), 0 ) );

g0 = ValueWhen( Sd2, Sd2 ); /* sample and hold non-zero values */

/* shift back one bar, add one dummy swing at the end and shift forward */
/* to ensure proper handling of the last swing */
lastbar = Cum(1) == LastValue( Cum(1) );
swinglevel = IIf( g0 == -1, HighestSince( Sd2 == 1, H ), LowestSince( Sd2 == -1, L ) );
swinglevel = IIf( lastbar, IIf( g0 == -1, LowestSince( Sd2 == -1, L ), HighestSince( Sd2 == 1, H )), Ref( swinglevel, 1 ) );

/* Gann Swing chart drawn here */
Graph1 = Ref( ValueWhen( Ref( Sd2 != 0, 1 ) OR lastbar, swinglevel , 0 ), -1 );
Graph1Style = 512+1024;
GraphXSpace = 5;

/* Colourized price bars drawn here */
/* graph0 = close; */
/* graph0style = 128; */
/* barcolor = IIF( outsidebar, 1, IIF( downbar, 4, IIF( upbar, 5, 0 ) ) ); */
/* graph0barcolor = ValueWhen( barcolor != 0, barcolor ); */


Cheers
deedeed
after graphXSpace = 5; add this code:

dist = 1.5 ATR(25);
for(i=1;i<=BarCount - 1; i++){
iif(swinglevel[i] == swinglevel[i-1], txtVal = 0, txtVal = swinglevel[i]-swinglevel[i-1]);
if(txtVal > 0) PlotText ("" + txtVal, i-1, H[i] + dist[i], colorblack);
if(txtVal < 0) PlotText ("" + abs(txtVal), i-1, L[i] + dist[i], colorblack);
}

refine it a little bit, and you got it.
regards
ashutosh

Reply With Quote
  #3  
Old 7th March 2008, 06:56 PM
Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 15
deedeed is on a distinguished road
Default Re: Need Help with this AFL

Thank You ashutosh for the help. Here are the changes I have made. I have marked them in red.


dist = 0.5*ATR(25);
for(i=1;i<=BarCount - 1; i++){
IIf(swinglevel[i] == swinglevel[i-1], txtVal = 0, txtVal = swinglevel[i]-swinglevel[i-1]);
if(txtVal > 0) PlotText ("" + txtVal, i-1, H[i] + dist[i], colorBlack);
if(txtVal < 0) PlotText ("" + abs(txtVal), i-1, L[i] - dist[i], colorBlack);
}

It works fine but there are some small problems.

Firstly and most importantly I would like to round off the values to two points. How can that be done.

Secondly, I am posting a screenshot for you to understand what is happening right now. Please let me know as to what is to be changed for getting the perfect values.

Circle A - there is value 5 in there. I dont understand what that is.

Circle B - Why is the value being printed above?

Circle C - the value must be below the swing but it gets printed in between.

Circle D - The value 2.94995 doesn't make any sense here again.

Circle E - Notice the value 8 that is printed to the left. The calculation is perfect. However it gets printed to the lift and not at the bottom of the swing.

Thank You once again for helping me with the code.

Cheers

Attached Images
File Type: gif new.gif (21.1 KB, 54 views)
Reply With Quote
  #4  
Old 8th March 2008, 12:32 PM
Member
 
Join Date: Jan 2007
Posts: 78
ashutosh.krsrivastava is on a distinguished road
Default Re: Need Help with this AFL

Quote:
Originally Posted by deedeed View Post
Thank You ashutosh for the help. Here are the changes I have made. I have marked them in red.


dist = 0.5*ATR(25);
for(i=1;i<=BarCount - 1; i++){
IIf(swinglevel[i] == swinglevel[i-1], txtVal = 0, txtVal = swinglevel[i]-swinglevel[i-1]);
if(txtVal > 0) PlotText ("" + txtVal, i-1, H[i] + dist[i], colorBlack);
if(txtVal < 0) PlotText ("" + abs(txtVal), i-1, L[i] - dist[i], colorBlack);
}

It works fine but there are some small problems.

Firstly and most importantly I would like to round off the values to two points. How can that be done.

Secondly, I am posting a screenshot for you to understand what is happening right now. Please let me know as to what is to be changed for getting the perfect values.

Circle A - there is value 5 in there. I dont understand what that is.

Circle B - Why is the value being printed above?

Circle C - the value must be below the swing but it gets printed in between.

Circle D - The value 2.94995 doesn't make any sense here again.

Circle E - Notice the value 8 that is printed to the left. The calculation is perfect. However it gets printed to the lift and not at the bottom of the swing.

Thank You once again for helping me with the code.

Cheers
Circle A: 5 is okey, i m checking 1.
Circle B: use swinglevel[i]+dist[i] in place of h[i]+dist[i], l[i]+dist[i].
Cirvle c: same as B
Circle D: you r right, checking
Circle E: checking


for roundingoff, use
txtValStr = NumToStr(abs(txtVal), 1.2);
if(txtVal >0) PlotText("" + txtValStr, i, swinglevel[i]+dist[i]......


try these, use Reliance EOD for chart and then post the picture, meanwhile i am trying to setright A,D and E.
regards
ashutosh

Reply With Quote
  #5  
Old 9th March 2008, 09:28 AM
Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 15
deedeed is on a distinguished road
Default Re: Need Help with this AFL

Hi ashutosh,

Thank You for your help.

I did make the changes you mentioned. And its looking too good now.

Here is the latest version of the code

dist = 0.5*ATR(25);
for(i=1;i<=BarCount - 1; i++){
IIf(swinglevel[i] == swinglevel[i-1], txtVal = 0, txtVal = swinglevel[i]-swinglevel[i-1]);
txtValStr = NumToStr(abs(txtVal), 1.2);
if(txtVal >0) PlotText("" + txtValStr, i, swinglevel[i] + dist[i], colorBlack);
if(txtVal < 0) PlotText ("" + txtValStr, i-1, swinglevel[i] - dist[i], colorBlack);

And as for the last line, I have used swinglevel[i] - dist[i], instead of
swinglevel[i] + dist[i], else the values are not being printed properly.

Also I have attached the reliance ka chart.

I have one question though.
What does the ATR(25) exactly mean?

cheers
deedeed

Attached Images
File Type: gif reliance-swing.gif (32.9 KB, 48 views)
Reply With Quote
  #6  
Old 10th March 2008, 12:33 AM
Member
 
Join Date: Nov 2006
Posts: 1,235
kkseal is on a distinguished road
Default Re: Need Help with this AFL

Why is it called the GANN swing chart?

Reply With Quote
  #7  
Old 10th March 2008, 12:58 AM
Member
 
Join Date: Nov 2006
Posts: 1,235
kkseal is on a distinguished road
Default Re: Need Help with this AFL

Deeded, would you care to post the same chart with twobarmode (variable in code) set to 1.

As for the ATR, i think Ashustosh is simply using it to position the text properly above & below the swing highs & lows.

Regards,
Kalyan.

Reply With Quote
  #8  
Old 10th March 2008, 09:07 AM
Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 15
deedeed is on a distinguished road
Default Re: Need Help with this AFL

Quote:
Originally Posted by kkseal View Post
Why is it called the GANN swing chart?
Its called Gann Swing Chart because this type of charting was invented by W.D Gann, a legendary trader from the early 1900's.

Reply With Quote
  #9  
Old 10th March 2008, 09:16 AM
Member
 
Join Date: Apr 2007
Location: Bangalore
Posts: 15
deedeed is on a distinguished road
Default Re: Need Help with this AFL

Quote:
Originally Posted by kkseal View Post
Deeded, would you care to post the same chart with twobarmode (variable in code) set to 1.

As for the ATR, i think Ashustosh is simply using it to position the text properly above & below the swing highs & lows.

Regards,
Kalyan.

Hi Kalyan

I have attached 2 images here.

1. reliance-2-bar-mode.gif - This is the 2 bar mode you requested.
2. reliance-2-bar-mode-error.gif - The same chart with the errors circled. There are some extra values which are being printed which I have no clue about. Please check.

Cheers
deedeed

Attached Images
File Type: gif reliance-2-bar-mode.gif (33.6 KB, 31 views)
File Type: gif reliance-2-bar-mode-error.gif (40.1 KB, 19 views)
Reply With Quote
  #10  
Old 10th March 2008, 10:36 AM
Member
 
Join Date: Jan 2007
Posts: 78
ashutosh.krsrivastava is on a distinguished road
Default Re: Need Help with this AFL

Quote:
Originally Posted by deedeed View Post
Hi ashutosh,

Thank You for your help.

I did make the changes you mentioned. And its looking too good now.

Here is the latest version of the code

dist = 0.5*ATR(25);
for(i=1;i<=BarCount - 1; i++){
IIf(swinglevel[i] == swinglevel[i-1], txtVal = 0, txtVal = swinglevel[i]-swinglevel[i-1]);
txtValStr = NumToStr(abs(txtVal), 1.2);
if(txtVal >0) PlotText("" + txtValStr, i, swinglevel[i] + dist[i], colorBlack);
if(txtVal < 0) PlotText ("" + txtValStr, i-1, swinglevel[i] - dist[i], colorBlack);

And as for the last line, I have used swinglevel[i] - dist[i], instead of
swinglevel[i] + dist[i], else the values are not being printed properly.

Also I have attached the reliance ka chart.

I have one question though.
What does the ATR(25) exactly mean?

cheers
deedeed
Hi,
Now finally try this:

Code:
dist = 1.0*ATR(25);
	for(i = 1; i <= BarCount - 1; i++){
		IIf(swinglevel[i] == swinglevel[i -1], txtVal = 0 , txtVal = swinglevel[i] - swinglevel[i-1]);
		Cntp = BarsSince(Cross(sd2, 0));
		Cntn = BarsSince(Cross(0, sd2));
		txtValStr = NumToStr(abs(txtVal), 1.2);
		if(txtVal > 0) PlotText("" + txtValStr, i-(Cntp[i]+2)/2, swinglevel[ i ] + dist[ i ], colorBlack);
		if(txtVal < 0) PlotText("" + txtValStr, i-(Cntn[i]+2)/2 , swinglevel[ i ] - dist[ i ], colorBlack);
	}
regards
ashutosh

Reply With Quote
Sponsored Links


Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +5.5. The time now is 11:56 AM.

Indemnity, Disclaimer & Disclosure Notice:
• By visiting Traderji.com you indicate your acceptance of our Forum Rules Disclaimer & Disclosure and indemnify Traderji.com, its associates and related parties of all claims howsoever resulting from the usage of the forum.
Disclaimer: Trading or investing in stocks & commodities is a high risk activity. Any action you choose to take in the markets is totally your own responsibility. Traderji.com will not be liable for any, direct or indirect, consequential or incidental damages or loss arising out of the use of this information.
Disclosure: The information in this forum is neither an offer to sell nor solicitation to buy any of the securities mentioned herein. The writers may or may not be trading in the securities mentioned.
• All names or products mentioned are trademarks or registered trademarks of their respective owners.
General Content Disclaimer Notice:
In light of our policy of encouraging candid, open exchanges of views and the rapid distribution of information originating from many sources, Traderji.com cannot determine the accuracy of information that may be uploaded to the forum. Opinions, advice and all other information expressed by participants in discussions are those of the author. You rely on such information at your own risk. You are urged to seek professional advice for specific, individual situations and not rely solely on advice or opinions given in the discussions. Since Traderji.com is an open and free discussion forum, any comments made by members of this forum in their posts reflect their own views and not of the owner or administrator of Traderji.com. Thus the owner/administrator indemnify themselves of all claims whatsoever and will not be liable or responsible for any members comments/views in this forum Traderji.com. If you find any objectionable or offensive posts made by members of this forum which you would like to bring to our notice for removal then please Contact Us.
 


Copyright © 2001 - 2008, Traderji.com All Rights Reserved.

Recommended Websites - www.TradersEdgeIndia.com - www.TradingPicks.com - www.HiFiVision.com - www.MasterOfTrading.com - www.NotebookTalk.com