Traderji.com - Discussion forum for Stocks Commodities & Forex

Need help for AFL

Discuss Need help for AFL at the AmiBroker within the Traderji.com - Discussion forum for Stocks Commodities & Forex; Hi, I got this code from amibroker website and would like to include the buy/long ...


Go Back   Traderji.com - Discussion forum for Stocks Commodities & Forex > TOOLS & RESOURCES > Software > AmiBroker

Notices


Advertise Here

Reply
 
Thread Tools
Sponsored Links
  #1  
Old 30th January 2007, 04:16 AM
Member
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tican2 is on a distinguished road
Reputation: 20
Default Need help for AFL

Hi,

I got this code from amibroker website and would like to include the buy/long condition is reverse to the short . Could someone please help me out ? Thanks

fCl = Ref(C,-1);
fHigh = Ref(H,-1);
fLow = Ref(L,-1);
fAdvDrop = fCl - Ref(C,-2);
fAtr = Ref(ATR(8),-1);
diffHl = fHigh-fLow;
fStoch = Ref(StochD(14),-1);
fBBandTop=Ref(BBandTop(C,20,2),-1);
fOpCond = fCl - 0.5 * fAtr;
fOp = Ref(O,0);
fStopLoss = fHigh + 0.5 * fAtr;

bbTopSell =
// The stock must first puncture and close outside (above) the upper Bollinger Band
IIf( fCl > fBBandTop AND
// The closer the closing price is to the high of the day, the better.
fCl > (fLow + 0.75 * diffHL ) AND
// And the bigger the day's advance, the better
fAdvDrop > (1.5 * fAtr) AND
// On the following day, the stock must 'gap' down below the prior day's close.
// This 'gap down' is crucial as it serves as the most important criteria of
// the entire strategy.
fOp < fOpCond AND
// Overbought condition added
fStoch > 80, 1, 0 );

/* Exploration Columns for Sorting */

NumColumns = 10;

Column0 = fOp;
Column1 = fOpCond;
Column2 = fStopLoss;

Column0Name = "Open";
Column1Name = "OpenCond";
Column2Name = "StopLoss";

Column0Format = 1.2;
Column1Format = 1.2;
Column2Format = 1.2;

Filter = bbTopSell == 1;

Buy = 0;
Sell = bbTopSell>0;
Reply With Quote
  #2  
Old 30th January 2007, 08:06 AM
Member
 
Join Date: Aug 2006
Location: kerala
Posts: 143
Thanks: 0
Thanked 0 Times in 0 Posts
kurian is on a distinguished road
Reputation: 20
Default Re: Need help for AFL

hai tican2
can u pls help me to plot daily and weekly mscd in daily price charts in amibroker.
kurian joseph
Reply With Quote
  #3  
Old 30th January 2007, 12:38 PM
Member
 
Join Date: Sep 2005
Posts: 1,102
Blog Entries: 1
Thanks: 9
Thanked 25 Times in 17 Posts
beginner_av will become famous soon enoughbeginner_av will become famous soon enough
Reputation: 107
Default Re: Need help for AFL

dear tican2,

i have arranged your formula so that it is more understandable. pls see this. it is for ami4.8 or higher. else replace the addcolumns with the older one with numcolumns.

**************************************

fCl = Ref(C,-1); // close yesterday
fHigh = Ref(H,-1); // high yesterday
fLow = Ref(L,-1); // low yesterday
fAdvDrop = fCl - Ref(C,-2); // difference between yesterday and day before's close
fAtr = Ref(ATR(8),-1); // last 8 days Average True Range till yesterday
diffHl = fHigh-fLow; // difference between yesterday's high and low (range)
fStoch = Ref(StochD(14),-1); //14 day slow stochastics as on yeaterday
fBBandTop=Ref(BBandTop(C,20,2),-1); //bollinger band top
fOpCond = fCl - 0.5 * fAtr; // opening condition gap down by .5 times ATR(8) from yesterday's close
fOp = Ref(O,0); //today's opening
fStopLoss = fHigh + 0.5 * fAtr; // stp loss at yesterday's high + .5 times ATR(8)

// The stock must first puncture and close outside (above) the upper Bollinger Band

