Tag Archives: Emini S&P

Why Do I Need to Test with Intraday Data

Why Can’t I Just Test with Daily Bars and Use Look-Inside Bar?

Good question.  You can’t because it doesn’t work accurately all of the time.   I just default to using 5 minute or less bars whenever I need to.  A large portion of short term, including day trade, systems need to know the intra day market movements to know which orders were filled accurately.  It would be great if you could just flip a switch and convert a daily bar system to an intraday system and Look Inside Bar(LIB) is theoretically that switch.  Here I will prove that switch doesn’t always work.

Daily Bar System

  • Buy next bar at open of the day plus 20% of the 5 day average range
  • SellShort next at open of the day minus 20% of the 5 day average range
  • If long take a profit at one 5 day average range above entryPrice
  • If short take a profit at one 5 day average range below entryPrice
  • If long get out at a loss at 1/2 a 5 day average range below entryPrice
  • If short get out at a loss at 1/2 a 5 day average range above entry price
  • Allow only 1 long and 1 short entry per day
  • Get out at the end of the day

Simple Code for the System

value1 = .2 * average(Range,5);
value2 = value1 * 5;

Buy next bar at open of next bar + value1 stop;
sellShort next bar at open of next bar - value1 stop;

setProfitTarget(value2*bigPointValue);
setStopLoss(value2/2*bigPointValue);
setExitOnClose;
Simplified Daily Bar DayTrade System using ES.D Daily
Daily Bar Using 5 min Look Inside Bar

Looks great with just the one hiccup:  Bot @ 3846.75 and the Shorted @ 3834.75 and then took nearly 30 handles of profit.

Now let’s see what really happened.

What Really Happened – Bot – Shorted – Stopped Out

Intraday Code to Control Entry Time and Number of Longs and Shorts

Not an accurate representation so let’s take this really simple system and apply it to intraday data.  Approaching this from a logical perspective with limited knowledge about TradeStation you might come up with this seemingly valid solution.  Working on the long side first.

//First Attempt


if d <> d[1] then value1 = .2 * average(Range of data2,5);
value2 = value1 * 5;
if t > sess1startTime then buy next bar at opend(0) + value1 stop;
setProfitTarget(value2*bigPointValue);
setStopLoss(value2/2*bigPointValue);
setExitOnClose;
First Simple Attempt

This looks very similar to the daily bar system.  I cheated a little by using

if d <> d[1] then value1 = .2 * average(Range of data2,5);

Here I am only calculating the average once a day instead of on each 5 minute bar.  Makes things quicker.  Also I used

if t > sess1StartTime then buy next bar at openD(0) + value1 stop;

I did that because if you did this:

buy next bar at open of next bar + value1 stop;

You would get this:

Cannot Sneak a Peek with Data2

That should do it for the long side, right?

Didn’t work quite right!

So now we have to monitor when we can place a trade and monitor the number of long and short entries.

How does this look!

Correct Execution!

So here is the code.  You will notice the added complexity.  The important things to know is how to control when an entry is allowed and how to count the number of long and short entries.  I use the built-in keyword/function totalTrades to keep track of entries/exits and marketPosition to keep track of the type of entry.

Take a look at the code and you can see how the daily bar system is somewhat embedded in the code.  But remember you have to take into account that you are stepping through every 5 minute bar and things change from one bar to the next.

vars: buysToday(0),shortsToday(0),curTotTrades(0),mp(0),tradeZoneTime(False);


if d <> d[1] then
begin
curTotTrades = totalTrades;
value1 = .2 * average(Range of data2,5);
value2 = value1 * 5;
buysToday = 0;
shortsToday = 0;
tradeZoneTime = False;
end;

mp = marketPosition;

if totalTrades > curTotTrades then
begin
if mp <> mp[1] then
begin
if mp[1] = 1 then buysToday = buysToday + 1;
if mp[1] = -1 then shortsToday = shortsToday + 1;
end;
if mp[1] = -1 then print(d," ",t," ",mp," ",mp[1]," ",shortsToday);
curTotTrades = totalTrades;
end;
if t > sess1StartTime and t < sess1EndTime then tradeZoneTime = True;

