![]() |
|
| Discuss Trendline Indicator at the AmiBroker within the Traderji.com - Discussion forum for Stocks Commodities & Forex; Kind Greetings, I have been trying to code an AFL indicator that will render a ... |
|
|||||||
| Notices |
![]() |
|
|
Thread Tools |
| Sponsored Links |
|
#1
|
|||
|
|||
|
Kind Greetings, I have been trying to code an AFL indicator that will render a trendline that will be used as a support-resistance reference line. The trendline would be drawn through yesterdays 9:30AM candle (open+close)/2 and yesterdays 4:00PM candle (open+close)/2 and extend into today. I have found an automatic trendline formula in the AFL library and have been trying to modify it by removing the trough function references which has worked but I'm having trouble trying to get the trendline to go through the specific times. I'm not sure which function reference to use to give me the desired time points. I can get a trendline to plot but it only works if I use constants for the start and end values. Any help on this would be greatly appreciated. Thank you, All the best convertah x = Cum(1); perchg = 0.3*LastValue( Highest( ROC( Low, 50 ) )); startvalue = LastValue( Trough( Low, perchg, 1 ) ); endvalue1 = LastValue( Trough( Low, perchg, 2 ) ); startbar = LastValue( ValueWhen( Low == startvalue, x, 1 ) ); endbar = LastValue( ValueWhen( Low == endvalue1, x, 1 ) ); Aa = (endvalue1-startvalue)/(endbar-startbar); b = startvalue; trendline = Aa * ( x - startbar ) + b; Plot( Close, "Price", colorBlue, styleCandle ); Plot( IIf( x >= endbar, trendline, Null ), "Trendline", colorRed ); |
| Sponsored Links |
|
#2
|
|||
|
|||
|
Pls find herewith afl for Advanced Trendlines which i got from Amibroker fan.
_SECTION_BEGIN("Advanced Trend Lines"); function TD_Supply() { return ( H > Ref(H, 1) AND H > Ref(H, -1) AND H > Ref(C, -2)); } function TD_Demand() { return ( L < Ref(L, 1) AND L < Ref(L, -1) AND L < Ref(C, -2)); } function IsTD_Supply(n) { n = (BarCount - 1) - n; return LastValue( Ref(H, -n) > Ref(H, -n+1) AND Ref(H, -n) > Ref(H, -n-1) AND Ref(H, -n) > Ref(C, -n-2)); } function IsTD_Demand(n) { n = (BarCount - 1) - n; return LastValue( Ref(L, -n) < Ref(L, -n+1) AND Ref(L, -n) < Ref(L, -n-1) AND Ref(L, -n) < Ref(C, -n-2)); } function GetXSupport(Lo, Percentage, Back) { return ((BarCount - 1) - LastValue(TroughBars(Lo, Percentage,Back))); } function GetYSupport(Lo, Percentage, Back) { return (LastValue(Trough(Lo, Percentage, back))); } function GetXResistance(Hi, Percentage, Back) { return ((BarCount - 1) -LastValue(PeakBars(Hi, Percentage, Back))); } function GetYResistance(Hi, Percentage, Back) { return (LastValue(Peak(Hi, Percentage, Back))); } //////////////////////////////////////////////////////////////////////// //Parameters Percentage = Param("Percentage", 0.5, 0.01, 100. ,0.01); Lines = Param("Lines?", 5, 1, BarCount-2); DrawR = ParamList("Resistance Points", "Off|High to High|High to Low", 1); DrawS = ParamList("Support Points", "Off|Low to Low|Low to High", 1); DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes", 1); Method = ParamToggle("Method", "TD Points|ZigZag",1); ShowTDP = ParamToggle("Show TD Pionts", "No|Yes"); AllOrDownR = ParamToggle("Resistance Direction", "All|Down"); AllOrUpS = ParamToggle("Support Direction", "All|Up"); //////////////////////////////////////////////////////////////////////// Main = C; Con = ConS = ConR = 1; if(DrawS=="Low to Low") { Support1 = L; Support2 = L; } else { Support1 = L; Support2 = H; } if(DrawR=="High to High") { Resistance1 = H; Resistance2 = H; } else { Resistance1 = H; Resistance2 = L; } //////////////////////////////////////////////////////////////////////// //Plotting Area Plot(Main, "", IIf(C>O,colorGreen, colorRed), styleBar); if(DrawAllLines) for(i = 2; i<=Lines+1; i++) { if(DrawS!="Off") { x0 = GetXSupport(Support1, Percentage, i); x1 = GetXSupport(Support2, Percentage, i-1); y0 = GetYSupport(Support1, Percentage, i); y1 = GetYSupport(Support2, Percentage, i-1); x = LineArray(x0, y0, x1, y1, 1); if(!Method) Con = (IsTD_Demand(x0) AND IsTD_Demand(x1)); if(AllOrUpS) ConS = y0 < y1; if(Con AND ConS) Plot(x, "", colorLightBlue, styleLine|styleThick); } if(DrawR!="Off") { x0 = GetXResistance(Resistance1, Percentage, i); x1 = GetXResistance(Resistance2, Percentage, i-1); y0 = GetYResistance(Resistance1, Percentage, i); y1 = GetYResistance(Resistance2, Percentage, i-1); x = LineArray(x0, y0, x1, y1, 1); if(!Method) Con = (IsTD_Supply(x0) AND IsTD_Supply(x1)); if(AllOrDownR) ConR = y0 > y1; if(Con AND ConR) Plot(x, "", colorRed , styleLine|styleThick); } } else { if(DrawS!="Off") { x0 = GetXSupport(Support1, Percentage, Lines+1); x1 = GetXSupport(Support2, Percentage, Lines); y0 = GetYSupport(Support1, Percentage, Lines+1); y1 = GetYSupport(Support2, Percentage, Lines); x = LineArray(x0, y0, x1, y1, 1); if(!Method) Con = (IsTD_Demand(x0) AND IsTD_Demand(x1)); if(AllOrUpS) ConS = y0 < y1; if(Con AND ConS) Plot(x, "", colorLightBlue, styleLine|styleThick); } if(DrawR!="Off") { x0 = GetXResistance(Resistance1, Percentage, Lines+1); x1 = GetXResistance(Resistance2, Percentage, Lines); y0 = GetYResistance(Resistance1, Percentage, Lines+1); y1 = GetYResistance(Resistance2, Percentage, Lines); x = LineArray(x0, y0, x1, y1, 1); if(!Method) Con = (IsTD_Supply(x0) AND IsTD_Supply(x1)); if(AllOrDownR) ConR = y0 > y1; if(Con AND ConR) Plot(x, "", colorRed , styleLine|styleThick); } } if(ShowTDP) { PlotShapes(TD_Supply()*shapeSmallCircle, colorRed, 0, H, H*.001); PlotShapes(TD_Demand()*shapeSmallCircle, colorGreen, 0, L, -L*.001); } Title =FullName()+" ({{NAME}})\n{{DATE}}\n"+"Open: "+O+", Hi: "+H+", Lo: "+L+", Close: "+C; _SECTION_END(); Last edited by raakesh; 13th October 2008 at 02:24 AM. Reason: incomplete |
|
#3
|
|||
|
|||
|
raakesh,
Thanks for the code I will try it. The current code which I have for the trendline through the beginning and ending candle of the day (open+close)/2 is: x = Cum(1); startvalue = LastValue(Ref( (O+C)/2, -157 )); endvalue1 = LastValue(Ref( (O+C)/2, -79 )); startbar = LastValue( ValueWhen( (O+C)/2 == startvalue, x, 1 ) ); endbar = LastValue( ValueWhen( (O+C)/2 == endvalue1, x, 1 ) ); Aa = (endvalue1-startvalue)/(endbar-startbar); b = startvalue; trendline = Aa * ( x - startbar ) + b; Plot( Close, "Price", colorBlue, styleCandle ); Plot( trendline, "Trendline", colorRed ); All this code does is count back from the last 5 minute candle of today and only works if today is finished. This code needs to be refined and I will post more as I figure out what to do. This simple trendline when coded correctly acts as a good support-resistance indicator for future price action. Thank you, convertah |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
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.