Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Shell128

Filtering an Indicator

Recommended Posts

I have developed an indicator that I would like to feed into my system. The indicator usually outputs small values 99.9% of the time. However, it's the large values that I care about. The indicator output looks like a series of spikes surrounded by noise. I would like to process this signal such that the background noise is filtered out and the spikes are less intense, but hold their value longer. One way to do this would be to high-pass filter or threshold the signal then apply an infinite impulse-response filter such as an exponential moving average to "hold" the spikes so that they stay around for longer. But I would like to preserve a bit more information. I would like the intensity of processed signal at some time to be proportionate to:

 

1) Intensity of last spike

2) Time last spike was observed (intensity would decay as time of last observation increases)

3) Spike intensity relative to background noise

 

Does anyone know of a good way (simple is better) to create such filter? I thought about taking the difference of two moving averages...one longer window moving average to capture the background noise and then subtract that from a shorter moving average to capture the spikes. Problem with that approach is that the filter would likely either allow too much of the noise to pass (pass-band too large) or would not hold the spike on the output long enough.

Share this post


Link to post
Share on other sites

You could add another filter such as a DMI with ADX - when the ADX is over (for e.g.) 25 then a buy would be taken if the DMI+ is above the DMI- and a sell if the DMI- is above the DMI+ and your indicator is also signaling a large value. You could change the value of the length of the DMI/ADX to print faster such as 11 instead of the conventional 14. When the ADX is over 40 you might want to start looking to get out of your trade.

 

Another way you could consolidate your indicator is to change the way the bars are structured. For example, minute based charts are time-bound and a lot can happen before the bar is allowed to change by the setting you use so that a lot of action occurs within that bar's time-frame as things be-bop around. Tick charts (e.g. 500, 1000, 2000 ticks) show momentum when it occurs as the bars are filling up faster; and range bar charts are even better from this point of view e.g. setting on a range of 1.5 and an 8 tick interval - much more stable.

Share this post


Link to post
Share on other sites

I know what you are talking about, and I've programed code to deal with situations like this. What trading platform are you using? You could set up a counter to hold you signal as valid for a certain number of bars. So as soon as that big spike happens, it would show a signal for a certain number of bars, according to the counter. Count 5 bars after the signal. I don't know if this is a good solution for you, but I'm just trying to do some "brain storming" here.

If you want the most current spike to be proportionate to the last spike, you could hold the value of that last spike in some variable, and then make a comparison. So it seems like you want to know if the signal had a higher high, or a weaker high, etc. Maybe you need a way to keep track of the current highs and lows.

I'm just guessing here about what your indicator might look like in a lower study/sub graph. Sounds like you need someone who can make the programing happen. Is there a programing group you could join for the language that your platform uses? You could ask the customer service support for the trading platform you are using if there is any programing help "out there" somewhere.

Basically what you need is to find some appropriate ratio that condenses things down to make the data easier to "read". But the ratio may need to be dynamic, as the data is cycling through large ranges. This is really a math problem.

Let's see, I wonder if a fractional exponent would somehow help here. If you could make the small values bigger, and the big values smaller, it could smooth the data. So you are looking at a, sort of inverse relationship.

You could experiment with a spreadsheet, and feed different exponents into the formula to see how the numbers react. Put a bunch of numbers into a column in a spreadsheet that are representative of the data you might have. Then write a formula for the output in the next column and copy it down. Have the formula reference a cell that you could change, that would affect all the formulas.

If you looked at the graph of the curve for something like x^2, (x squared) it would be a curve getting steeper and steeper as "x" gets bigger 2x2, 4x4, 100x100.

But you want the big numbers to get smaller. When you get a real big spike, you want that number to be cut down to a smaller size. I think a fractional exponent will do that x^1/3.

Something to think about.

Share this post


Link to post
Share on other sites
can you post some chart examples?

 

It looks like this:

 

88315252.jpg

 

That's zoomed out so you can see the big spikes. When you zoom in, there's noise in-between the big spikes. Most of the chart is noise and the big spikes don't take up as much time as they appear on the plot above.

 

Iris and Tradewinds, I appreciate the comments. My current thoughts on this indicator is to use a modified exponential moving average. Change the weight factor for large changes in value upwards only. For example, if the past 1000 point average is 10 and the next value is 900, instead of using the minimum weight of 0.001, use a weight factor based on the ratio between new value and past average, like 0.4 to allow the indicator to ratchet up quickly. Then then change the weight factor back to some smaller value to allow the indicator to decay off with time. If I knew more about filters, I'd probably know of a standard filter that behaves in this way. Does anyone know?

 

