var Y, X, Y1, Y2, Y3, Y4: float;
var BBOUGHT: boolean;
var NSMA, NPANE, NCOUNT, BAR, I, COLOR, LINE, XSERIES, HILO, X1, X2, X3, X4: integer;
{ Wealth-Lab's Master System }
{ Plot a 14 day Moving Average }
nSMA := SMASeries( #Close, 14 );
PlotSeries( nSMA, 0, 044, 1 );
{ Plot 14 day CMO in new chart pane }
nPane := CreatePane( 60, TRUE, FALSE );
PlotSeries( CMOSeries( #Close, 14 ), nPane, 009, 0 );
DrawText( 'CMO 14', nPane, 4, 4, 006, 8 );
DrawHorzLine( 0, nPane, 666, 0 );
DrawHorzLine( 50, nPane, 666, 1 );
DrawHorzLine( -50, nPane, 666, 1 );
{ Some variables }
nCount := BarCount();
bBought := false;
{ Max 1000 shares per position }
SetShareCap( 1000 );
{ Execute the Trading System }
for Bar := 15 to BarCount() - 1 do
begin
if CumDown( Bar, #Close, 4 ) = 0 then
bBought := false;
if CumDown( Bar, #Close, 4 ) >= 9 then
if not bBought then
begin
BuyAtMarket( Bar + 1, '');
bBought := true;
end;
if ( CumUp( Bar, #Close, 4 ) >= 9 ) OR ( CMO( Bar, #Close, 14 ) >= 50 ) then
begin
for i := 0 to PositionCount() - 1 do
if PositionActive( i ) then
SellAtMarket( Bar + 1, i, '');
end;
end;
{ Below is tbui's Support/Resistance PlugIn -
It displays the most recent up and down trendlines
Parameters
--------------------------------------------------------}
Bar := BarCount() - 20;
Color := 900;
Line := 0;
{High Low AVERAGE
For the last 50 bars:
. Calculate the diff. between PriceHight and PriceLow
. Normalize it with PriceClose
. Put it into a new series
. Total all them up
. Average them with highest and the lowest excluded.
---------------------------------------------------------}
x := 0 ;
xSeries := CreateSeries();
For i := Bar - 50 to Bar do
Begin
y := (PriceHigh(i) - PriceLow(i)) / PriceClose(i);
y := y * 100 ;
SetSeriesValue( i, xSeries, y );
x := x + y;
end;
x := x - Highest(Bar, xSeries, 50);
x := x - Lowest(Bar, xSeries, 50);
hilo := Round(x / 48 );
{ RESISTANCE LINE
. Calculate coordinates of 2 consecutive peaks using
hilo as ReversalPct.
. Extrapolate the coordinates to the current bar, also
10 bars to the left.
. Draw a resistance line.
---------------------------------------------------------}
y1 := Peak( Bar, #High, hilo);
x1 := Peakbar( Bar, #High, hilo);
y2 := Peak( x1, #High, hilo * 2);
x2 := Peakbar( x1, #High, hilo * 2);
If (x2 <> x1) then
Begin
x3 := x1 + 20;
if (x3 > (BarCount() - 1)) then x3 := BarCount() - 1;
y3 := (((y2 - y1) * (x3 - x1)) / (x2 - x1)) + y1;
x4 := x2 - 10;
y4 := (((y2 - y1) * (x4 - x1)) / (x2 - x1)) + y1;
DrawLine( x3, y3, x4, y4, 0, Color, Line);
end;
{ SUPPORT LINE
. Same as above
---------------------------------------------------------}
y1 := Trough( Bar, #Low, hilo);
x1 := Troughbar( Bar, #Low, hilo);
y2 := Trough( x1, #Low, hilo * 2);
x2 := Troughbar( x1, #Low, hilo * 2);
If (x2 <> x1) then
Begin
x3 := x1 + 20;
if (x3 > (BarCount() - 1)) then x3 := BarCount() - 1;
y3 := (((y2 - y1) * (x3 - x1)) / (x2 - x1)) + y1;
x4 := x2 - 10;
y4 := (((y2 - y1) * (x4 - x1)) / (x2 - x1)) + y1;
DrawLine( x3, y3, x4, y4, 0, Color, Line);
end;
{ END OF STUDY
==========================================================}