Friday, March 19, 2010

Osikani Market Noise Indicator

2010-03-19_2243 A Brief Treatise On Market Noise (and an indicator)

This description is a very simplified, almost but not quite naive discussion of how to determine market noise based on the idea that the way that we look at market data is in effect a digital sampling of an analog signal. It never gets mathematically dense, as it is a bit oversimplified, but just in case you are not interested in the understanding behind the indicator, you can jump to the code that is appended to this post.
1. To get started, why is market data a digital sample of an analog signal?
Given any chart interval, we specify one price (most often the close), as the price for that time. In reality, the price moved within a range (quasi-continuous, as even within that range, prices can only move in discrete ticks). Therefore, by specifying only one price for each interval, we have in effect taken discrete samples of the continuous range and are using it to represent the progression of prices. That is the definition of digital sampling. So we theorize initially that the sampling should be amenable to principles of digital signal processing, where the analog signal is made up of the continuous stream of market prices, and the samples are the prices that we use to mark each arbitrary chart interval.
With this simplified view of market prices, let us see how we can determine a value for noise.
2. Using our anecdotal experiences, I am sure that most peoples' entry price is actually the middle of the price candle. We all know that, like magic, as soon as we enter our order, the price moves against us, before moving in our direction, if at all. This of course, excludes those super traders who always buy the bottom tick, sell the top tick, and never have a losing trade. They do not need stinking Osikani to give them this crap. Therefore, we are going to say that the sample price is the mid price. By most simplified definitions, this would be, and often is, called the average price.
Again drawing a parallel with the world of DSP, let us assume that we have a constant signal. In terms of market price, we essentially have a series of candles that have the same average price; in which case most moving averages of short enough duration would be flat. Again, as we all know, the candles would be have OHLC. In other words, each candle would have a range, but the same average price. We normally call it chop. In the DSP world, we would take a measure of that fluctuation, call it noise, and design a filter to remove it, so that we have a clean signal that is the flat average signal. How do we do that with price?
Let us take an example. Let us say that the last 30 candles have caused our EMA to flatline, and that these candles have about 20 (just an arbitrary majority that I chose to illustrate the point) candles with a 4 tick range, and that most of the other candles have ranges between 0 and 6 ticks, and even a spike or two with an outlier range like 10 ticks.
In the DSP world, we would use some fancy statistical measure like a mean-square deviation, and some transform to determine the noise. We need not get so fancy. All we want is an intuitive definition of the noise. For most, this would simply be the most likely excursion from the average price that we have been watching for 30 candles and getting frustrated. (At this point, some of us would be about ready to bring out the Magnum .44 and take it to the 'puter). In other words, we would say that we are most likely to have an excursion of half the range on either side. Until we break out of that range, we are effectively trapped within the market noise. So we define market noise as the most likely value of "half the range", or half the value of the most likely range.
Here is where we think statistically of the meaning of "most likely value". To most, that means "the mean", the most traditional value of what is usually thought of as the average. Actually, there are two other measures of "the average". In this case, for reasons that are too mathematically involved to explain, the more likely correct "average" is "the mode". (To make a simplistic analogy, think of it like this: If you went to a fashion show, what would be the correct measure of the average height of the model's shoe heels? Obviously, it would be the height of the heels that most of the models were wearing, not the arithmetic mean, which in this particular case would be particularly meaningless, as nobody would likely have that shoe measurement).

Comparison of mean, median and mode

So we now say that the market noise is half the modal range, and we use this definition even if the average price is fluctuating. After all, a moving average is merely a simplified attempt to linearize trending data.
3. The next principle we take from DSP is that a signal is only valid if it is at least 2 times the noise (no need to get fancy with decibels and such arcana).
4. Given this, we design our system to show us the threshold of noise before a signal fails to be valid. So we use the range. i.e., 2 times the (previously defined) "market noise" - which is half the range, as the target excursion, which if not exceeded would indicate that the move was noise after all. The idea, then, is to take advantage of market noise to exit a portion of the position, so as to cover costs, take some risk off the table, grab a tidy little profit; and then let the rest ride, just in case we are getting a signal rather than noise. We can always grab the rest and run, if it is taking too long; and we can move up our stop to ensure that, even if stopped out, the trade would still show an albeit little profit. Obviously, this is a scalper's tool.
Hence, the indicator that we come up with simply measures the mode of ALL candles from the beginning of the day, and uses that as the measure of market noise for the day, at any given time. In effect, while the indicator is called "market noise", it is actually plotting the value that represents the largest signal that fails to be a valid signal. Think if this as saying that this is the value that, if you entered in the most adverse position of the candle, price could move against you, and you would still not have a valid reversal signal.
After that long treatise, here is the code, as promised earlier. We note the assumptions that we have made.
a) We arbitrarily say that the maximum value of "market noise" is 4 ticks. The indicator was designed with /ES in mind, but provides an input for you to decide what is the quantum of price movement such that that movement represents noise to you. Simply define your NoiseUnitTickSize to be a quarter of the maximum price excursion that you would consider as “noise”.
b) We arbitrarily define the 1-minute timeframe as the limit of time within which we will measure noise. In other words, we say that the 1-minute chart is noise. However, because of the way that TOS defines tick charts, ANY tick chart can also be used to represent a noise chart for the purposes of this indicator. This was actually a fortuitous accident when I was writing the indicator. I simply decided that the accidental result was so good that I kept it that way instead of sticking to the original specification. I have found that on the /ES, interestingly enough, a 1600-tick chart and the 1-minute chart usually indicate the same noise value.
This means that the indicator will plot on any tick chart or 1-minute chart, but will not plot on any chart longer than the 1-minute timeframe. On slower timeframes, you can enable the actual counts of ranges to show you the counts of 1, 2, 3, and 4 tick bars. Those plots are normally hidden.
Needless to say, TOS indicators are plain text, so it is trivial to change this on an ad-hoc basis. If there is enough demand, I can always write in an option to simply remove the timeframe limit, and show the "market noise" values on all timeframes. The problem here is that by its very design, a large timeframe chart will almost always pin the value of market noise at 4, so is rather pointless in my humble opinion.

