Currency strength (like Hanover)

Place your new trading idea here to see if someone can automate it.
Locked
User avatar
mobthehop
Trader
Posts: 362
Joined: Wed Nov 16, 2011 12:16 am

Re: Currency strength (like Hanover)

Post by mobthehop »

Hi Gary,

frankly this discussion is way over my head but maybe are able to glean some insight if you look at the internals of the XMeter EA which is, to my (limited) knowledge, the only existing and semi-functioning EA with a currency strength implementation.

Here: http://www.stevehopwoodforex.com/phpBB3 ... ?f=20&t=48 or

original: http://www.forex-tsd.com/suggestions-tr ... meter.html

I am following this thread with great interest as I am looking forward to have such a component as plug-in to a number of EAs along lines of Hannover module by Steve....

Actually I did ask Steve around end of last year whether he would be interested to lift the XMeter code and implement it in the EA shell but other projects took priority - am not complaining.....

Keep up the good work!
User avatar
squalou
Trader
Posts: 49
Joined: Wed Nov 16, 2011 8:57 am
Location: fabulous Aix en Provence, southern France;

Re: Currency strength (like Hanover)

Post by squalou »

garyfritz wrote: Except... when I first set the color to NONE, MQL says it's -1, the currency color is == CLR_NONE, and the NONE currencies don't display. Then if I change one color, all the OTHER "NONE" colors spontaenously change to -16777216 !? Then the lines start displaying again, in black. If I use Pink, it works. :?: :?: So I'm going back to Pink for now and I'll worry about it later.
weird Empty4 behaviour, i agree ...!?!
-16777216 translates to 0xFFFFFFFFFF000000, which is NOT -1(decimal) encoded on a 64-bits value...
Perhaps because the "color" type is truncated or shifted somehow internally (possibly encoded on only 40 bits, then stored into 64-bits data storage...)
Let's keep it simple, who would display a Pink line anyway ? :lol:
I realized, though, that if I don't want to display an index, and I don't call SetIndexBuffer(), then Empty4 won't know it's a buffer and won't automagically shift it when Bar 0 closes. But that shouldn't matter because I'm not displaying it anyway, and I don't access it in any other calculations.
correct
sq, when bar 0 closes and becomes bar 1, I need to shift all the arrays I use for MAs -- e.g. AUDindex[], AUDspeed[], AUDsmooth[]. What about the pair arrays? I load those up with e.g. "AUDUSD = iClose("AUDUSD",0,iBarShift("AUDUSD",0,iTime(NULL,0,i)));". So they should line up with the Bar data already. But when bar 0 closes, the Bar data shifts, and AUDUSD[] doesn't. The IndicatorCounted() value is probably only going to have me calling iClose() one one or two bars. So I should shift the AUDUSD[] pair array too, right?


absolutely;
you have to "manually" shift ANY non-buffer array that needs to keep up with the buffers.

I'll get this coded this weekend -- I think the changes from this point are pretty simple (famous last words?? :D) -- but I can't test it until Sunday night so I won't release anything until at least then.


actually you CAN test it: load any EA in the visual backtester, Pause it, load the indi on the chart, then Run; it will display ALL the currencies, although an EA only has access to the selected symbol, because the indicator runs independently from the history data feed provided to the EA -- one more strange and misleading Empty4 behaviour... :shock:


PS: BTW I was thinking about how this really simple concept has exploded into hundreds of lines of code and lots of CPU-gobbling work to calculate the averages and maintain the history. Then I realized that about 98% of that is just dealing with the strange Empty4 indicator behavior. Calculating the raw index values is very simple.

Maybe, if you wanted to use the currency strength in an EA and NOT in an indicator, you might not have to drag along that extra 98%. Let me ping Steve and ask him exactly how EAs behave.



Well, an EA does not even have the "buffers" available.
So an EA would have to calc everything manually by itself, thru the same arrays as in the indi.
However, you can save several arrays by implementing your own EMA "incremental" function, because EMA only needs to know the "previous bar" EMA and the current data value to calc the current EMA.
You only need "push" the current EMA into the "previous_EMA" value at each new bar-opening, without the need to handle of whole lot of arrays.
init() would make the first EMA calculations.

Something like this:

Code: Select all

double ema_now(double previous_ema, double current_data, int ema_period)
{
  double alpha = 2*(ema_period+1);
  return (alpha * current_data + (1-alpha) * previous_ema);
}

