[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] Gordon Sutherland "JOHN CLAYBURG Suport & Restance"



PureBytes Links

Trading Reference Links

Jack,

 

I have not used the code for nearly twelve months and of course AB has developed since then (as hopefully have I). As I recall, you needed to run one lot of code for the Exploration/Backtesting and use the code as presented yesterday for Plots. FWIW, I attach the Exploration/Backtesting code immediately below and at the very bottom of this email is the Plot code as submitted yesterday. This is a Long and Short system combined but you will need to set your own Stops in Settings for your exits etc.

 

I hope the size of this posting is not a nuisance for the rest of the Group!

 

/* JOHN CLAYBURG BASED SUPPORT/RESISTANCE LINES

   an extension concept by Gordon Sutherland to use Trendline Extensions

   instead of horizontal S & R Lines

   Coded by Bob Johnson and Gordon Sutherland May 2004

       (Bob kindly did the tricky extensions and looping code for me)       */

 

/* PARAMETERS */

ColLSC = ParamColor("SU Color",colorOrange);

ColLRC = ParamColor("RE Color",colorBlue);

 

/* CATEGORY 3 SUPPORT BREAKOUT TRIGGER FOR SHORTS: */

LL_3_6 = Ref(L,-6) > Ref(L,-3);

LL_3_5 = Ref(L,-5) > Ref(L,-3);

LL_3_4 = Ref(L,-4) > Ref(L,-3);

LL_3_2 = Ref(L,-2) > Ref(L,-3);

LL_3_1 = Ref(L,-1) > Ref(L,-3);

LL_3_0 = L > Ref(L,-3);

Cat3Sup = LL_3_6 AND LL_3_5 AND LL_3_4 AND LL_3_2 AND LL_3_1 AND LL_3_0;

 

/* SUPPORT LINE ("SC") */

y0=ValueWhen(Cat3Sup,Ref(L,-3),2);

y1=ValueWhen(Cat3Sup,Ref(L,-3),1);

x0=ValueWhen(Cat3Sup,BarIndex(),2)-3;

x1=ValueWhen(Cat3Sup,BarIndex(),1)-3;

 

// looking into the future here, but it is

// only applied to historical plots to determine

// the length of the extension.

 

xsf=ValueWhen(Cat3Sup,BarIndex(),0)-3;

 

/* CATEGORY 3 RESISTANCE BREAKOUT TRIGGER FOR LONGS: */

HH_3_6 = Ref(H,-6) < Ref(H,-3);

HH_3_5 = Ref(H,-5) < Ref(H,-3);

HH_3_4 = Ref(H,-4) < Ref(H,-3);

HH_3_2 = Ref(H,-2) < Ref(H,-3);

HH_3_1 = Ref(H,-1) < Ref(H,-3);

HH_3_0 = H < Ref(H,-3);

Cat3Res = HH_3_6 AND HH_3_5 AND HH_3_4 AND HH_3_2 AND HH_3_1 AND HH_3_0;

 

y2=ValueWhen(Cat3Res,Ref(H,-3),2);

y3=ValueWhen(Cat3Res,Ref(H,-3),1);

x2=ValueWhen(Cat3Res,BarIndex(),2)-3;

x3=ValueWhen(Cat3Res,BarIndex(),1)-3;

 

// another look into the future.

 

xrf=ValueWhen(Cat3Res,BarIndex(),0)-3;

 

Plot(C,"C", colorBlack, styleCandle);

 

// This bit is used to plot the buy/short arrows.  The loops below generate

// extraneous buys at the start of new resistance lines.  Reason unknown

// so far.

 

ms = (y1 - y0)/(x1 - x0); // simple slope of support

mr = (y3 - y2)/(x3 - x2); // simple slope of support

 

exts=BarsSince(Cat3sup);

supline=y1 + ms * (3 + exts);

 

//Plot(supline,"Cat3Sup",colorWhite,styleLine);

 

extr=BarsSince(Cat3Res);