if tradeZoneTime and buysToday = 0 and mp <> 1 then
buy next bar at opend(0) + value1 stop;

if tradeZoneTime and shortsToday = 0 and mp <> -1 then
sellShort next bar at opend(0) - value1 stop;

setProfitTarget(value2*bigPointValue);
setStopLoss(value2/2*bigPointValue);
setExitOnClose;
Proper Code to Replicate the Daily Bar System with Accuracy

Here’s a few trade examples to prove our code works.

Looks Right!

Okay the code worked but did the system?

Uh? NO!

Conclusion

If you need to know what occurred first – a high or a low in a move then you must use intraday data.  If you want to have multiple entries then of course your only alternative is intraday data.   This little bit of code can get you started converting your daily bar systems to intraday data and can be a framework to develop your own day trading/or swing systems.

Can I Prototype A Short Term System with Daily Data?

You can of course use Daily Bars for fast system prototyping.  When the daily bar system was tested with LIB turned on, it came close to the same results as the more accurately programmed intraday system.  So you can prototype to determine if a system has a chance.  Our core concept buyt a break out, short a break out, take profits and losses and have no overnight exposure sounds good theoretically.  And if you only allow 2 entries in opposite directions on a daily bar you can determine if there is something there.

A Dr. Jekyll and Mr. Hyde Scenario

While playing around with this I did some prototyping of a daily bar system and created this equity curve.  I mistakenly did not allow any losses – only took profits and re-entered long.

Wow! Awesome! Holy Grail Uncovered. Venalicius Cave!

Venalicius Cave!  Don’t take a loser you and will reap the benefits.  The chart says so – so its got to be true – I know right?

The same chart from a different perspective.

You Start and End at the Same Place. But What A Ride. Yikes!

Moral of the Story – always look at your detailed Equity Curve.  This curve is very close to a simple buy and hold strategy.   Maybe a little better.

Highly Illogical – Best Guess Doesn’t Match Reality

An ES Break-Out System with Unexpected Parameters

I was recently testing the idea of a short term VBO strategy on the ES utilizing very tight stops.  I wanted to see if using a tight ATR stop in concert with the entry day’s low (for buys) would cut down on losses after a break out.  In other words, if the break out doesn’t go as anticipated get out and wait for the next signal.  With the benefit of hindsight in writing this post, I certainly felt like my exit mechanism was what was going to make or break this system.  In turns out that all pre conceived notions should be thrown out when volatility enters the picture.

System Description

  • If 14 ADX < 20 get ready to trade
  • Buy 1 ATR above the midPoint of the past 4 closing prices
  • Place an initial stop at 1 ATR and a Profit Objective of 1 ATR
  • Trail the stop up to the prior day’s low if it is greater than entryPrice – 1 ATR initially, and then trail if a higher low is established
  • Wait 3 bars to Re-Enter after going flat – Reversals allowed

That’s it.  Basically wait for a trendless period and buy on the bulge and then get it out if it doesn’t materialize.  I knew I could improve the system by optimizing the parameters but I felt I was in the ball park.  My hypothesis was that the system would fail because of the tight stops.  I felt the ADX trigger was OK and the BO level would get in on a short burst.  Just from past experience I knew that using the prior day’s price extremes as a stop usually doesn’t fair that well.

Without commission the initial test was a loser: -$1K and -$20K draw down over the past ten years.  I thought I would test my hypothesis by optimizing a majority of the parameters:

  • ADX Len
  • ADX Trigger Value
  • ATR Len
  • ATR BO multiplier
  • ATR Multiplier for Trade Risk
  • ATR Multiplier for Profit Objective
  • Number of bars to trail the stop – used lowest lows for longs

Results

As you can probably figure, I  had to use the Genetic Optimizer to get the job done.  Over a billion different permutations.  In the end here is what the computer pushed out using the best set of parameters.

No Commission or Slippage – Genetic Optimized Parameter Selection