It would be a bunch of lines of code...

Sq
" Every battle is won before it is ever fought "
Sun-Tzu, The Art of War, 400BC.
User avatar
squalou
Trader
Posts: 49
Joined: Wed Nov 16, 2011 8:57 am
Location: fabulous Aix en Provence, southern France;

Re: Currency strength (like Hanover)

Post by squalou »

mobthehop wrote:Hi Gary,

frankly this discussion is way over my head but maybe are able to glean some insight if you look at the internals of the XMeter EA which is, to my (limited) knowledge, the only existing and semi-functioning EA with a currency strength implementation.

Here: http://www.stevehopwoodforex.com/phpBB3 ... ?f=20&t=48 or

original: http://www.forex-tsd.com/suggestions-tr ... meter.html

I am following this thread with great interest as I am looking forward to have such a component as plug-in to a number of EAs along lines of Hannover module by Steve....

Actually I did ask Steve around end of last year whether he would be interested to lift the XMeter code and implement it in the EA shell but other projects took priority - am not complaining.....

Keep up the good work!

The problem with xMeter is that it calculates the "strength" based on the daily high/low levels;
which makes it "rince" at the 00:00 bell every night, giving over-sensitive results during the first hours of the day.
(it is something like a "distorted" stochastic, but with a "fixed anchor" at 00:00)

What we want is a sliding constant-time window.

There is no escape from complex coding...

sq
" Every battle is won before it is ever fought "
Sun-Tzu, The Art of War, 400BC.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

squalou wrote:So an EA would have to calc everything manually by itself, thru the same arrays as in the indi.
However, you can save several arrays by implementing your own EMA "incremental" function, because EMA only needs to know the "previous bar" EMA and the current data value to calc the current EMA.
It would be a bunch of lines of code...
That's exactly what I have in mind. I'm guessing it will be about 12-15 lines per currency, so something like 100-120 lines total, but it will be quick and efficient. I should be able to do it with no arrays at all. I'll just have two functions, one to initialize it (specify EMA lengths, etc), and one to return the 8 current index values. That second function will detect whether the bar has just closed, and if so, it will save the previous EMA value to use in the next bar. Then it will return the "value so far in this bar" as of that tick.

I would have had it written by now, but Steve dangled a "prove Martingales don't work" challenge in front of my nose, and that ate up my morning. :lol: I have other plans this afternoon but I'll return to this "calc currency strengths in EA" idea soon.
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Currency strength (like Hanover)

Post by SteveHopwood »

garyfritz wrote:I would have had it written by now, but Steve dangled a "prove Martingales don't work" challenge in front of my nose, and that ate up my morning. :lol: I have other plans this afternoon but I'll return to this "calc currency strengths in EA" idea soon.
Yep. Sorry. Mea culpa. Look on the bright side. Gary and I are working on saving the next bunch of M loonies from themselves. Just imagine the amount of money Gary is going to save M punters from losing, assuming they have the brains to take on board what he is writing. Big assumption, but....

That is another story and no need to comment further. Just confirming the cause of G's temporary distraction.

:D
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
User avatar
squalou
Trader
Posts: 49
Joined: Wed Nov 16, 2011 8:57 am
Location: fabulous Aix en Provence, southern France;

Re: Currency strength (like Hanover)

Post by squalou »

no need to justify anything, i am here to help when i can, and it can also take quite a while before i post myself...
" Every battle is won before it is ever fought "
Sun-Tzu, The Art of War, 400BC.
User avatar
mobthehop
Trader
Posts: 362
Joined: Wed Nov 16, 2011 12:16 am

Re: Currency strength (like Hanover)

Post by mobthehop »

SQ,

thanks for your clarification, I did not know that.... The xmeter indy is a vital part of trading Pitbull on H1 for me and works well as trade duration is normally measured in hours rather than days for me. However it is quite useless in the H4 strategy I use....

Question: Would you expect the xmeter to give better results for higher tf's (eg H4) if it were based on previous week high / low? Just curious.

Cheers

Mop
User avatar
squalou
Trader
Posts: 49
Joined: Wed Nov 16, 2011 8:57 am
Location: fabulous Aix en Provence, southern France;

Re: Currency strength (like Hanover)

Post by squalou »

mobthehop wrote:SQ,

thanks for your clarification, I did not know that.... The xmeter indy is a vital part of trading Pitbull on H1 for me and works well as trade duration is normally measured in hours rather than days for me. However it is quite useless in the H4 strategy I use....

