// Control System for testing e-Mini financial futures ES, NQ, ER2, EMD intra-day. // WARNING: DO NOT TRADE THIS SYSTEM - IT TAKES RANDOM ENTRIES AND SHOULD ONLY // BE USED AS A COMPARISON FOR A 'REAL' SYSTEM // Setup: None - simply apply to any futures contract being tested // Entry: Random side and time (between 9:35am and 3:00pm // Position Sizing: Percent of notional equity based on initial stop // Stops: Simple trailing stop // Exit: Exit at end of day if not stopped out - no overnight positions // Addition rules: None // Notes: // Does not include commissions or slippage in cumulative notional calculation // All times EST. // Date: 10/19/5 // Version: 1.0 // Author: Paul King // Copyright 2005 PMKing Trading LLC www.pmkingtrading.com // Schedule (EST): // 9:30 AM Initialize trading for day and determine entry side and time (randomly) // 9:35 AM Commence checking for random entry previously determined // 3:00 PM Stop checking for entry // 4:10 PM Exit if not stopped out variables: int lookback(0), // Number of bars in one session int i(0), // A counter int daysback(0), // Number of days to calculate range over int entrybar(0), // Barnumber of trade entry int positionsize(0), // Number of contracts to trade int tradeperiod(0), // Average number of days between generated trades int enterbar(0), // Randomly generated bar to enter random trade int inposition(0), // Indicates whether in a position (>0 -> Long, <0 -> Short) float dayrange(0), // Range of trading over daysback days float stopprice(0), // Current stop price float stopsize(0), // Distance of current stop from market float percentrisk(0), // Percent of notional to risk per trade float currentnotional(0), // Initial notional system allocation float enterside(0), // Randomly generated side float enterprice(0), // Entry price bool entryok(False), // True if OK to enter a trade // Use this input variable to run an 'optimization' the required number of iterations to see the variablility of returns inputs: int simulationnumber(1); // One time only actions if BarNumber=1 then begin currentnotional=40000; // Starting notional equity allocated to this strategy end; // Strategy constants lookback=390; // Number of bars to calculate stop over // Position sizing constants percentrisk=0.02; // Start with 2% risk per position // Parameters tradeperiod=3; // Average number of days between trades dayrange=3; // Number of days to calculate range over // Setup entry parameters at 9:30 am if (time = 0930) then begin // Initialize positions - should be flat from previous day inposition=0; entryok=false; // Calculate random entry if round(random(tradeperiod),0)=tradeperiod then begin // OK to enter entryok=true; // Random bar to enter between now and 3:00 PM enterbar=BarNumber+round(random(330),0); // Random side >=0.5 -> long, <0.5 -> short enterside=random(1); end; end; // Calulate entry signal between 9:35 AM and 3:00 PM if (time>0935 and time<1500) then begin // Enter long if (inposition=0 and entryok and CurrentBar=enterbar and enterside>=0.5) then begin // Store details inposition=1; stopsize=Round2Fraction(dayrange); stopprice=Close-stopsize; entrybar=CurrentBar; enterprice=close; // Calulate number of contracts positionsize=round((currentnotional*percentrisk)/(stopsize*BigPointValue),0); // Buy order if (positionsize>=1) then Buy ( "Long" ) positionsize contracts next bar at market else inposition=0; end; // Enter short if (inposition=0 and entryok and CurrentBar=enterbar and enterside<0.5)then begin // Store details inposition=-1; stopsize=Round2Fraction(dayrange); stopprice=Close+stopsize; entrybar=CurrentBar; enterprice=close; // Calulate number of contracts positionsize=round((currentnotional*percentrisk)/(stopsize*BigPointValue),0); //Sell order if (positionsize>=1) then Sell Short ( "Short" ) positionsize contracts next bar at market else inposition=0; end; end; // Check stop between 9:35 AM and 4:10 PM if (time>0935 and time < 1610) then begin // Test Stops if (inposition<>0) then begin // Long stop hit if (inposition>0 and Close<=stopprice) then begin Sell ("Long Stop Hit") positionsize contracts next bar at market; inposition=0; entryok=False; entrybar=0; // Modify notional currentnotional=currentnotional+((close-enterprice)*positionsize*BigPointValue); positionsize=0; end; // Short stop hit if (inposition<0 and Close>=stopprice) then begin buy to cover ("Short Stop Hit") positionsize contracts next bar at market; inposition=0; entryok=False; entrybar=0; // Modify Notional currentnotional=currentnotional+((enterprice-close)*positionsize*BigPointValue); positionsize=0; end; end; // Adjust stops // Long Stop if (inposition>0) then stopprice=Highest(Close, CurrentBar-entrybar)-stopsize; // Short Stop if (inposition<0) then stopprice=Lowest(Close, CurrentBar-entrybar)+stopsize; end; // Close positions if not stopped out by ent of day (4:10 PM) if (time=1610) then begin if (inposition>0) then begin sell ("Long EOD") positionsize contracts next bar at market; inposition=0; // Modify notional currentnotional=currentnotional+((close-enterprice)*positionsize*BigPointValue); positionsize=0; end; if (inposition<0) then begin buy to cover ("Cover Short EOD") positionsize contracts next bar at market; inposition=0; // Modify notional currentnotional=currentnotional+((enterprice-Close)*positionsize*BigPointValue); positionsize=0; end; end;