Optimization Report – The Best of the Best

Top Parameters – notice the Wide Stop Initially and the Trailing Stop Look-Back and also the Profit Multiplier – but what really sticks out is the ADX inputs

ADX – Does it Really Matter?

Take a look at the chart – the ADX is mostly in Trigger territory – does it really matter?

A Chart is Worth a 1000 Words

What does this chart tell us?

70% of Profit was made in last 40 trades

Was the parameter selection biased by the heightened level of volatility?  The system has performed on the parameter set very well over the past two or three years.  But should you use this parameter set going into the future – volatility will eventually settle down.

Now using my experience in trading I would have selected a different parameter set.   Here are my biased results going into the initial programming.  I would use a wider stop for sure, but I would have used the generic ADX values.

George’s More Common Sense Parameter Selection – wow big difference

I would have used 14 ADX Len with a 20 trigger and risk 1 to make 3 and use a wider trailing stop.  With trend neutral break out algorithms, it seems you have to be in the game all of the time.  The ADX was supposed to capture zones that predicated break out moves, but the ADX didn’t help out at all.  Wider stops helped but it was the ADX values that really changed the complexion of the system.  Also the number of bars to wait after going flat had a large impact as well.  During low volatility you can be somewhat picky with trades but when volatility increases you gots to be in the game. – no ADX filtering and no delay in re-Entry.  Surprise, surprise!

Alogorithm Code

Here is the code – some neat stuff here if you are just learning EL.  Notice how I anchor some of the indicator based variables by indexing them by barsSinceEntry.  Drop me a note if you see something wrong or want a little further explanation.

Inputs: adxLen(14),adxTrig(25),atrLen(10),atrBOMult(1),atrRiskMult(1),atrProfMult(2),midPtNumBar(3),posMovTrailNumBars(2),reEntryDelay(3);
vars: mp(0),trailLongStop(0),trailShortStop(0),BSE(999),entryBar(0),tradeRisk(0),tradeProf(0);
vars: BBO(0),SBO(0),ATR(0),totTrades(0);

mp = marketPosition;
totTrades = totalTrades;
BSE = barsSinceExit(1);
If totTrades <> totTrades[1] then BSE = 0;
If totalTrades = 0 then BSE = 99;


ATR = avgTrueRange(atrLen);

SBO = midPoint(c,midPtNumBar) - ATR * atrBOMult;
BBO = midPoint(c,midPtNumBar) + ATR * atrBOMult;

tradeRisk = ATR * atrRiskMult;
tradeProf = ATR * atrProfMult;

If mp <> 1 and adx(adxLen) < adxTrig and BSE > reEntryDelay and open of next bar < BBO then buy next bar at BBO stop;
If mp <>-1 and adx(adxLen) < adxTrig AND BSE > reEntryDelay AND open of next bar > SBO then sellshort next bar at SBO stop;

If mp = 1 and mp[1] <> 1 then
Begin
trailLongStop = entryPrice - tradeRisk;
end;

If mp = -1 and mp[1] <> -1 then
Begin
trailShortStop = entryPrice + tradeRisk;
end;

if mp = 1 then sell("L-init-loss") next bar at entryPrice - tradeRisk[barsSinceEntry] stop;
if mp = -1 then buyToCover("S-init-loss") next bar at entryPrice + tradeRisk[barsSinceEntry] stop;


if mp = 1 then
begin
sell("L-ATR-prof") next bar at entryPrice + tradeProf[barsSinceEntry] limit;
trailLongStop = maxList(trailLongStop,lowest(l,posMovTrailNumBars));
sell("L-TL-Stop") next bar at trailLongStop stop;
end;
if mp =-1 then
begin
buyToCover("S-ATR-prof") next bar at entryPrice -tradeProf[barsSinceEntry] limit;
trailShortStop = minList(trailShortStop,highest(h,posMovTrailNumBars));
// print(d, " Short and trailStop is : ",trailShortStop);
buyToCover("S-TL-Stop") next bar at trailShortStop stop;
end;