resline=y3 + mr * ( 3 + extr);

ResSlopeUp = resline > y3; // Try adding Rule that slope of ResLine must be Up

SupSlopeDn = supline < y1; // Try adding Rule that slope of SupLine must be Down

 

TradeDlrs = Volume * Close;

Liquid = Sum(IIf(Volume < 1,1,0),20);

Liquidity = MA(TradeDlrs,20) >= 60000 AND Liquid < 3;

 

Buy=Cross(C,resline) AND ResSlopeUp AND Liquidity;

Short=Cross(supline,C) AND SupSlopeDn AND Liquidity;

PlotShapes(IIf(Short,shapeHollowDownArrow,shapeNone),colorRed,0,H,-10);

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-10);

 

 

//     END OF THE SIGNALS SECTION ////

 

// EXPLORATION AND SYSTEM TEST REPORTS AREA //////////////////////////////////////////////////

 

Sell = 0; Cover = 0;

//BuyPrice = ShortPrice == Open; SellPrice = CoverPrice == Open;

 

//SetTradeDelays(1,1,1,1);

 

// POSITION SIZING MODEL EXAMPLES:

// PositionSize = 10000; //invest $10,000 in every trade

 

       PosQty = 10; // Defines how many open positions you want - this overrides the "Settings"

       SetOption("MaxOpenPositions", PosQty );

       PositionSize = -100/PosQty; // invest 100% of portfolio equity divided by max. position count

 

// PositionSize = -0.5 * BuyPrice/Ref((1.25 * EMA(ATR(1),2)),-1);   

// (Van Tharp-style AmiBroker uses Wilder's Smoothing ergo use WMA(ATR(1),7) for 7 period WMA

 

PositionScore = 100-RSI(); // 'Tie-breaker method'prefer stocks that have low RSI;

 

// NumColumns = 0;

Filter = Buy OR Sell;

 

AddTextColumn(FullName(),"Full name",77,colorPlum, IIf(Close < 1.00,colorYellow,colorDefault ) );

Result = WriteIf(Buy,"Buy","Sell");

AddTextColumn(Result,"Trade", formatChar, IIf(Buy,colorDarkGreen,colorRed ), IIf                                                                                                                                                                              (Sell,colorPink,colorLime));

AddColumn(Ref(Close,-1),"Y-Close",1.4, IIf( ROC(Ref(C,-1),1)>= 0,colorDarkGreen, colorRed ),50 );

AddColumn(Open,"Open",1.4,IIf( ROC(Open, 1 ) >= 0, colorDarkGreen, colorRed ) );

AddColumn(High,"High",1.4,IIf( ROC(High, 1 ) >= 0, colorDarkGreen, colorRed ) );

AddColumn(Low,"Low",1.4,IIf( ROC(Low, 1 ) >= 0, colorDarkGreen, colorRed ) );

AddColumn( Close, "Close", 1.4, IIf( ROC(C, 1 ) >= 0, colorDarkGreen, colorRed ),50 );

AddColumn( ROC( Close, 1 ), "ROC(1)", 1.2, IIf( ROC(C, 1 ) >= 0, colorDarkGreen, colorRed));

AddColumn( Volume, "Volume", 10.0, IIf( ROC(V, 1 ) >= 0, colorDarkGreen, colorRed ) );

AddColumn( resline, "Break L", 10.4, colorDarkBlue,37 );

AddColumn( ((Close-resline)/resline)*100, "L %", 10.2, colorDarkBlue,37 );

AddColumn( supline, "Break S", 10.4, colorRed,40 );

AddColumn( ((Close-supline)/Close)*100, "S %", 10.2, colorRed,40 );

 

Regards,

 

Gordon Sutherland

 

-----Original Message-----
From: ckinsey2003 [mailto:ckinsey2003@xxxxxxxxx]
Sent:
Sunday, 6 March 2005 7:39 a.m.
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Gordon Sutherland "JOHN CLAYBURG Suport & Restance"

 