bbTopSell = IIf( fCl > fBBandTop AND
// The closer the closing price is to the high of the day, the better.
fCl > (fLow + 0.75 * diffHL ) AND
// And the bigger the day's advance, the better
fAdvDrop > (1.5 * fAtr)
// On the following day, the stock must 'gap' down below the prior day's close.
// This 'gap down' is crucial as it serves as the most important criteria of
// the entire strategy.
AND fOp < fOpCond AND
// Overbought condition added
fStoch > 80, 1, 0 );

/* Exploration Columns for Sorting */

//NumColumns = 10;

//Column0 = fOp;
//Column1 = fOpCond;
//Column2 = fStopLoss;

//Column0Name = "Open";
//Column1Name = "OpenCond";
//Column2Name = "StopLoss";

//Column0Format = 1.2;
//Column1Format = 1.2;
//Column2Format = 1.2;

AddColumn(fOp, "Open", 1.2);
AddColumn(fOpCond, "OpenCond", 1.2);
AddColumn(fStopLoss, "StopLoss", 1.2);
AddTextColumn(FullName(), "Stock Name");

Filter = bbTopSell == 1;

Buy = 0;
Sell = bbTopSell>0;


*************************************


now this formula has a big problem. by bollinger itself it is fine, but it does not take into account the direction of the trend. in case of strong trend, if u understand all the conditions you will see that a gap down of .5 * atr is very normal and prices can recover very rapidly in the direction of the main trend. see the attached charts on the last day for which signals were generated. the macd and all the three MAs are up...so this kind of trade becomes very risky as you are going against the trend EVEN WHEN PRICES ARE TRENDING UP. you are only depending upon an opening gap, which professionals will gladly fill.
and STOC or RSI or any OSC is of no use as during trends, they will remain in overbought zones, often > 80.
in spite of this do you want a downside break formula for buy? if u still want, i can try. btw pls read bb walk in bollinger on bollinger bands, where prices walk across the bb top during strong trends.
Attached Images
File Type: png bharti fut.png (11.4 KB, 42 views)
File Type: png idfc fut.png (11.4 KB, 24 views)
Reply With Quote
  #4  
Old 30th January 2007, 01:18 PM
Member
 
Join Date: Sep 2005
Posts: 1,102
Blog Entries: 1
Thanks: 9
Thanked 25 Times in 17 Posts
beginner_av will become famous soon enoughbeginner_av will become famous soon enough
Reputation: 107
Default Re: Need help for AFL

// Weekly MACD Histogran
_SECTION_BEGIN("Weekly MACD");
TimeFrameSet( inWeekly );
MACDw = MACD( 3, 10 ) - Signal( 3, 10, 16 );
MACDwLINE = MACD( 3, 10 ) ;
MACDwSignal = Signal( 3, 10, 16);
TimeFrameRestore();
Plot(MACDw,"MACD Weekly",colorDarkOliveGreen,styleHistogram);
Plot(MACDwLINE,"MACD Weekly Line",colorRed,styleLine);
Plot(MACDwSignal,"MACD Weekly Signal Line",colorBlue,styleLine);
_SECTION_END();


please get it checked by someone like sunil or praveen

daily macd

