Designing and Building a Profitable Automated Trading System

Discussion in 'Automated Trading' started by ScottD, Dec 9, 2008.

  1. I see this is set up for a rocket entry (MACD hist .1.4) based on STOCH5 direction after a three bar time synch.

    Conservative but useful for first pass.

    I see the exit is STOCH 14 stuff.

    You need to slip in a way to do a reversal if the new entry is BEFORE the old exit.

    you said you had two losses. throw up the chart and I will focus on the coding here to eliminate losses as a starter. then we go to work on coding.
     
    #61     Dec 11, 2008
  2.  
    #62     Dec 11, 2008
  3. its probably me but I can deal with the chart in any way. Can't enlarge of copy it.
     
    #63     Dec 11, 2008
  4. It was me. I copied it to paint and I can now see it.
     
    #64     Dec 11, 2008
  5. LOL that is yesteday.... Two trades before I recognized it.

    can we set up to post a list of trades as they occur like a log of some sort.

    The STOCH5 X over 50 and the STOCH14 80/20 exit are in good synch. I'll find the two "losers" and see if the cases from yesterday fixed them.
     
    #65     Dec 11, 2008
  6. At this point it looks like the code is cycling at the end of every bar (once evey five minutes). This is like the screen is the source of the data and not an external stream of data.

    Dark ages type use of PC.

    Can you confirm that your ATS coding doesn't get information very often?

    Where I am going with the conversation is dealing with forming bars and how to code C and D and.........both entwine and how to do suppression with MLR's etc.

    So far we are just doing "chunking" with slugs of H, L and C's at the end of a 5 minute bar. Display type historical data. Talking head type stuff on TV.
     
    #66     Dec 11, 2008
  7. Jack,

    You spend a lot of time typing everyday during market hours. Do you ever do any real trading.
     
    #67     Dec 11, 2008
  8. ScottD

    ScottD

    Updated 10 Dec 2008 (yesterday) chart attached, showing trades from updated logic engine.

    As desired, we can focus on the same day to see how the code changes impact the same time series of data.

    Current screen technology allows one to see this stuff in its native resolution.

    It's nice not to have to downgrade the image in the feedback information loop.

    24" or 30" screens are useful for trading.

    17" was a common size for a black and white TV when I was a young lad, so I do have some experience with it.

    17"x5 may not be as effective as 30"x1.

    Chart labels
    S5FKLE: Stoch5 FastK Long Entry
    S5FKSE: Stoch5 FastK Short Entry
    S5FKRL: Stoch5 FastK Reverse Long
    S5FKRS: Stoch5 FastK Reverse Short
    S14KDLX: Stoch14 KxD Long Exit
    S14KDSX: Stoch14 KxD Short Exit
    and so on...

    Long Entry bar and price: Green arrows
    Long Exit bar and price: Blue arrows
    Short Entry bar and price: Purple arrows
    Short Exit bar and price: Dark Yellow arrows

    In the next post I will attach a log of trades.

    Version 0.2 of the logic engine below.

    Additional capability and enhancement as follows:

    - Built the Reversal logic, using the Stoch5 FastK.
    System now takes many more trades.

    - Added a quick and clean Medium volume threshold qualifier for entry and reversal.

    - Cleaned up and standardized the nomenclature as discussed.

    - Better structured the code for intuitive understanding and natural reading.

    - Added some commentary behind double forward slash // symbol

    Comments:

    At the moment I deliberately have the system configured to make decisions and to take actions at the end of each bar, instead of at every tick.

    This makes the logic much easier to validate in the chart.

    When we are ready for prime time, I can toggle the switch and change to tick-by-tick decisions and actions.

    If I were to do it now, it would plot entries that don't appear to be validated in the chart
    (temporal intrabar crosses that don't close as crosses, and that sort of thing).

    Code:
    {
    CashCow automated trading system
    Architect: Jack Hershey
    Version 0.2
    Date 11 Dec 2008
    }
    
    variables:
    Stoch5FastK( 0 ), Stoch5FastD( 0 ), Stoch5SlowK( 0 ), Stoch5SlowD( 0 ),
    Stoch14FastK( 0 ), Stoch14FastD( 0 ), Stoch14SlowK( 0 ), Stoch14SlowD( 0 ) ;
    
    if CurrentBar > 2 and Time > 945 and Time < 1600 then
    begin
    	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 ) ;
    
    	//Entry logic
    	if Volume of 1 bar ago > 20000 then  //enter only when volume greater than 'Medium'
    	begin
    		if CurrentBar > 2 and Stoch5FastK crosses above 50 
    		and Stoch5FastK > Stoch5FastD and marketposition = 0 then
    
    			Buy ( "S5FKLE" ) 1 contract this bar at close ;
    
    		if CurrentBar > 2 and Stoch5FastK crosses below 50 
    		and Stoch5FastK < Stoch5FastD and marketposition = 0 then
    
    			Sellshort ( "S5FKSE" ) 1 contract this bar at close ;
    	end;
    
    	//Reverse logic
    	If Volume of 1 bar ago > 20000 then
    	begin
    		if marketposition > 0 and Stoch5FastK crosses below 50 then
    			sellshort ( "S5FKRS" ) 1 contracts this bar at close ;
    
    		if marketposition < 0 and Stoch5FastK crosses above 50 then
    			buy ( "S5FKRL" ) 1 contracts this bar at close ;
    	end;
    
    	//Exit logic
    	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 ;
    
    	{
    	MACD Exit logic stub
    	Commented out.  Will be brought to life later.
    	variables: MACDVal( 0 ), MACDMA( 0 ), MACDHist( 0 ) ;
    	MACDVal = MACD( Close, 5, 13 ) ;
    	MACDMA = XAverage( MACDVal, 6 ) ;
    	MACDHist = MACDVal - MACDMA ;
    	if absvalue( MACDVal ) < 1.4 and marketposition > 0 then 
    		Sell ( "MACDLX" ) this bar at close ;
    	if absvalue( MACDVal ) < 1.4 and marketposition < 0 then     
    			Buytocover ( "MACDSX" ) this bar at close ;
    	}
    end;
    
    //Flatten at end of day
    if Time > 1600 and marketposition > 0 then sell ( "EODLX" ) next bar at market;
    if Time > 1600 and marketposition < 0 then buytocover ( "EODSX" ) next bar at market;
    
    
    <img src=http://elitetrader.com/vb/attachment.php?s=&postid=2216805 width=800>
    click on attachment link to enlarge image
     
    #68     Dec 11, 2008
  9. Thanks.

    I agree we can switch to more frequent cycles later afterwe rough out some refinements.
     
    #69     Dec 11, 2008
  10. ScottD

    ScottD

    Trade log for diagnosis.
     
    #70     Dec 11, 2008