When I run an Explore or Backtest with your code, I do not get any
output in AA, even though the Graph displays many trend lines & BUY
SELL arrows?  Do you have the same experiance for stocks ??

Jack Kinsey

/* JOHN CLAYBURG BASED SUPPORT/RESISTANCE LINES
Coded by GBS May 2004
/* CATEGORY 3 SUPPORT BREAKOUT TRIGGER FOR SHORTS: */

/* PARAMETERS */

ColLSC = ParamColor("SU Color",colorOrange);
ColLRC = ParamColor("RE Color",colorBlue);

LL_3_6 = Ref(L,-6) > Ref(L,-3);
LL_3_5 = Ref(L,-5) > Ref(L,-3);
LL_3_4 = Ref(L,-4) > Ref(L,-3);
LL_3_2 = Ref(L,-2) > Ref(L,-3);
LL_3_1 = Ref(L,-1) > Ref(L,-3);
LL_3_0 = L > Ref(L,-3);
Cat3Sup = LL_3_6 AND LL_3_5 AND LL_3_4 AND LL_3_2 AND LL_3_1 AND
LL_3_0;

/* SUPPORT LINE ("SC") */
y0=ValueWhen(Cat3Sup,Ref(L,-3),2);
y1=ValueWhen(Cat3Sup,Ref(L,-3),1);
x0=ValueWhen(Cat3Sup,BarIndex(),2)-3;
x1=ValueWhen(Cat3Sup,BarIndex(),1)-3;

// looking into the future here, but it is
// only applied to historical plots to determine
// the length of the extension.
xsf=ValueWhen(Cat3Sup,BarIndex(),0)-3;

/* CATEGORY 3 RESISTANCE BREAKOUT TRIGGER FOR LONGS: */
HH_3_6 = Ref(H,-6) < Ref(H,-3);
HH_3_5 = Ref(H,-5) < Ref(H,-3);
HH_3_4 = Ref(H,-4) < Ref(H,-3);
HH_3_2 = Ref(H,-2) < Ref(H,-3);
HH_3_1 = Ref(H,-1) < Ref(H,-3);
HH_3_0 = H < Ref(H,-3);
Cat3Res = HH_3_6 AND HH_3_5 AND HH_3_4 AND HH_3_2 AND HH_3_1 AND
HH_3_0;

y2=ValueWhen(Cat3Res,Ref(H,-3),2);
y3=ValueWhen(Cat3Res,Ref(H,-3),1);
x2=ValueWhen(Cat3Res,BarIndex(),2)-3;
x3=ValueWhen(Cat3Res,BarIndex(),1)-3;

// another look into the future.
xrf=ValueWhen(Cat3Res,BarIndex(),0)-3;

Plot(C,"C", colorBlack, styleCandle);

extendedSup=0;
extendedRes=0;

NullY0=IsNull(y0);
NullY2=IsNull(y2);