// Daily MACD Histogram
_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2),
ParamColor("MACD color", colorRed ), ParamStyle("MACD style") );
Plot( sl = Signal(r1,r2,r3), "Signal" + _PARAM_VALUES(), ParamColor("Signal
color", colorBlue ), ParamStyle("Signal style") );
Plot( ml-sl, "MACD Histogram", ParamColor("Histogram color", colorBlack ),
styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleNoLabel,
maskHistogram ) );
_SECTION_END();

this was posted by someone in this forum...is it casoni?
Reply With Quote
  #5  
Old 30th January 2007, 01:34 PM
Member
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tican2 is on a distinguished road
Reputation: 20
Default Re: Need help for AFL

hi beginner_av,

Thanks you for your help and comments . I understand the risk there . What i am after is the coding for the reverse ( buy position ) .
Thanks
Tican2
Reply With Quote
  #6  
Old 30th January 2007, 01:55 PM
Member
 
Join Date: Sep 2005
Posts: 1,102
Blog Entries: 1
Thanks: 9
Thanked 25 Times in 17 Posts
beginner_av will become famous soon enoughbeginner_av will become famous soon enough
Reputation: 107
Default Re: Need help for AFL

by reverse position do u mean buy when prices go and hit bb bottom and then gap up?
Reply With Quote
  #7  
Old 30th January 2007, 03:05 PM
Member
 
Join Date: May 2006
Location: Bangalore
Posts: 911
Thanks: 0
Thanked 8 Times in 2 Posts
bvpraveen is on a distinguished road
Reputation: 40
Default Re: Need help for AFL

Quote:
Originally Posted by beginner_av View Post
by reverse position do u mean buy when prices go and hit bb bottom and then gap up?
Hello Avi,

I think Tican is asking to edit the AFL, so that it gives BUY signal. If you see the AFL, it gives SELL signal alone.

I've not went through the AFL; so can't comment much on it.

Praveen.
Reply With Quote
  #8  
Old 30th January 2007, 04:21 PM
Member
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tican2 is on a distinguished road
Reputation: 20
Default Re: Need help for AFL

hi beginner_av ,

You are correct , that is what i mean .
Thanks
Tican
Reply With Quote
  #9  
Old 30th January 2007, 04:21 PM
Member
 
Join Date: Sep 2005
Posts: 1,102
Blog Entries: 1
Thanks: 9
Thanked 25 Times in 17 Posts
beginner_av will become famous soon enoughbeginner_av will become famous soon enough
Reputation: 107
Default Re: Need help for AFL

This is the exact reverse of what u have given - buy when prices go and hit bb bottom and then gap up


fCl = Ref(C,-1); // close yesterday
fHigh = Ref(H,-1); // high yesterday
fLow = Ref(L,-1); // low yesterday
fAdvDrop = Ref(C,-2) - fCl; // difference between yesterday and day before's close
//where yesterday's close < day b4 yesterday close

fAtr = Ref(ATR(8),-1); // last 8 days Average True Range till yesterday
diffHl = fHigh-fLow; // difference between yesterday's high and low (range)
fStoch = Ref(StochD(14),-1); //14 day slow stochastics as on yeaterday

fOpCond = fCl + 0.5 * fAtr; // opening condition gap up by .5 times ATR(8) from yesterday's Close

fOp = Ref(O,0); //today's opening

fStopLoss = fLow - 0.5 * fAtr; // stp loss at yesterday's low - .5 times ATR(8)

fBBandBottom=Ref(BBandBot(C,20,2),-1); //bollinger band bottom *****

// The stock must first puncture and close outside (below) the lower Bollinger Band
bbBottomBuy = IIf( fCl < fBBandBottom AND
// The closer the closing price is to the low of the day, the better.
fCl < (fHigh - 0.75 * diffHL ) AND
// And the bigger the previous day's decline, the better
fAdvDrop > (1.5 * fAtr) AND
// On the following day, the stock must 'gap' up above the prior day's close.
// This 'gap up' is crucial as it serves as the most important criteria of
// the entire strategy.

fOp > fOpCond AND

// Oversold condition added
fStoch < 80, 1, 0 );


/* Exploration Columns for Sorting */

AddColumn(fOp, "Open", 1.2);
AddColumn(fOpCond, "OpenCond", 1.2);
AddColumn(fStopLoss, "StopLoss", 1.2);
AddTextColumn(FullName(), "Stock Name");


Filter = bbBottomBuy == 1;

Sell = 0;
Buy = bbBottomBuy>0;


in case u r looking for something else, do let me know.
Reply With Quote
  #10  
Old 30th January 2007, 04:33 PM
Member
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
tican2 is on a distinguished road
Reputation: 20
Default Re: Need help for AFL

hi Avi,

Thank you so much . That is what i really need . You have been a great help.
Just a quick question . In the code you mentioned :
// Oversold condition added
fStoch < 80, 1, 0 );

Don't you mean :
// Oversold condition added
fStoch < 30, 1, 0 );


Thanks
Tican
Reply With Quote
Sponsored Links

Reply

Bookmarks


Advertise Here


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

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


All times are GMT +5.5. The time now is 12:54 PM.

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.MasterOfTrading.com