Question: Would you expect the xmeter to give better results for higher tf's (eg H4) if it were based on previous week high / low? Just curious.

Cheers

Mop
I had a look at the !xMeter_v2.1.2.mq4 EA code, and it differs from the !xMeter v 1.3.mq4 INDICATOR that i have.
The Indicator (1.3) is using the 00:00 bell anchor, and is subject to the over-sensitivity issue i mensionned.

However, the EA uses a constant-time period to calculate a stochastic-like value.
It is controlled by the xMeterLookBackPer EA input, which is set to 84 hours as default (last 3.5 days).
This would give better results i guess, at least more stable/less time-sensitive.

I don't know if there is an Indicator version that uses the same algo as the EA, though.
The one posted by tex in the Pitbul thread uses a similar algo as the one i have(1.3), so it is different from the xMeter EA.

SQ
" Every battle is won before it is ever fought "
Sun-Tzu, The Art of War, 400BC.
lonelytrader
Trader
Posts: 79
Joined: Wed Feb 29, 2012 1:29 pm
Location: Canada

Re: Currency strength (like Hanover)

Post by lonelytrader »

I have been using the !xmeter_v2_2_7
and its pretty good, in last 30 days it has generated about 1500 pips... with only 8% open DD

i dont know why this robot was dropped from further development, but it has legs.

If anyone is willing to improve the code, i will be more then happy to give all my personal experience with this robot both good and weaknesses.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

OK, I'm finally getting back to this indicator. Sorry for the long delay.

Sq, thanks for the tip of using the visual backtester!! That's very helpful for debugging the indicator.

I've cleaned up a number of things, and I added the bar-shift code you recommended. When Time[0] != LastTime, I shift all the non-buffer arrays one bar into the past, e.g. AUDUSD[i+1] = AUDUSD.

Unfortunately I have an error in here somewhere and I can't find it. If you step through the chart in the visual backtester, the indicator lines go fairly flat, and there is a "bend" in the newest 2 bars. Then if you redisplay the indicator, the lines replot in their proper shapes:

CurrIndy.gif
So the lines that have the highest values bend up, and the lines that have the lowest values bend down. Obviously the bar-0 value is not being shifted out properly into history but I'm not sure why.

Sq, can you spot my goof? You know the indicator behavior a lot better than I do, so maybe you can see what I'm doing wrong.

Some hints / behaviors:

First there's the "not shifting values into history properly" problem. I'm not sure where that's coming from. I'm shifting the non-buffer arrays when Time[0] != LastTime, which I think is the right thing to do. The "bend" in the last 2 bars indicates the bar 0 value is getting changed when it gets shifted !? Maybe the MA is doing that? And even the bar 0 value doesn't match the value that gets plotted if you replot the history. I think the history is right -- it's the realtime behavior that's killing me. As usual.

Then there's a less-serious but annoying initialization problem connected to the iMAOnArray() calls. The resulting values start out at a bogus level, and converge to the proper level as the MA includes more of my calculated index values.
* If the MA lengths (SmoothLen, SpeedLen, AccelLen) are all 0, the raw index values display fine, all the way back to the first bar.
* If I turn on smoothing e.g. SmoothLen = 50, the smoothed values start out at 0 and gradually work their way up to the proper levels.
* If I turn on speed e.g. SpeedLen = 50, the relative values start out at 24.5 (!?!?) and gradually work their way down to the proper levels.
* That's with MAmethod = MODE_EMA. If I set it to SMA, the relative values start out at 49.0 -- double the EMA starting value. Hm.

So the raw index values are OK, but the values from iMAOnArray() are starting out at a bogus value. Am I calling iMAOnArray() wrong?

I tried not filling the buffers until the values had settled. That works OK for MODE_SMA but not as well for MODE_EMA, which takes longer to settle. But I'd like to understand what's *causing* it.

Do I need to start filling the XXXindex array, and then don't try to do iMAOnArray() on it until I've got N values for the MA to work on? And then maybe limit the iMAOnArray() to only those cells, with the "total" argument? I tried that, and it didn't work at all... maybe I don't understand what the "total" argument does.

Thanks sq!!

5/19/12 EDIT: uploaded slightly improved version of the indicator
You do not have the required permissions to view the files attached to this post.
Locked

Return to “Ideas for Possible Automation”