[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ELA Question: Entry as soon as MA xover vs at the close



PureBytes Links

Trading Reference Links

> How can I program a system to enter as soon as criteria are met
> versus close of the bar?  Please see code example below: 
> If Average((H+L)/2,11) > Average((H+L)/2,20) then buy at market;

As Scott Hoffman explained, you CANNOT execute system code in the 
middle of a bar.  Your system code executes ONLY at the close of a 
bar.  The only way to cause position changes intrabar is by using 
stops, and those must be placed on the previous bar.

If you want to act intrabar, you will have to move to a smaller 
timeframe.  E.g. let's say you're currently running on 60min bars.  
You want to buy when the 11-bar avg (using 60min bars) of (H+L)/2 
crosses the 20-bar avg.

You could run your system on 5min bars, and compute the equivalent 
averages at the end of every 5 minutes.  At each 5min close you would 
compute the H and L of the current "60min bar" -- the part of the 
60min bar that has been built so far with your 5min bars -- and 
compute the average of the previous N-1 "60min bars" (which won't 
change while you build this 60min bar) and the current one.  You'll 
probably have to store the last N bars' H & L in arrays.  Then if the 
current 5min bar has a high enough H to trip your buy condition, you 
buy at the close of that 5min bar.

You could do this for any size bar you want -- run it every 1min, or 
whatever -- to get the time resolution you want.  Heck, you could run 
it on a 1 tick chart if you wanted, but I wouldn't recommend it.

Note, BTW, that executing "intrabar" like this will cause different 
results than if you act only at the end of the 60min bar.  It will 
enter a strong move earlier, which is what you want, but there will 
also be cases where it will enter when an end-of-bar approach won't.  
E.g. if the price goes up intrabar high enough to trip the entry, and 
then turns down and sets a new low before the end of the 60min bar, 
the intrabar approach will be long but the end-of-bar approach 
wouldn't.  

Aggregating ticks into bars is an implicit noise-filtering mechanism, 
and it can avoid unwanted trades.  Executing on finer bar resolution 
does NOT always produce better results!

Gary