stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

iMAOnArray for smoothing - Help needed
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5604
Page 1 of 1
Author:  Bruster400 [ Tue Jan 15, 2019 1:21 pm ]
Post subject:  iMAOnArray for smoothing - Help needed

Hi,

I'm trying to write a "smoothed" version of the bands indicator. The idea is that it will become a "trend" indicator highlighting strong trends and also periods of pull-back and consolidation. The attached version sort of works.... The recent data is fine and it's doing what I want it to. The problem is the data towards the oldest bars gives strange results with the line values going all over the place.

It's a very simple indicator (to match my coding skills :oops: ). I basically copy all the values of iBands into 3 buffers and then I apply iMAOnArray on these buffers. I realise that this function doesn't work in series so I've tried reversing the buffers but that hasn't solved it. I also thought that I needed to start the loops at different indexes - The first time round we need enough bars for the iBands to run but the second, smoothing run through we need enough completed ibands values to be able to apply the smoothing MA - hence limit2. This doesn't really help.

I've checked the ibands data and it's populated correctly all the way back to the oldest data point within those buffers so I know the problem is with iMAOnArray. Can anyone tell me how this is supposed to be correctly applied?

Thanks

Bruce
Author:  renexxxx [ Tue Jan 15, 2019 8:22 pm ]
Post subject:  iMAOnArray for smoothing - Help needed

Hi Bruce,

You have to run your second loop also from left to right. I have made some small changes to your code and I think that it does what you want it to do. Try eg. with BandsPeriod=10 and SmoothingPeriod=10.

Cheers ... René.
Author:  Bruster400 [ Wed Jan 16, 2019 8:39 am ]
Post subject:  iMAOnArray for smoothing - Help needed

René,

Thanks once again for helping me out!! I've taken a look at the changes you've made and I understand what you've done. I had reversed the calculation direction because I'd reversed the buffer to series false. I tried doing the other way round and it didn't seem to make any difference - buffers are obviously more forgiving than arrays in EAs?

However, I'm still getting the same issue with the changes you've made. In the screen grab below you can see the strange plots that the oldest smoothed data is giving:
2019-01-16_0812.png
I've looked back at what I'm doing with limits to ensure that I'm giving the calculations enough valid back data and I think I've got it right:
2019-01-16_0810.png
While doing this I couldn't work out why the iMAOnArray couldn't just calculate a simple average from the bolli data..... and then I realised that I wasn't doing a "simple" average, I was smoothing with an exponential average. This seems to be what is causing the problem. If I change the smoothing to SMA then I don't have the issue. There must be something about the EMA calculation that either uses more back data than I've allowed for or runs iterative calculations on its own results that send the older values exponential when EMPTY_VALUE starts getting used. I've tried initialising with zero but this doesn't work either.

I don't want to waste other people's time on this more than I have done already so I think I'll look at using the SMA smoothing and see if that works for me. Alternatively I can leave it alone and just not scroll the charts back too far!! :smile: If anyone knows why the EMA smoothing has this issue let me know.

Thanks again for your time helping me René. I really do appreciate it.

Bruster
Author:  Bruster400 [ Wed Jan 16, 2019 10:18 am ]
Post subject:  iMAOnArray for smoothing - Help needed

For those interested in why I'm coding this indi......

I'm a trend trader. I trade the H1 and above charts looking for H1timeframe moves in line with the longer timeframe trend. I have a number of ways of telling the HTF trend but I'm coding this indi as a potential H1 entry signal. My ideal entry is where price pulls back against the HTF trend and then rejoins the trend for my entry. This indicator is supposed to watch for just that.

The idea is that when price is between the bands it's pulling back or ranging. When price breaks out (closed bar) of the bands then it's trending - with momentum - which is what I'm looking for. A valid breakout has to be in line with the HTF trend AND preceded by a touch of the centre line - ie a decent size pull back. Stops would be back across the centre line with a bit of a buffer - 10pips or so - or a recent H/L if there's a really obvious one very near to this point.

Here's an example of a random snapshot of my system with a description to help clarify the idea behind it:
2019-01-16_0929.png
I've used the D1 SuperSlope as the HTF filter
Blue dot = pullback (reset ready to trade)
Orange dot = filtered trade not taken
Arrows = trade entries
  • 1 - A breakout short after a reset (pullback to centre line). This trade is a loss
    2 - A breakout short after a reset gives > 2:1
    3 - These breakouts are not valid because there hasn't been a pullback reset prior to them
    4 - Now we get a pullback reset so we're looking to trade
    5 - Filtered trade - this breakout took place with a green (long only) SuperSlope
    6 - After the filtered breakout at 5, we can't trade until this reset pullback - the spike here up doesn't close
    7 - A breakout short after a reset gives > 2:1
    8 - Reset pullback after the trade at 7
    9 - Filtered breaks - means we're waiting for a new pullback which we get at 10 (next picture)
2019-01-16_0956.png
  • 10 - pullback reset allows for Long breakout trade which is stopped out (11)
    11 - Stopped out trade - although depends on your SL buffer to the centre line....;-)
    12 - Long entry with the HTF trend gives > 2:1
It's that simple. I've been trading it manually for a while with ok results - depends on the pair. I think different pairs will need different periods but I'm working on this. I've only looked at this on the H1 timeframe vs a D1 trend and my default settings of 200 and 200 are my preferred for this. This is not a proven system by anybody's standards but it has my interest for now because it fits around my other stuff. I don't have the time to run a thread so what you have here is all I have. I just wanted to give something back and to show that I don't randomly ask for help without there being a lot of previous work behind it.

Cheers

Bruster
Author:  Herman [ Tue Feb 12, 2019 11:31 pm ]
Post subject:  iMAOnArray for smoothing - Help needed

Hopefully I understood correctly.
Author:  Bruster400 [ Wed Feb 13, 2019 9:07 am ]
Post subject:  iMAOnArray for smoothing - Help needed

Herman,

You have indeed. Brilliantly simple version. I had tried using the iBands function rather than calculating the std devs internally but for some reason my version of this wouldn't pull through on an iCustom...? Anyway, I've checked and your version pulls through just fine so it must have been something I'd done wrong. :oops:

I did notice that your version still has issues with the soothing on the oldest data but I've given up solving this as I'm sure it's down to the exponential average calcs and it's easily covered up with a decent DrawBegin gap. ;)

Thanks very much for your help with this, really appreciate it.

bruster
Author:  Bruster400 [ Wed Feb 13, 2019 9:20 am ]
Post subject:  iMAOnArray for smoothing - Help needed

I've built on the version Herman posted above and have added arrows to indicate the possible entries for the way that I trade this indicator. (These are breakouts from the channel but only once after each touch of the center line - ie a pullback).
All times are UTC Page 1 of 1