for ( i = BarCount -1 ; i > 7 ; i-- ) {
if ( !NullY0[i] ){ // only plot lines when enough datapoints avail.
if ( x0[i] != x0[i-1] ) {

ms = (y1[i] - y0[i])/(x1[i] - x0[i]); // simple slope of support

if ( NOT extendedSup ) { // Haven't extended one yet

extendedSup = 1;
Line1 = LineArray( x0[i], y0[i], x1[i] + 3, y1[i] + (3 *
ms),0,True);
Plot(Line1,"",ColLSC,styleLine);

Line2 = LineArray( x1[i] + 3, y1[i] + (3 * ms), x1[i] + 4,y1
[i] + (4 * ms), 1,True);
Plot(Line2,"Cat3Sup",colorWhite,styleLine+styleNoRescale);

Sell=Cross(Line2,C);
PlotShapes(IIf
(Sell,shapeHollowDownArrow,shapeNone),colorRed,0,H,-10);

} else { // old Cat3Sup lines, use 'look ahead' extensions

Line3 = LineArray( x0[i], y0[i], x1[i] + 3, y1[i] + (3 *
ms),0,True);
Plot(Line3,"",colorPink,styleLine);

Line4 = LineArray( x1[i] + 3, y1[i] + (3 * ms),
xsf[i] + 3, y1[i] + ms * (xsf[i] -
x1[i] + 3), 0,True);
Plot(Line4,"Cat3Sup",colorWhite,styleLine+styleNoRescale);

Sell=Cross(Line4,C);
PlotShapes(IIf
(Sell,shapeHollowDownArrow,shapeNone),colorRed,0,H,-10);
}
}
}

if ( !NullY2[i] ){ // only plot lines when enough datapoints avail.
if ( x2[i] != x2[i-1] ) {

mr = (y3[i] - y2[i])/(x3[i] - x2[i]); // simple slope of resistance

if ( NOT extendedRes ) { // Haven't extended one yet

extendedRes = 1;
Line5= LineArray( x2[i], y2[i], x3[i] + 3, y3[i] + (3 *
mr),0,True);
Plot(Line5,"",ColLRC,styleLine);

Line6 = LineArray( x3[i] + 3, y3[i] + (3 * mr), x3[i] + 4,y3
[i] + (4 * mr), 1,True);
Plot(Line6,"Cat3Sup",colorWhite,styleLine+styleNoRescale);

Buy=Cross(C,Line6);
PlotShapes(IIf
(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-10);

} else { // old Cat3Sup lines, use 'look ahead' extensions

Line7= LineArray( x2[i], y2[i], x3[i] + 3, y3[i] + (3 *
mr),0,True);
Plot(Line7,"",colorBlue,styleLine);

Line8 = LineArray( x3[i] + 3, y3[i] + (3 * mr),
xrf[i] + 3, y3[i] + mr * (xrf[i] -
x3[i] + 3), 0,True);
Plot(Line8,"Cat3Sup",colorWhite,styleLine+styleNoRescale);

Buy=Cross(C,Line8);
PlotShapes(IIf
(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-10);
}
}
}
}

NumColumns = 0;

// EXPLORATION EXAMPLE:
Filter = Buy OR Sell;
AddTextColumn(FullName(),"Full name",77,colorPlum, IIf(Close <
1.00,colorYellow,colorDefault ) );
result = WriteIf(Buy,"Buy","Sell");
AddTextColumn(result,"Trade", formatChar, IIf
(Buy,colorDarkGreen,colorRed ),
IIf(Sell,colorPink,colorLime));
AddColumn(Ref(Close,-1),"Y-Close",1.4, IIf( ROC(Ref(C,-1),1)>=
0,colorDarkGreen, colorRed ),50 );
AddColumn(Open,"Open",1.4,IIf( ROC(Open, 1 ) >= 0, colorDarkGreen,
colorRed ) );
AddColumn(High,"High",1.4,IIf( ROC(High, 1 ) >= 0, colorDarkGreen,
colorRed ) );
AddColumn(Low,"Low",1.4,IIf( ROC(Low, 1 ) >= 0, colorDarkGreen,
colorRed ) );
AddColumn( Close, "Close", 1.4, IIf( ROC(C, 1 ) >= 0, colorDarkGreen,
colorRed ),50 );
AddColumn( ROC( Close, 1 ), "ROC(1)", 1.2, IIf( ROC(C, 1 ) >= 0,
colorDarkGreen, colorRed));
AddColumn( Volume, "Volume", 10.0, IIf( ROC(V, 1 ) >= 0,
colorDarkGreen, colorRed ) );
AddColumn( y3, "TL Break", 10.4, colorDarkBlue,37 );
AddColumn( ((Close-y3)/y3)*100, "TL Break %", 10.2,
colorDarkBlue,37 );
AddColumn( y1, "TL Break", 10.4, colorRed,40 );
AddColumn( ((Close-y1)/Close)*100, "TL Break %", 10.2, colorRed,40 );





Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html






Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Yahoo! Groups Sponsor
ADVERTISEMENT
click here


Yahoo! Groups Links