The Code

# Osi_MarketNoise ver. 1
# Originally written by Osikani
# koganam at nc rr com
# ver 1.0 - Last Update Feb. 17, 2010
declare lower;
input NoiseUnitTickSize = 0.25;
input PointSize = 2;
input Market_Open_Time = 0930;
input Market_Close_Time = 1615;
def Day = getDay();
def Range = High[0] - Low[0];
def pastOpen = if((secondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = if((secondsTillTime(Market_Close_Time) > 0), 0, 1);
def marketOpen = if(pastOpen and !pastClose, 1, 0);
def MarketOpenFilter = if Marketopen then 1 else double.NaN;
rec OneTick = if !MarketOpen or Day[1] != Day then 0 else if Range == NoiseUnitTickSize * 1 then OneTick[1] + 1 else OneTick[1];
rec TwoTick = if !MarketOpen or Day[1] != Day then 0 else if Range == NoiseUnitTickSize * 2 then TwoTick[1] + 1 else TwoTick[1];
rec ThreeTick = if !MarketOpen or Day[1] != Day then 0 else if Range == NoiseUnitTickSize * 3 then ThreeTick[1] + 1 else ThreeTick[1];
rec FourTick = if !MarketOpen or Day[1] != Day then 0 else if Range == NoiseUnitTickSize * 4 then FourTick[1] + 1 else FourTick[1];
def Noise = Max(FourTick, Max(ThreeTick, Max(TwoTick, OneTick))) * MarketOpenFilter;
plot MarketNoise = if Noise == FourTick then 4 else if Noise == ThreeTick then 3 else if Noise == TwoTick then 2 else if Noise == Onetick then 1 else 0;
MarketNoise.SetHiding(getAggregationPeriod() > AggregationPeriod.MIN);
plot "1 Tick" = OneTick;
plot "2 Tick" = TwoTick;
plot "3 Tick" = ThreeTick;
plot "4 Tick" = FourTick;
# Hide the tick count plots by default
"1 Tick".hide();
"2 Tick".hide();
"3 Tick".hide();
"4 Tick".hide();

Our tutorial on the use of the MarketNoise Indicator
Let us use data from today, March 19, 2010. We shall look at a trade, in this case successful.
Shown is the chart setup.
The chart on the left is a 1-minute /ES chart with the MarketNoise Indicator.
The chart on the left is a 1600-tick chart with a MarketNoise Indicator.
Trades are taken off of the 1600-tick chart, NOT the 1-minute chart. The only real purpose of the 1-minute chart is to give us the MarketNoise value.
Please note that this is not a complete description of my entry and confirmation method. I am just using it to illustrate the use of the MarketNoise Indicator for profit taking and risk control. You have to use your own entry method in which you have great confidence. That will depend on your style and comfort levels. Granted that I did actually take these trades, this is not a recommendation that you use this entry method. There is a little more to it than just the "Sit On Hands" pattern that I describe, which uses only the last 3 bars.
That having been said, let us begin.
We started with weak internals, and had been going down, so we will enter short on a retrace, provided our entry conditions are satisfied. We do not care about the depth of the retrace.
Our entry is going to be based on (inter alia), a lack of buying interest on a try to the upside. The conditions we shall use are:
1. High greater than the high of both of the last 2 bars.
2. Volume less than the volume of the last 2 bars.
3. Range of bar less than the range of EITHER of the last 2 bars.
This is the initial trigger condition.
The trigger bar will be the first bar that closes red, as we are seeking to go short.
Once we have our red bar, we shall get ready to enter.
The first time we have entry conditions is the bar at 9:47 EDT (on the 1600-tick chart). Note that the condition is NOT satisfied on the 1-minute chart. If it were, we would have even more confidence in the entry.
At 9:50 EDT, we get the first red bar. This is the trigger bar, NOT the entry bar, but it gives us all we need to know.
We calculate as follows:
MarketNoiseValue = 3 ticks. This happens to be the same for the 1-minute chart and the 1600-tick chart.
We are going to enter on the first tick below this bar, WITHOUT waiting for a close, so we shall enter when we see the first touch of 1160.75.
EntryPrice = 1160.75 + MarketNoiseValue = 1161.5
InitialStop = EntryPrice + MarketNoiseValue + 1-tick = 1162.5
FirstTarget = MarketNoiseValue = 3-tick
SecondTarget = (2 * MarketNoiseValue) + 1-tick = 7-tick
ThirdTarget = initially placed at 12 ticks. Will be managed if second target is hit.
If there cannot be a third target, you need to decide if you will use the second target and be out, or if you want to manage the second part of the trade. The first part of the trade is inviolate. I am not stating how many contracts I trade, so for this example we shall assume 3 contracts, just so we can illustrate what happens.
At 9:55 EDT, we get the entry bar, and are triggered in at 1161.5, when the market ticks up through our limit order.
At 10:00 EDT, we hit the first target. $37.50. Assuming standard TOS rate of 7.00 per round trip, total cost of trade WILL be $21, no matter what, so we have banked $16.50.
We move the stop to 1-tick behind our entry. If we retrace to our stop and hit it, we shall lose another $25, losing $8.50 on the trade, after we take commissions into account. This time we did not, so we sit tight.
At the Overnight Low (a natural pivot, that I would have used to adjust this target, if it had not been spot on it), our second target is hit, at 10:02 EDT. We have now made a total of 10 ticks on the trade. Stop is moved to 3-ticks past entry. If we retrace to the stop, we make $25 on the last contract, a total of 12 ticks on the entire trade. Agreed that is a mere 1 point per contract, but I have lost enough money being greedy, so $129 (150 - 21) is plenty for me. That is assuming that I traded 3 contracts this way.
Now, hopefully, we have the runner that the trading gods may give us, just in case the bullcrap has ended. However, we are at a natural pivot. At the very first bar that stays entirely above the Overnight Low, I shall take the money and run. As it happens, I can hold on, until I see the "Lack of sellers" bar at 10:16 EDT, and get out when the next green bar violates the high of the previous bar.
Question: What was the target I was eyeing to get out if we stalled? The natural pivot at yesterday's low.
Question: Why did I exit early? I would rather be out of a trade wishing that I were in, than in wishing that I were out.
Total ticks on trade: 3 + 7 + 14 = 24. So it turned out at 2 points per contract, much better than I had hoped for. Subtract commission.
Believe me; they do not all turn out this well. Matter of fact, most trades usually end up with taking that 2-tick profit on the last contract, or a scratch.
However, I am more interested in making a profit, no matter how small, on as many of my trades as possible. It all adds up. I have even scratched the rest of the trade if the action is taking too long in my opinion. Most trades get to the first target. That is the whole point: the first target is within the normal market noise. All we are doing is taking advantage of market noise to give us a free ride on the rest of the trade.
Any other questions, just ask.

blog comments OCCASIONALLY powered by Disqus