inputs:volumethreshold(0),macdThreshold(0);
{
CashCow automated trading system
Architect: Jack Hershey
Version 0.3
12 Dec 2008
New functionality: Context Supression Logic. Diagnostic Module.
New enhancements: Better organized code structure for natural reading.
Bug fixes: none
}
//Data Module
variables:
Stoch5FastK( 0 ), Stoch5FastD( 0 ), Stoch5SlowK( 0 ), Stoch5SlowD( 0 ),
Stoch14FastK( 0 ), Stoch14FastD( 0 ), Stoch14SlowK( 0 ), Stoch14SlowD( 0 ),
MACDVal( 0 ), MACDMA( 0 ), MACDDiff( 0 ),
TimeOK(False),
VolumeOK(False),
CurrentbarOK(False),
LongOK(False),
ShortOK(False),
DateOK(False);
//Formula Module
Value1 = Stochastic( H, L, C, 5, 2, 3, 1,
Stoch5FastK, Stoch5FastD, Stoch5SlowK, Stoch5SlowD ) ;
Value2 = Stochastic( H, L, C, 14, 1, 3, 1,
Stoch14FastK, Stoch14FastD, Stoch14SlowK, Stoch14SlowD ) ;
MACDVal = MACD( Close, 5, 13 ) ;
MACDMA = XAverage( MACDVal, 6 ) ;
MACDDiff = MACDVal - MACDMA ;
//Context Supression Logic
if Time > 845 and Time < 1500 then TimeOK = True else TimeOK = False;
if Volume of 1 bar ago > volumethreshold then VolumeOK = True else VolumeOK = False;
if currentbar > 2 then CurrentbarOK = True else CurrentbarOK = False;
if MACDDiff > macdthreshold then LongOK = true else LongOK = false;
//Needs to be validated and then tuned.
if MACDDiff < macdThreshold*-1 then ShortOK = true else ShortOK = false;
//Needs to be validated and then tuned.
DateOK = true;
//Only used during testing phase.
if CurrentBarOK and TimeOK and DateOK then
begin
//Entry Logic
if VolumeOK then //enter only when volume greater than 'Medium'
begin
if LongOK and Stoch5FastK crosses above 50
and Stoch5FastK > Stoch5FastD and marketposition = 0 then
Buy ( "S5FKLE" ) 1 contract this bar at close ;
if ShortOK and Stoch5FastK crosses below 50
and Stoch5FastK < Stoch5FastD and marketposition = 0 then
Sellshort ( "S5FKSE" ) 1 contract this bar at close ;
end;
//Reverse logic
If VolumeOK then
begin
if ShortOK and marketposition > 0 and Stoch5FastK crosses below 50 then
sellshort ( "S5FKRS" ) 1 contracts this bar at close ;
if LongOK and marketposition < 0 and Stoch5FastK crosses above 50 then
buy ( "S5FKRL" ) 1 contracts this bar at close ;
end;
//Exit Logic
{ Hold Logic. Tee up stub for later. if absvalue( MACDVal ) < 1.4 then }
if {(Stoch14SlowK < Stoch14SlowD) and} (Stoch14SlowK crosses below 80)
and marketposition > 0 then
Sell ( "S14SKLX" ) 1 contract this bar at close ;
if {(Stoch14SlowK > Stoch14SlowD) and} (Stoch14SlowK crosses above 20)
and marketposition < 0 then
buytocover ( "S14SKSX" ) 1 contract this bar at close ;
if marketposition > 0 and Stoch14SlowK crosses below Stoch14SlowD then
sell ( "S14KDLX" ) 1 contract this bar at close ;
if marketposition < 0 and Stoch14SlowK crosses above Stoch14SlowD then
buytocover ( "S14KDSX" ) 1 contract this bar at close ;
if marketposition > 0 and Stoch5FastK crosses below 50 then
sell ( "S5FKSX" ) 1 contracts this bar at close ;
if marketposition < 0 and Stoch5FastK crosses above 50 then
buytocover ( "S5FKLX" ) 1 contracts this bar at close ;
//Diagnostic Module
{Remove brackets and define date to enable.
if date = 1081210 then
Print(File("c:\log.txt"), time, Stoch5FastK, Stoch5FastD,
Stoch5SlowK, Stoch5SlowD,
Stoch14FastK, Stoch14FastD, Stoch14SlowK, Stoch14SlowD,
MACDVal, MACDMA, MACDDiff, " ",Volume[0]);
if date = 1081210 then
Print(Stoch5FastK, Stoch5FastD, Stoch5SlowK,
Stoch5SlowD,
Stoch14FastK, Stoch14FastD, Stoch14SlowK, Stoch14SlowD,
MACDVal, MACDMA, MACDDiff,
" ",Volume[0]);
}
end;
//End of Day Module
if Time > 1500 and marketposition > 0 then sell ( "EODLX" ) next bar at market;
if Time > 1500 and marketposition < 0 then buytocover ( "EODSX" ) next bar at market;