Basically, I'm looking for a filter that reacts quickly to spikes in one direction, but then decays off gradually to the longer-term average value.

Edited by Shell128
Added last comment

Share this post


Link to post
Share on other sites

Thanks for the chart example. To me it looks like a volume histogram, with up volume positive and down volume negative. I've attached a .jpg file of a lower study that shows volume in green histogram bars, and then a red line. The red line has much lower highs. It fluctuates much less, but it still maintains it's respective ratios. If a spike is higher, then the red line is higher. All I did was raise that data to a fractional exponential power of 0.75. So instead of the power being squared, 2, or cubed, x^3, the exponent is less than 1. If you look at the attachment you will see that the red line does a very good job of compressing the spikes down and squeezing the data into a much tighter range.

SpikesModifiedLower.JPG.a0443de00c3b554977ca9dd719aa7cef.JPG

Share this post


Link to post
Share on other sites

his is John Ehler's generic filter for Tradestation - perhaps this might help:

 

{

Here is a generic EasyLanguage version of the nonlinear Ehlers filter, based on John Ehlers's article in this issue,

"Nonlinear Ehlers Filters."

This EasyLanguage filter accepts the coefficients statistic as an input.

In the following EasyLanguage indicator code, the Coef input is set to

AbsValue( MedianPrice - MedianPrice[5] ),

and the price input is set to MedianPrice. MedianPrice is a built-in function in EasyLanguage that

returns (H + L) / 2.

With these values for the inputs, the indicator is equivalent to the momentum-based Ehlers filter,

for which a specific EasyLanguage version has been developed by John Ehlers and is given at the top of this

Traders' Tips section.

 

To derive the distance coefficient Ehlers filter, which is also described in Ehlers's article,

the Coef input value in the following EasyLanguage can be replaced with DistanceSqrd( MedianPrice, 15 ).

DistanceSqrd is a custom function, and the code for that follows the indicator code.

}

 

inputs:

 

Price( MedianPrice ), //MedianPrice = (H+L)/2

Length( 15 ) ,

UseDistSquared ( False )

;

 

variables:

Num( 0 ),

SumCoef( 0 ),

Count( 0 ),

Filt( 0 ) ,

Coef ( 0 )

;

 

If UseDistSquared = False then begin

Coef = ( AbsValue( MedianPrice - MedianPrice[5] ) ) ;

end else

Coef = DistanceSqrd ( Price, Length ) ;//DSqrd + Square( Price - Price[LookBack] ) ;

 

Num = 0 ;

SumCoef = 0 ;

 

for Count = 0 to Length - 1

begin

Num = Num + Coef[Count] * Price[Count] ;

SumCoef = SumCoef + Coef[Count] ;

end ;

 

if SumCoef <> 0 then

Filt = Num / SumCoef ;

 

Plot1( Filt, "Ehlers" ) ;

 

 

 

Condition1 = FALSE ;

if Condition1 then

Alert( "" ) ;

Share this post


Link to post
Share on other sites
It looks like this:

 

88315252.jpg

 

That's zoomed out so you can see the big spikes. When you zoom in, there's noise in-between the big spikes. Most of the chart is noise and the big spikes don't take up as much time as they appear on the plot above.

 

Iris and Tradewinds, I appreciate the comments. My current thoughts on this indicator is to use a modified exponential moving average. Change the weight factor for large changes in value upwards only. For example, if the past 1000 point average is 10 and the next value is 900, instead of using the minimum weight of 0.001, use a weight factor based on the ratio between new value and past average, like 0.4 to allow the indicator to ratchet up quickly. Then then change the weight factor back to some smaller value to allow the indicator to decay off with time. If I knew more about filters, I'd probably know of a standard filter that behaves in this way. Does anyone know?

 

Basically, I'm looking for a filter that reacts quickly to spikes in one direction, but then decays off gradually to the longer-term average value.

 

I would recommend reading up on Ehler.

