|
System Code for Trading
System Labs |
Back
to main code page
September
2000, Hybrid system No. 1
October 2000, RS System No. 1
November 2000, Pullback system No. 1
January/February 2001, Meander system
March 2001, Relative strength bands
June 2001, Old faithful
July 2001, Volume weighted average
August 2001, A bad compromise
October 2001, Beta value
November 2001, Harris 3L-R pattern variation
December 2001, Deep pockets system
January 2002, Pair-trade system
February 2002, Pair-trade II system
April 2002, Pair-trade III system
May 2002, Pristine variation
June 2002, Expert exits
July 2002, Moving average crossover
August 2002, Reverse bandwagon
September 2002, Low-volatility breakout
October 2002, Volatility breakout system
November 2002, Counterpunch stock system
December 2002, Volatility benchmark system
January 2003, Long-term volatility breakout
system
February 2003, Dynamic breakout system
May
2004, Short-term WMA crossover system
May
2004, Another oddball system (Futures Trading System Lab)
June
2004, QQQ crash system
June 2004, Experimenting with exits
(Futures Trading System Lab)
July
2004, Indicator-time combination (ITC) (Futures System Trading
Lab)
August
2004, RSI Trend system (Futures Trading System Lab)
June
2006, Channel Midpoint indicator
Active
Trader is working with various software companies to provide
code for Trading System Labs not shown here.
September
2000, TradeStation code:
Inputs:
LookBack(9), WhereToBuy(0.5);
Variables: HighValue(0), LowValue(99999), BuyValue(0);
LowValue = Lowest(Low, LookBack);
HighValue = Highest(High, LookBack);
BuyValue = (HighValue - LowValue) * WhereToBuy ;
If MarketPosition = 0 Then Begin
Buy tomorrow at BuyValue + LowValue Stop;
If Close < LowValue[1] Then
ExitLong at Open;
If BarsSinceEntry = 9 and OpenPositionProfit < 0 Then
ExitLong on Open;
Back
to top
October
2000, TradeStation code:
Variables: RelStr(0),
AvgRelStr(0), CalcRelStr(0), AvgOBV(0), CalcOBV(0),
CalcStr(0);
RelStr = IFF(AvgPrice = 0, 0, AvgPrice / AvgPrice Data2);
AvgRelStr = Average(RelStr, 5);
CalcRelStr = IFF(RelStr = 0, 0, RelStr / AvgRelStr);
AvgOBV = Average(OBV, 5);
CalcOBV = IFF(OBV = 0, 0, OBV / AvgOBV);
CalcStr = CalcRelStr * CalcOBV;
If CalcStr Crosses Above 1.0 and MarketPosition = 0 Then
Buy on Close;
If CalcStr Crosses Below 1 Then
ExitLong on Close;
If Close < EntryPrice * 0.96 Then
ExitLong on Close;
Back
to top
November
2000, TradeStation code:
Condition1 = MarketPosition
= 0 and Close Average(Close, 50) and High
High[1] and
(close[1] < close[2] and close[2] < close[3]);
If Condition1 = True Then
Buy tomorrow at Market;
ExitLong ("Stop") tomorrow at Lowest(Low, 2) Stop;
If PositionProfit 0 Then
ExitLong ("Exit") tomorrow at Market;
Back
to top
January/February
2001, TradeStation code:
Vars:
SumVS(0), AvgVS(0), DiffVS(0), StdVS(0), SetArr(0), SumArr(0),
DiffArr(0), VSLow(0), VSMid(0), VSHigh(0), RiskReward(0);
Array:
VS[20](0);
For
SetArr = 0 To 4 Begin
VS[SetArr * 4 + 0] = (Open[SetArr] - AvgPrice[SetArr + 1]) /
AvgPrice[SetArr + 1];
VS[SetArr * 4 + 1] = (High[SetArr] - AvgPrice[SetArr + 1]) /
AvgPrice[SetArr + 1];
VS[SetArr * 4 + 2] = (Low[SetArr] - AvgPrice[SetArr + 1]) /
AvgPrice[SetArr + 1];
VS[SetArr * 4 + 3] = (Close[SetArr] - AvgPrice[SetArr + 1])
/ AvgPrice[SetArr + 1];
End;
For
SumArr = 0 To 19 Begin
If SumArr = 0 Then
SumVS = 0;
SumVS = SumVS + VS[SumArr];
If SumArr = 19 Then
AvgVS = SumVS / 20;
For DiffArr = 0 To 19 Begin
If DiffArr = 0 Then
DiffVS = 0;
DiffVS = DiffVS + Square(VS[DiffArr] - AvgVS);
If DiffArr = 19 Then
StdVS = SquareRoot(DiffVS / 20);
End;
End;
VSLow
= AvgPrice * (1 + (AvgVS - StdVS * 2));
VSMid
= AvgPrice * (1 + AvgVS);
VSHigh
= AvgPrice * (1 + (AvgVS + StdVS * 2));
If MarketPosition = 0 Then Begin
Buy ("Buy") Tomorrow at VSLow Limit;
RiskReward = VSMid-VSLow;
End;
If
MarketPosition = 1 Then
ExitLong ("PT") Tomorrow At VSHigh Limit;
If
MarketPosition = 1 Then
ExitLong ("TS") Tomorrow At VSLow Stop;
If
Open Tomorrow >= VSLow Then
ExitLong ("SLa") From Entry ("Buy") At (VSLow-(VSMid-VSLow))
Stop;
If
Open Tomorrow < VSLow Then
ExitLong ("SLb") From Entry ("Buy") At (Open
Tomorrow-(VSMid-VSLow)) Stop;
Back
to top
March
2001, TradeStation code:
Vars:
MaLen(21), Ratio2(0), Ratio3(0), MaRatio2(0), MaRatio3(0), DiffMaRatio2(0),
DiffMaRatio3(0), ProdDiff(0), UpperProdDiff(0), LowerProdDiff(0);
Ratio2
= C / C Data2;
Ratio3 = C / C Data3;
MaRatio2
= Average(Ratio2, MaLen);
MaRatio3 = Average(Ratio3, MaLen);
DiffMaRatio2
= Ratio2 / MaRatio2;
DiffMaRatio3 = Ratio3 / MaRatio3;
ProdDiff
= DiffMaRatio2 * DiffMaRatio3;
UpperProdDiff = 1 + StdDev(ProdDiff, MaLen) * 1;
LowerProdDiff = 1 - StdDev(ProdDiff, MaLen) * 2;
If
MarketPosition = 0 and BarsSinceExit(1) > 1 and ProdDiff
> UpperProdDiff and ProdDiff > ProdDiff[2] Then
Buy ("Go Long") at Close;
If
MarketPosition = 1 and ProdDiff < ProdDiff[4] Then
ExitLong ("End Long") at Market;
ExitLong ("Trailing Long") tomorrow at Lowest(Low,
2) Stop;
If
MarketPosition = 0 and BarsSinceExit(1) > 1 and ProdDiff
< LowerProdDiff and ProdDiff < ProdDiff[2] Then
Sell ("Go Short") at Close;
If
MarketPosition = -1 and ProdDiff > ProdDiff[4] Then
ExitShort ("End Short") at Market;
ExitShort ("Trailing Short") tomorrow at Highest(High,
2) Stop;
If
BarsSinceEntry = 8 and OpenPositionProfit < 0 Then Begin
ExitLong at Market;
ExitShort at Market;
End;
Back
to top
June
2001, TradeStation code:
Input: VSStd(1);
Vars: SumVS(0), AvgVS(0), DiffVS(0), StdVS(0), SetArr(0), SumArr(0),
DiffArr(0), VSLow(0), VSMid(0), VSHigh(0), RiskReward(0);
Array: VS[20](0);
For SetArr = 0 To 4 Begin
VS[SetArr * 4 + 0] = (O[SetArr] - C[SetArr + 1]) / C[SetArr
+ 1];
VS[SetArr * 4 + 1] = (H[SetArr] - C[SetArr + 1]) / C[SetArr
+ 1];
VS[SetArr * 4 + 2] = (L[SetArr] - C[SetArr + 1]) / C[SetArr
+ 1];
VS[SetArr * 4 + 3] = (C[SetArr] - C[SetArr + 1]) / C[SetArr
+ 1];
End;
For SumArr = 0 To 19 Begin
If SumArr = 0 Then
SumVS = 0;
SumVS = SumVS + VS[SumArr];
If SumArr = 19 Then
AvgVS = SumVS / 20;
For DiffArr = 0 To 19 Begin
If DiffArr = 0 Then
DiffVS = 0;
DiffVS = DiffVS + Square(VS[DiffArr] - AvgVS);
If DiffArr = 19 Then
StdVS = SquareRoot(DiffVS / 20);
End;
End;
VSLow = C * (1 + (AvgVS - StdVS * VSStd));
VSMid = C * (1 + AvgVS);
VSHigh = C * (1 + (AvgVS + StdVS * VSStd));
If MarketPosition = 0 and BarsSinceExit(1) > 1 Then Begin
If Average(Close, 80) > Average(Close, 80)[11] Then
Buy ("Buy") tomorrow at VSLow limit;
If Average(Close, 80) < Average(Close, 80)[11] Then
Sell tomorrow at VSHigh limit;
End;
If BarsSinceEntry >= 1 Then Begin
ExitLong on Close;
ExitShort on Close;
End;
Back
to top
July
2001, TradeStation code:
Vars:
MaLen(9), AvgVolume(0), Turbo(0), InvTurbo(0), MaWeight(0),
TurboMA(0);
AvgVolume
= Average(V, MaLen);
Turbo
= (AvgVolume - Lowest(AvgVolume, MaLen)) / (Highest(AvgVolume,
MaLen) - Lowest(AvgVolume, Malen));
InvTurbo = 1 - Turbo;
If
MaLen > 2 Then MaWeight = (2 / (1 + MaLen)) Else MaWeight
= 0.67;
TurboMA
= TurboMA * InvTurbo + AvgPrice * Turbo;
If
Date < 1000401 Then Begin
If MarketPosition = 0 and C < TurboMA and TurboMA < TurboMA
[1] Then
Buy Tomorrow on Highest(High, 2) Stop;
End;
If
MarketPosition = 1 and C < TurboMA Then Begin
ExitLong on Close;
ExitLong Tomorrow on EntryPrice * 0.96 Stop;
End;
If Date >= 1000401 Then Begin
If MarketPosition = 0 and C > TurboMA and TurboMA > TurboMA
[1] Then
Sell Tomorrow on Lowest(Low, 2) Stop;
End;
If
MarketPosition = -1 and C > TurboMA Then Begin
ExitShort on Close;
ExitShort Tomorrow on EntryPrice * 1.04 Stop;
End;
Back
to top
August
2001, TradeStation code:
If
(Maxlist(High[3], Close[4]) > High[4] Or
Maxlist(High[3], Close[4]) > High[2] Or
Maxlist(High[3], Close[4]) > High[1]) and
Close < Close[1] and
Open Tomorrow <= High[3] Then
Buy 1 Contract Tomorrow on (Maxlist(High[3], Close[4]) * 1.001)
Stop;
If
(Minlist(Low[3], Close[4]) < Low[4] Or
Minlist(Low[3], Close[4]) < Low[2] Or
Minlist(Low[3], Close[4]) < Low[1]) and
Close > Close[1] and
Open Tomorrow >= Low[3] Then
Sell 1 Contract Tomorrow on (Minlist(Low[3], Close[4]) * 0.999)
Stop;
If
EntryPrice > 0 Then Begin
If MarketPosition = 1 Then Begin
ExitLong on EntryPrice * 0.96 Stop;
ExitLong on EntryPrice * 1.12 Limit;
End;
If MarketPosition = -1 Then Begin
ExitShort on EntryPrice * 1.04 Stop;
ExitShort on EntryPrice * 0.88 Limit;
End;
End;
If
BarsSinceEntry >= 3 Then SetExitOnClose;
ExitLong on Close;
ExitShort on Close;
End;
Back
to top
October
2001, TradeStation code:
Inputs:
DepPrice(Close of data1), IndPrice(Close of data2);
Vars: Length(63), iBeta(1), Ind(0), Dep(0), SumX(0), SumY(0),
SumXY(0), SumXsq(0), j(0);
Dep
= (DepPrice - DepPrice[1]) / DepPrice[1];
Ind = (IndPrice - IndPrice[1]) / IndPrice[1];
If
CurrentBar >= Length Then Begin
SumX = Summation(Ind, Length);
SumXY = 0;
SumY = Summation(Dep, Length);
SumXsq = 0;
For j = 0 to Length - 1 Begin
SumXY = SumXY + (Ind[j] * Dep[j]);
SumXsq = SumXsq + Square(Ind[j]);
End;
If SumXY <> 0 and SumX <> 0 Then
iBeta = ((Length * SumXY) - (SumX * SumY)) / ((Length * SumXsq)
- Square(SumX));
If IndPrice > Average(IndPrice, Length) and iBeta > 1
and MarketPosition <> 1 Then
Buy 1 Contract Tomorrow at Lowest(Low, 5) Limit;
If IndPrice < Average(IndPrice, Length) and iBeta < 1
and MarketPosition <> -1 Then
SellShort 1 Contract Tomorrow at Highest(High, 5) Limit;
If EntryPrice > 0 Then Begin
If Close < EntryPrice * 0.96 or Close > EntryPrice * 1.12
Then
Sell Tomorrow at Market;
If Close > EntryPrice * 1.04 or Close < EntryPrice * 0.88
Then
BuyToCover Tomorrow at Market;
End;
End;
Back
to top
November
2001, TradeStation code:
Inputs:
PTarget(12), StopL(4);
Variables: ProfitPrice(0), StopPrice(0);
If
L[1] < L[2] and L[2] < L[3] and H[0] > H[3] Then
Buy ("3L-R") Next Bar on Open;
ProfitPrice
= EntryPrice * (1 + PTarget / 100);
StopPrice = EntryPrice * (1 - PTarget / 100);
If
MarketPosition = 1 Then Begin
Sell ("3L-R Exit") Next Bar at ProfitPrice Limit;
Sell ("3L-R Stop") Next Bar at StopPrice Stop;
End;
Back
to top
December
2001, TradeStation code:
Inputs:
MaxLength(5);
Variables: MarPos(0), LongLoss(0), ShortLoss(0);
If BarsSinceEntry >= (MaxLength - 2) Then
SetExitOnClose;
If MarketPosition <> 1 and Close < AvgPrice and AvgPrice
< AvgPrice[5] Then Begin
If Open Tomorrow < AvgPrice Then Begin
Buy ("Long") tomorrow at AvgPrice Stop;
End;
End;
If MarketPosition <> -1 and Close > AvgPrice and AvgPrice
> AvgPrice[5] Then Begin
If Open Tomorrow > AvgPrice Then Begin
SellShort ("Short") tomorrow at AvgPrice Stop;
End;
End;
MarPos = MarketPosition;
If MarPos <> MarPos[1] and MarPos = 1 Then
LongLoss = Low[1];
If MarPos <> MarPos[1] and MarPos = -1 Then
ShortLoss = High[1];
If EntryPrice > 0 Then Begin
If BarsSinceEntry >= 1 Then Begin
LongLoss = MaxList(LongLoss, Low);
ShortLoss = MinList(ShortLoss, High);
End
Else Begin
LongLoss = MaxList(LongLoss, Low);
ShortLoss = MinList(ShortLoss, High);
End;
If MarketPosition = 1 Then Begin
Sell ("LS") tomorrow at LongLoss Stop;
Sell ("LT") tomorrow at Highest(High, 5) Limit;
End;
If MarketPosition = -1 Then Begin
BuyToCover ("SS") tomorrow at ShortLoss Stop;
BuyToCover ("ST") tomorrow at Lowest(Low, 5) Limit;
End;
End;
Back
to top
January
2002, TradeStation code:
Variables:
LenRC(5), TradeLenRC(5), RiskCalc(0),
RC1(0), RC2(0), RC3(0), RC4(0), RC5(0), RC6(0), RC7(0), RC8(0),
RC9(0), RC10(0);
RC1
= RateOfChange(Close Data1, LenRC);
RC2 = RateOfChange(Close Data2, LenRC);
RC3 = RateOfChange(Close Data3, LenRC);
RC4 = RateOfChange(Close Data4, LenRC);
RC5 = RateOfChange(Close Data5, LenRC);
RC6 = RateOfChange(Close Data6, LenRC);
RC7 = RateOfChange(Close Data7, LenRC);
RC8 = RateOfChange(Close Data8, LenRC);
RC9 = RateOfChange(Close Data9, LenRC);
RC10 = RateOfChange(Close Data10, LenRC);
If
MarketPosition = 0 and RC1 = MinList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Buy Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
If
MarketPosition = 0 and RC1 = MaxList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Sell Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
If
BarsSinceEntry >= TradeLenRC Then Begin
ExitLong Next Bar at Market;
ExitShort Next Bar at Market;
End;
Back
to top
February
2002, TradeStation code:
Vars:
Ratio(0), AvgRatio(0), RiskCalc(0);
Ratio
= Close Data1 / Close Data2;
AvgRatio
= XAverage(Ratio, 9);
If
AvgRatio Crosses above AvgRatio[9] Then Begin
Buy at market;
RiskCalc = AvgTrueRange(9);
End;
If
AvgRatio Crosses below AvgRatio[9] Then Begin
Sell at market;
RiskCalc = AvgTrueRange(9);
End;
Back
to top
April
2002, TradeStation code:
Variables:
LenRC(5), TradeLenRC(5), RiskCalc(0), MMExport(1),
RC1(0), RC2(0), RC3(0), RC4(0), RC5(0), RC6(0), RC7(0), RC8(0),
RC9(0), RC10(0), TrendFilter(0);
RC1
= RateOfChange(Close Data1, LenRC);
RC2 = RateOfChange(Close Data2, LenRC);
RC3 = RateOfChange(Close Data3, LenRC);
RC4 = RateOfChange(Close Data4, LenRC);
RC5 = RateOfChange(Close Data5, LenRC);
RC6 = RateOfChange(Close Data6, LenRC);
RC7 = RateOfChange(Close Data7, LenRC);
RC8 = RateOfChange(Close Data8, LenRC);
RC9 = RateOfChange(Close Data9, LenRC);
RC10 = RateOfChange(Close Data10, LenRC);
TrendFilter = Average(Close Data11, 80);
If
TrendFilter > TrendFilter[11] Then Begin
If MarketPosition = 0 and RC1 = MinList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Buy Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
If MarketPosition = 0 and RC1 = MaxList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Sell Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
End;
If
TrendFilter < TrendFilter[11] Then Begin
If MarketPosition = 0 and RC1 = MinList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Sell Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
If MarketPosition = 0 and RC1 = MaxList(RC1,RC2,RC3,RC4,RC5,RC6,RC7,RC8,RC9,RC10)
Then Begin
Buy Next Bar at Market;
RiskCalc = AvgTrueRange(5);
End;
End;
If
BarsSinceEntry >= TradeLenRC Then Begin
ExitLong Next Bar at Market;
ExitShort Next Bar at Market;
End;
Back
to top
May
2002, TradeStation code:
{Three
black candle sticks for entry:}
If High < High[1] and High [1] < High[2] and High[2] <
High[3] and
Close < Open and Close[1] < Open[1] and Close[2] <
Open[2] Then
Buy Tomorrow at High Stop;
{Trailing
stop:}
ExitLong Tomorrow at Low Stop;
{Profit
taking Gap higher:}
If MarketPosition <> 0 and Open Tomorrow > High Then
ExitLong Tomorrow at Open;
{
Retracement bar:}
If High > High[1] and Close < Close[1] Then
SetExitOnClose;
Back
to top
June
2002, TradeStation code:
Inputs:
BarsInTrade(8), ProfitExit(8), LossExit(4);
Variables: LongStop(0), ShortStop(0), LongTarget(0), ShortTarget(0),
LimitExit(0), StopExit(0);
LimitExit = (ProfitExit / 2 + 0.5) / 100;
StopExit = (LossExit / 5 + 0.2) / 100;
If MarketPosition = 0 Then Begin
If High < High[2] and Close < Open and Open Next Bar <
High Then Begin
Buy Next Bar at High Stop;
LongStop = 1 - StopExit;
LongTarget = 1 + LimitExit;
End;
If Low > Low[2] and Close > Open and Open Next Bar >
Low Then Begin
Sell Next Bar at Low Stop;
ShortStop = 1 + StopExit;
ShortTarget = 1 - LimitExit;
End;
End;
If MarketPosition = 1 Then Begin
ExitLong Next Bar at EntryPrice * LongStop Stop;
ExitLong Next Bar at EntryPrice * LongTarget Limit;
End;
If MarketPosition = -1 Then Begin
ExitShort Next Bar at EntryPrice * ShortStop Stop;
ExitShort Next Bar at EntryPrice * ShortTarget Limit;
End;
If BarsSinceEntry = BarsInTrade+1 Then Begin
ExitLong Next Bar at Market;
ExitShort Next Bar at Market;
End;
Back
to top
July
2002, TradeStation code:
Variables:
RiskCalc(0);
If
MarketPosition <> 1 and Average(Close, 9) Crosses above
Average(Close, 36) Then Begin
RiskCalc = 4 * AvgTrueRange(10);
Buy Next Bar at Market;
End;
If
Average(Close, 9) Crosses below Average(Close, 36) Then
ExitLong Next Bar at Market;
If
MarketPosition = 1 and EntryPrice > 0 Then
ExitLong Next Bar at EntryPrice - RiskCalc Stop;
Back
to top
August
2002, TradeStation code:
If
MarketPosition <> -1 Then
Sell
Next Bar at Close[1] + 2 * AvgTrueRange(5) limit;
If
MarketPosition <> 1 Then
Buy
Next Bar Close[1] - 2 * AvgTrueRange(5) limit;
If
MarketPosition = 1 Then Begin
ExitLong
Next Bar at EntryPrice - AvgTrueRange(5) Stop;
ExitLong
Next Bar at EntryPrice + 2 * AvgTrueRange(5) Limit;
End;
If
MarketPosition = -1 Then Begin
ExitShort
Next Bar at EntryPrice + AvgTrueRange(5) Stop;
ExitShort
Next Bar at EntryPrice - 2 * AvgTrueRange(5) Limit;
End;
Back
to top
September
2002, TradeStation code:
Variables:
ProfitDistance(0), RiskCalc(0), MMExport(1);
Condition1
= Range = MinList(Range, Range[1], Range[2], Range[3]);
Condition2 = Low < Low[1] and High < High[2];
Condition3 = Low > Low[1] and High > High[1];
Condition4 = Close < High[1] and Close > Low[1];
If
MarketPosition = 0 and Condition1 and Condition2 and Condition4
Then Begin
Buy Next Bar on High Stop;
ProfitDistance = Range * 3;
End;
{
If MarketPosition = 0 and Condition1 and Condition3 and Condition4
Then Begin
Sell Next Bar on High Limit;
ProfitDistance = Range * 3;
End;
}
If EntryPrice > 0 Then Begin
ExitLong at Low Stop;
ExitLong at EntryPrice + ProfitDistance Limit;
{ExitShort at High Stop;
ExitShort at EntryPrice - ProfitDistance Limit;}
End;
Back
to top
October
2002, TradeStation code:
Variables:
EntryAvg(0), ExitAvg(0), EntryVol(0), ExitVol(0), RiskCalc(0);
EntryAvg
= Average(Close, 60);
ExitAvg = Average(Close, 30);
EntryVol = 2 * StdDev(Close, 60);
ExitVol = 1 * StdDev(Close, 30);
RiskCalc
= (EntryAvg + EntryVol) - (ExitAvg - ExitVol);
Buy
NumCont Contracts Next Bar at EntryAvg + EntryVol Stop;
Sell NumCont Contracts Next Bar at EntryAvg - EntryVol Stop;
ExitLong
Tomorrow at ExitAvg - ExitVol Stop;
ExitShort Tomorrow at ExitAvg + ExitVol Stop;
AmiBroker
code:
EntryAvg
= MA(Close, 60);
ExitAvg = MA(Close, 30);
EntryVol = 2 * StDev(Close, 60);
ExitVol = 1 * StDev(Close, 30);
RiskCalc
= (EntryAvg + EntryVol) - (ExitAvg - ExitVol);
/*
entry at Entryavg + EntryVol STOP */
BuyStopLevel
= EntryAvg + EntryVol;
Buy = High > BuyStopLevel;
BuyPrice = Max( Open, BuyStopLevel );
/*
and similar equations for short */
ShortStopLevel
= EntryAvg - EntryVol;
Short = Low < ShortStopLevel;
ShortPrice = Min( Open, ShortStopLevel );
/*
... and exits */
SellStopLevel
= ExitAvg - ExitVol;
Sell = Low < SellStopLevel;
SellPrice = Min( Open, SellStopLevel );
CoverStopLevel
= ExitAvg + ExitVol;
Cover = High > CoverStopLevel;
CoverPrice = Max( Open, CoverStopLevel );
Back
to top
November
2002, TradeStation code:
Condition1
= CloseW(2) > CloseW(1) and CloseW(1) > C and C[2] >
C[1] and C[1] > C;
Condition2 = CloseW(2) < CloseW(1) and CloseW(1) < C and
C[2] < C[1] and C[1] < C;
If
Condition1 = True and MarketPosition = 0 Then
Buy ("Go long") at open;
If Condition2 = True and MarketPosition = 0 Then
Sell ("Go short") at open;
Variables:
TrailingStop(True), BarsInTrade(8), ProfitExit(4){4.5}, LossExit(1.6){1},
LongStop(0), ShortStop(0), LongTarget(0), ShortTarget(0), Top(0),
Bottom(0);
If
BarNumber = 1 Then Begin
ProfitExit = ProfitExit / 100;
LossExit = LossExit / 100;
LongStop = 1 - LossExit;
LongTarget = 1 + ProfitExit;
ShortStop = 1 + LossExit;
ShortTarget = 1 - ProfitExit;
End;
Top = High;
Bottom = Low;
If
EntryPrice > 0 Then Begin
If MarketPosition = 1 Then Begin
If TrailingStop = True Then Begin
Top = MaxList(Top, High);
ExitLong ("L-Trail") Next Bar at Top * LongStop Stop;
End
Else
ExitLong ("L-Stop") Next Bar at EntryPrice * LongStop
Stop;
ExitLong ("L-Trgt") Next Bar at EntryPrice * LongTarget
Limit;
End;
If MarketPosition = -1 Then Begin
If TrailingStop = True Then Begin
Bottom = MinList(Bottom, Low);
ExitShort ("S-Trail") Next Bar at Bottom * ShortStop
Stop;
End
Else
ExitShort ("S-Stop") Next Bar at EntryPrice * ShortStop
Stop;
ExitShort ("S-Trgt") Next Bar at EntryPrice * ShortTarget
Limit;
End;
If BarsSinceEntry = BarsInTrade + 1 Then Begin
ExitLong ("L-Time") Next Bar at Market;
ExitShort ("S-Time") Next Bar at Market;
End;
End;
Back
to top
December
2002, TradeStation code:
Variables:
RandomTrigger(0), ShortVol(0), LongVol(0), ShortLookBack(10),
LongLookBack(63), ShortTrend(0), LongTrend(0), LongTrendDir(0);
ShortVol
= AvgTrueRange(ShortLookBack);
LongVol = AvgTrueRange(LongLookBack);
If ShortVol > LongVol Then
ShortTrend = 1
Else
ShortTrend = -1;
RandomTrigger
= IntPortion(Random(5));
LongTrend
= Average(Close, 80);
If LongTrend > LongTrend[20] Then
LongTrendDir = 1
Else
LongTrendDir = -1;
If
MarketPosition = 0 and ShortTrend = 1 and RandomTrigger = 1
Then Begin
If Date < 1000401 {LongTrendDir = 1} Then
Buy at Close;
If Date >= 1000401 {LongTrendDir = -1} Then
Sell at Close;
End;
If
MarketPosition <> 0 Then Begin
ExitLong at (EntryPrice - ShortVol) Stop;
ExitLong at (EntryPrice + 3 * ShortVol) Limit;
ExitShort at (EntryPrice + ShortVol) Stop;
ExitShort at (EntryPrice - 3 * ShortVol) Limit;
If BarsSinceEntry >= ShortLookBack -1 Then Begin
ExitLong on Close;
ExitShort on Close;
End;
End;
Back
to top
January
2003, TradeStation code:
If
Close > (Average(Close, 60) + StdDev(Close, 60)) Then
Buy at Market;
If
Close < (Average(Close, 60) - StdDev(Close, 60)) Then
Sell at Market;
Back
to top
February
2003, TradeStation code:
Var: HistVol(0), YestHistVol(0),
DeltaHistVol(0), LookBack(0);
YestHistVol = HistVol;
HistVol = StdDev(C, 30);
DeltaHistVol = (HistVol - YestHistVol) / HistVol;
If CurrentBar = 1 Then
LookBack = 20;
LookBack = LookBack * (1 + DeltaHistVol);
LookBack = MaxList(LookBack, 20);
LookBack = MinList(LookBack, 60);
If Close > Highest(High,
LookBack)[1] Then
Buy at Market;
If Close < Lowest(Low,
LookBack)[1] Then
Sell at Market;
Back
to top
May
2004, MetaStock code:
To
create the system test, open the tester under the Tools menu.
Select new test and enter the following formulas in for the
specific orders.
Enter
Long:
Cross(Mov(C,10,W),Mov(C,7,W))
Close
Long:
Cross(Mov(C,7,W),Mov(C,10,W))
Enter
Short:
Cross(Mov(C,7,W),Mov(C,10,W))
Close
Short:
Cross(Mov(C,10,W),Mov(C,7,W))
MetaStock
code for Futures Trading System Lab:
To
create the system test, open the tester under the Tools menu.
Select new test and enter the following formulas in for the
specific orders.
Enter
Long:
ama:=If(Cum(1)=5,Ref(C,-1)+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*
(C-Ref(C,-1)),PREV+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-PREV));
C>BBandTop(ama,38,S,3)
Close Long:
ama:=If(Cum(1)=5,Ref(C,-1)+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*
(C-Ref(C,-1)),PREV+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-PREV));
C<BBandBot(ama,38,S,3)
Enter
Short:
ama:=If(Cum(1)=5,Ref(C,-1)+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*
(C-Ref(C,-1)),PREV+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-PREV));
C<BBandBot(ama,38,S,3)
Close
Short:
ama:=If(Cum(1)=5,Ref(C,-1)+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*
(C-Ref(C,-1)),PREV+(Pwr((Abs((C-Ref(C,-4))
/Sum(Abs(ROC(C,1,$)),4)))*((2/3)-(2/31))+(2/31),2))*(C-PREV));
C>BBandTop(ama,38,S,3)
Back
to top
June
2004, TradeStation code:
inputs:
Length( 10 ),
NumDevsDn( 1.5 ) ;
variables:
LowerBand( 0 ) ;
LowerBand = BollingerBand( Low, Length, -NumDevsDn ) ;
value1 = TL_New( Date[1], Time[1], LowerBand[1], Date, Time,
LowerBand );
if CurrentBar > 1 and Low crosses under LowerBand then
{ CB > 1 check used to avoid spurious cross confirmation
at CB = 1 }
Buy ( "BBandLE" ) next bar Market ;
if Close > EntryPrice then
Sell this bar at Close ;
if BarsSinceEntry = 20 then
sell this bar at Close ;
MetaStock code:
To
create the system test, open the tester under the Tools menu.
Select new test and enter the following formulas in for the
specific orders.
Buy
Order:
L<BBandBot(L,10,S,1.5)
Sell
Order:
bc:=L<BBandBot(L,10,S,1.5);
C > ValueWhen(1,Ref(bc,-1),O)
MetaStock
code for Futures Trading System Lab
Because
this system uses an entry signal that can be true for several
bars in a row, MetaStock version prior to 8.0 can not accurately
count how long the trade has been active. Therefore, the formulas
for this system are only valid in the MetaStock 8.0 and later.
To create the system test, open the tester under the Tools menu.
Select new test and enter the following formulas in for the
specific orders.
Buy
Order:
h>ref(hhv(h,55),-1)
Sell Order:
x:= Simulation.CurrentPositionAge;
l< ref(llv(l,55),-1)*((0.1*ATR(20))*x)
Back
to top
July
2004, MetaStock code:
This
system is designed to run on weekly data. To create the system
test, open the tester under the Tools menu. Select new test
and enter the following formulas in for the specific orders.
The formulas below are for version 7.2 and earlier.
Enter
Long:
ADX(14)<30 AND
Cross(Mov(C,30,S),Mov(C,60,S))
Close Long:
bc:=ADX(14)<30 AND
Cross(Mov(C,30,S),Mov(C,60,S));
If(BarsSince(bc)<=10,
L<Ref(LLV(L,60),-1),
Mov(C,30,S)<Mov(C,60,S) )
Enter Short:
ADX(14)<30 AND
Cross(Mov(C,60,S),Mov(C,30,S))
Close Short:
sc:=ADX(14)<30 AND
Cross(Mov(C,60,S),Mov(C,30,S));
If(BarsSince(sc)<=10,
H>Ref(HHV(H,60),-1),
Mov(C,30,S)>Mov(C,60,S) )
For versions 8.0 and later, the formulas can be simplified a
bit, and at the same time, made for accurate to the intents
of the system. Below are the 8.0 formulas.
Buy
Order:
ADX(14)<30 AND
Cross(Mov(C,30,S),Mov(C,60,S))
Sell Order:
If(Simulation.CurrentPositionAge<=10, L<Ref(LLV(L,60),-1),
Mov(C,30,S)<Mov(C,60,S) )
Sell Short Order:
ADX(14)<30 AND
Cross(Mov(C,60,S),Mov(C,30,S))
Buy to Cover Order:
If(Simulation.CurrentPositionAge<=10, H>Ref(HHV(H,60),-1),
Mov(C,30,S)>Mov(C,60,S) )
Back
to top
August
2004, MetaStock code:
The
following formulas were written for use in an Expert Advisor.
To use them, open the expert advisor from the Tools menu. Select
New and then move to the symbols tab. For each of the following
formulas, click New to make a new symbol. Enter the name and
the formula. Then select the graphics tab to set the symbol,
color and placement desired.
Name:
Enter Long
Formula:
r:=RSI(14);
bc:=Cross(r,75);
sc:=Cross(25,r);
trade:=If(PREV=0,If(bc,1,0),
If(sc OR (PREV=20),0,PREV+1));
trade=1
Name: Enter Short
Formula:
r:=RSI(14);
bc:=Cross(r,75);
sc:=Cross(25,r);
trade:=If(PREV=0,If(sc,1,0),
If(bc OR (PREV=20),0,PREV+1));
trade=1
Name: Exit Long
Formula:
r:=RSI(14);
bc:=Cross(r,75);
sc:=Cross(25,r);
trade:=If(PREV=0,If(bc,1,0),
If(sc OR (PREV=20),0,PREV+1));
Cross(trade=0,0.5)
Name: Exit Short
Formula:
r:=RSI(14);
bc:=Cross(r,75);
sc:=Cross(25,r);
trade:=If(PREV=0,If(sc,1,0),
If(bc OR (PREV=20),0,PREV+1));
Cross(trade=0,0.5)
The
same formulas listed above can be put into the columns of an
exploration. Put each one into a separate formula and use the
following formula for the filter:
cola
AND colb AND colc AND cold
The formulas can also be used in a system test. No changes are
required for this.
Back
to top
June
2006, tymoraPRO software code:
Program
TymoraSampleIndicator_Channel_MidPoint;
//Must
have the word "Indicator" in the Program Header
const
IndName = 'ChnMidP';
var
tmpHi,tmpLo,curHi,curLo,prvMidP,MidP,PS,PV,MM,LS: extended;
barsToUse,rColor:
integer;
Band1: Integer;
function
init(ChartNo,TF: Integer; AssetN: String): integer;
//this
function is called first by tymoraPRO and should initialize
all your variables, etc
//ChartNo
= 0..35, TF (timeFrame) = 1=Day...7=1min, AssetN = assetname
//
if this function returns anything but 0 tymoraPRO will ignore
indicator for this run
var
i: integer;
cfgs: string;
begin
// Initialization
code goes here
SetName(IndName);
Band1 :=
AddBand(ChartNo);
SetBandScale(Band1,0);
//set scale to price
SetBandStyle(Band1,2,psSolid);
tmpHi :=
0; tmpLo := 0; curHi := 0; curLo := 0;
barsToUse := 50; rColor := clGreen;
cfgs := GetInitParams(ChartNo,IndName);
if (cfgs
<> '') then Begin
try barsToUse
:= strtoint(cfgs); except barsToUse := 50; end;
End;
//if (barsToUse
= 0) then barsToUse := OptimalCycle(ChartNo,TF)*4;
//if (barsToUse
= 0) then barsToUse := 50;
ReturnAssetInfo(AssetN,PS,PV,MM,LS);
result :=
0;
end;
function main(ChartNo,TF: Integer; AssetN: String; istemp: boolean):
integer;
//this function is called first by tymoraPRO and should initialize
all your variables, etc
//ChartNo = 0..35, TF (timeFrame) = 1=Day...7=1min, AssetN =
assetname
// if (istemp = true) this is a temporary newbar (the current
uncompleted bar)
//indicator can also be customized based on ChartNumber, TimeFrame,
and/or AssetName
var
i,volup,voldn,dt,tm,ok: integer;
op,hi,lo,cl,pcl,useHi,useLo,useMidP:
extended;
hifirst:
boolean;
begin
// main code
goes here
if (not istemp)
then Begin
tmpHi :=
0; tmpLo := 0;
if (curHi
<> 0) then Begin
ok := BarData(ChartNo,barsToUse,dt,tm,op,hi,lo,cl,volup,voldn,hifirst);
if (ok =
-1) or CompPrc(curHi,hi,PS,'=') or CompPrc(curLo,lo,PS,'=')
then curHi := 0;
End;
if (curHi
= 0) then Begin
curHi :=
0; curLo := 0;
for i :=
0 to barsToUse-1 do begin
BarData(ChartNo,i,dt,tm,op,hi,lo,cl,volup,voldn,hifirst);
if (curHi
= 0) or (curHi < hi) then curHi := hi;
if (curLo
= 0) or (curLo > lo) then curLo := lo;
end;
End;
PrvMidP :=
MidP;
MidP := (curHi+curLo)/2;
if (MidP
> PrvMidP) then rColor := clGreen else
if (MidP
< PrvMidP) then rColor := clRed;
BandAddXY(Band1,NewChartX(ChartNo,istemp),MidP,rColor,istemp);
End;
if istemp
then Begin
if (tmpHi
= 0) then Begin
for i :=
0 to barsToUse-2 do begin
BarData(ChartNo,i,dt,tm,op,hi,lo,cl,volup,voldn,hifirst);
if (tmpHi
= 0) or (tmpHi < hi) then tmpHi := hi;
if (tmpLo
= 0) or (tmpLo > lo) then tmpLo := lo;
end;
End;
useHi :=
tmpHi; useLo := tmpLo;
BarData(ChartNo,-
1,dt,tm,op,hi,lo,cl,volup,voldn,hifirst); //new temporary bar
if (hi >
useHi) then useHi := hi;
if
(lo < useLo) then useLo := lo;
if ((useHi+useLo)/2
> MidP) then rColor := clGreen else
if ((useHi+useLo)/2
< MidP) then rColor := clRed;
BandAddXY(Band1,NewChartX(ChartNo,istemp),(useHi+useLo)/2,rColor,istemp);
End;
result :=
0;
end;
function
afterdraw(ChartNo,TF: Integer; AssetN: String; FirstValueIndex,LastValueIndex:
integer): integer;
//this
routine is called in order to add any additional text or drawing
on the final chart
begin
// additional
chart annotation goes here
result :=
0;
end;
function
cleanup(ChartNo,TF: Integer; AssetN: String): integer;
//
perform any variable cleanup and other stuff here, return 0
if all okay
begin
// final
cleanup code goes here (ie. freeing created bands)
FreeBand(Band1);
result := 0;
end;
Back
to top

Copyright © 2000-2008, Active Trader® Magazine, Chicago, IL |