PureBytes Links
Trading Reference Links
|
Hi,
Disappearing signals should usually be treated as a giant flashing sign that you have one or more future leaks in your code.
Every one of the functions in the AFL you posted looks into the future. You cannot create a valid trade strategy from this code. At least not without adding a bunch of code to introduce delays beyond which you must wait before being able to accept the signal.
Note, all of the following appear in your code and are usually associated with a future leak:
Ref(..., X) where X is a positive number
LastValue(...)
Peak(...)
PeakBars(...)
Trough(...)
TroughBars(...)
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "kevinkee20" <kevinkee20@xxx> wrote:
>
> Hi,
> I would like to use trendline breakout as part of my trading system.
> I have added buy/sell signals to the Advanced Trendlines AFL in the AB library (full AFL attached below). A buy signal is triggered when Close crosses up the resistance line; and a sell signal is triggered when Close goes below the support line.
>
> However I am having problem backtesting the AFL below because the buy/sell signals will only stay as long as the trendlines do not change (i.e. the close price of the buy/sell trade bar remains above/below the trendlines). But as soon as the trendlines update themselves (as the original AFL is designed to do), the buy/sell signals disappear - this is because now the trade bar no longer crosses the new trendlines.
>
> Is there a way to get around this problem and make the buy/sell signals stay permanent after they are triggered ? Would anyone be able to please help ?
>
> I tried using a new array to store the buy/sell signals but it doesn't seem to work, e.g.
> for( i = 2; i < BarCount; i++ )
> {
> if( Buy[i-1]==1 OR nbuy[i-1]==1) nbuy[i-1]=1;
> if( Short[i-1]==1 OR nshort[i-1]==1) nshort[i-1]=1;
> }
> then do something with nbuy/nshort.
>
> Thanks.
> Kevin
>
>
>
>
> _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 = LastValue(IIf(ADX(14)>25, 0.1, 0.5));
> Lines = Param("Lines?", 1, 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);
> xa = x;
> }
> 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);
> xa = x;
> }
> 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;
>
> Buy = Cross(C, x) ;
> Short = Cross(xa, C);
> Cover = Buy;
> Sell = Short;
> PlotShapes( (Buy) * shapeUpArrow + (Short) * shapeDownArrow, colorBlack, 0,IIf( (Buy), L,H ),-20 );
>
>
>
> _SECTION_END();
>
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|