He's got lots of filters.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • INO Inovio Pharmaceuticals stock low volume pullback to 9.77 support area, watch for local breakout above 10.5, https://stockconsultant.com/?INO
    • GOOG Alphabet stock good trend, top of range breakout watch above 180.55, https://stockconsultant.com/?GOOG
    • Date: 7th June 2024. ECB closer look: All options open for the second half of the year! ECB officials continue to dampen rate cut speculation, following on from Lagarde’s hawkish comments yesterday. Officials have been out in force this morning to continue stressing that the inflation outlook remains uncertain and that the central bank is not committing to a particular rate path for the rest of the year. The ECB cut rates by 25 basis points, but as we expected it was a “hawkish” cut that left all options open for the second half of the year. Lagarde repeatedly stressed that future decisions will be data dependent, and even refused to confirm that yesterday’s move was the first step of an easing cycle. Rate cuts in September and December are still a possibility, but not cast in stone. Simkus admitted that there may be more than one rate cut this year, but on the whole, the comments were designed to keep a lid on speculation that the central bank kicked off a rate cut cycle yesterday. Austria’s central bank head Holzmann went on record yesterday to confirm that he was the sole dissenter objecting to a cut yesterday, and so far the doves have been quiet, which is helping to affirm Lagarde’s hawkish message yesterday.   Details of the Rate Cut The ECB delivered the first rate cut in five years and lowered key rates by 25 basis points. The deposit rate is now at 3.75% and the main refinancing rate at 4.25%. It was a “hawkish cut,” as near term inflation forecasts were revised higher, and Lagarde flagged that domestic inflation remains high. The statement stressed that the ECB is not pre-committing to a particular rate path, and the comments leave all options on the table for the second half of the year.   Economic Activity and Forecasts  The ECB noted the improvement in economic activity through the first quarter of the year. Lagarde also highlighted that manufacturing is showing signs of stabilization, with stronger exports expected to support growth in coming quarters. At the same time, monetary policy should be less of a drag on demand over time, according to the ECB. The new set of forecasts show GDP rising 0.9% this year, which is more than the 0.6% expected back in March. The forecast for 2025 has been revised slightly down to 1.4% from 1.5% previously, and the ECB still expects a slight acceleration to 1.6% for 2026. The inflation forecast for this year was raised to 2.5% from 2.3%, and the projection for 2025 was hiked to 2.2% from 2.0%. As such, inflation will fall toward the target later than previously anticipated, though the forecast for 2026 was left unchanged at 1.9%. This means the headline rate is still expected to fall below the target at the end of the forecast horizon.   Upside Risks to Inflation The statement noted upside risks to the inflation outlook from wages and profits, which could be higher than currently anticipated. Geopolitical tensions and extreme weather events could also push up prices once again, according to the ECB. At the same time, the ECB acknowledged that inflation could come in lower than anticipated if monetary restrictions have more of a dampening effect than currently anticipated, or if global growth weakens more than projected.   The press conference was mainly dedicated to driving home the point that future decisions will depend on data available at the time of the respective meeting. Lagarde even refused to confirm that the central bank has effectively kicked off an easing cycle, and said in response to a question that she wouldn’t necessarily say that the ECB started a “dialing-back process”. She suggested it is likely, but refused to confirm it, which in theory means rates could actually go up again. This seems unlikely, given that this move was a near unanimous decision, but its makes clear that the ECB will not cut rates at every meeting and that the outlook for the rest of the year is still very much open. The ECB still thinks that monetary policy needs to remain restrictive for the foreseeable future against the backdrop of high domestic inflation. However, as chief economist Lane suggested recently, officials will have to debate at every meeting whether the data allows the central bank to dial back the degree of restrictiveness.   Employment and Inflation Dynamics Wage growth, profits, and services price inflation will remain the key numbers to watch through the rest of the year. Lagarde pointed to data on the compensation of employees, due to be released tomorrow, but also flagged that current wage agreements are often still backward looking, as they reflect attempts to compensate for the sharp rise in prices since the start of the Ukraine war. As we flagged previously, the multi-year wage agreements in Germany are a prime example of that. However, as Lagarde highlighted, the deals on the table so far show sharp increases for this year, but also imply a slowdown in wage growth in coming years. However, unemployment is at a record low and the number of vacancies has dropped only slightly. At the same time, service price inflation remains stubbornly high, which suggests that companies have sufficient room to pass on higher labor costs. With real disposable income rising, thanks to lower inflation and higher wages, companies could find it even easier to hike prices in the second half of the year, and yesterday’s rate cut is also likely to boost demand. In the current situation, this could add to domestic price pressures. Looking ahead, the only thing that is clear is that Lagarde did her best to keep expectations of back-to-back cuts under control. The chances still are that the ECB will deliver two more 25 basis point cuts in September and December, but at this point, nothing is cast in stone. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Andria Pichidi Market Analyst HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • TRGP Targa Resources stock narrow range breakout watch above 119.02, https://stockconsultant.com/?TRGP
    • ROOT stock, short term downtrend break, bullish stats , https://stockconsultant.com/?ROOT
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.