Currency strength (like Hanover)

Place your new trading idea here to see if someone can automate it.
Locked
astral77
Trader
Posts: 171
Joined: Tue Nov 15, 2011 9:26 pm
Location: London

Re: Currency strength (like Hanover)

Post by astral77 »

Hi Gary

Fantastic work, we are very fortunate to have people like you helping us. I hope you know how much we appreciate all your hard work in all areas in this forum.

I was following David`s thread (HANOVER) from the early days and his train of thought was in line with yours during the development stage. I hope the attached pdf which contains extracts of David`s emails gives you a better insight in the application of your currency strength indicator.

As David says a graphical indicator such as recent strength and yours tells a ongoing story and is much more useful than just a simple strength meter. I hope you find this brief document of some use.

Kind Regards
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

OK. After muttering several unkind things about the parentage of the Empty4 designers, I finally have the currency strength FUNCTION working. This function must be called from EAs, NOT from indicators. It very efficiently calculates the 8 currency values -- it should cause VERY little load to the computer.

There are two functions:

Code: Select all

CurrencyStrengthInit(double SmoothLen, double SpeedLen = 1.0, double AccelLen = 1.0, double Scale = 1.0)

CurrencyStrength(datetime BarTime, bool NewBar, double& oAUD, double& oCAD, double& oCHF, double& oEUR, double& oGBP, double& oJPY, double& oNZD, double& oUSD)
See the code for detailed comments.

Call the Init function to specify the EMA lengths for the Smooth, Speed, and Accel EMAs. These are the same as the Smooth/Speed/Accel EMAs in the indicator I've previously posted.

Then call the CurrencyStrength function to calculate the current strength index values. Specify the Time[] of the bar you're calling it on and whether this is the first tick of a new bar. Then pass in 8 doubles. The function returns the 8 index values in these parameters.

There's a tiny EA in the file to show an example of calling it.

You can call the function once per bar e.g. on the Close, or multiple times per bar e.g. on each tick. It should work properly and produce the same final-bar value either way. I haven't verified the multiple-calls-per-bar functionality yet. I think, though, that it really only makes sense to pay attention to the values once per bar. It's not that jittery of an indicator.

The results of this function are really close to the values from my indicator. There is one gotcha, which I don't think is a problem: when I checked it, the function results lagged the indicator by one bar. (And my TS indicator says the Empty4 indicator is right.) I think it's lagging because I ran my tiny EA in System Tester to test it, and I ran the System Tester in Open Only mode. So the function was working with the Open of the new bar which was about the same as the Close of the previous bar. But when I checked it I tagged the results with the Date/Time of the bar. So my test basically used yesterday's Close and today's Date, whereas the indicator used today's Close and today's Date. If you call it properly I think it will work properly, and it should match the indicator almost exactly. I'll look at this more when I get a chance.

I haven't written EAs, so Steve or anyone else, let me know how this works for you.

I'm still learning how to use the results of this thing. In my testing so far, I set the Smooth/Speed/Accel to values that "look nice," then design signals around it. That is, I set it to produce lines that move about as rapidly as I want. I don't want the signals to change every bar or two, so I set the EMA lengths long enough to produce nice smooth curves on my chart. 50/50/20 seems like a decent starting point.

Have at it, gentlemen!
You do not have the required permissions to view the files attached to this post.
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 »

Fantastic Gary. You are a star.

The attached is not a trader, nor will it ever be. All it does is display the strength values on the chart, so I can check that I am making the call correctly.

I had to make some changes immediately:
  • double oAUD, oCAD, oCHF, oEUR, oGBP, oJPY, oNZD, oUSD; had to become globally available variables, so they are in the section that will eventually become the Currency Strength externs.
    - this meant changing bool CurrencyStrength(datetime BarTime, bool NewBar, ................) to simply bool CurrencyStrength(datetime BarTime, bool NewBar)
    - this last function needed editing to include pair suffixes such as Cowboy IBFX 'm'.
Apart from that, do the values displayed on the chart look correct? Once they are, this becomes a module that can inhabit any trading EA coded by anybody.

:D
You do not have the required permissions to view the files attached to this post.
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
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 »

Incidentally, I agree that it is unnecessary to call the function more than once per bar - we can have an input that specifies the time-frame. I find that calling thingies at the open of an M1 candle cuts down of processor use enormously.

Also, you are right about the strategy tester bar thingy; Open prices only causes it to lag behind by 1 bar.

: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.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

SteveHopwood wrote:Apart from that, do the values displayed on the chart look correct? Once they are, this becomes a module that can inhabit any trading EA coded by anybody.
Hm, no. In start() you printed the values of AUDIndex, etc. Those are the raw index values, basically what you would get if you set the Smooth, Speed, and Accel lengths to 1.0. I changed the code to display oAUD, etc -- but that just returned zeroes, and I'm not quite sure why. You declared them globally on line 126 so start() should have been able to access the values stored in lines 1795-1802.

(...dig dig dig...)

Looks like it's only being called once. It needs to run on some historic bars to spin up the values of the EMAs. If you only run it on one bar, you have no history to smooth the noisy raw index values or determine what the "normal" value is so you can determine if you're above or below it.

How does that work with Empty4? I'm used to Tradestation, which always runs a system on the chart history before switching to processing realtime ticks -- similar to how Empty4 handles indicators. That means you have the chart history to get everything running.

Empty4 doesn't do that, does it? Does that mean this thing can't work on Empty4 because you'd have to let it run for XXX bars before it stabilized!? If so, I'm gonna be really severely pissed... :evil: ("pissed" in the US sense, i.e. "cheesed off." Though I may go drown my sorrows and end up pissed in the UK sense too!!)
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

Thinking some more... you pass a "bar time" into the main function so it can grab Close values for 7 pairs that are all from the same time. It may be possible to modify things so the Init function sets things up, then it calls the main function for the last N bars. It would discard the resulting values, but that would initialize and stabilize the EMA values. Then when you called CurrencyStrength() from start(), it would be spun up and producing valid values.

So it may be possible to work around this.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

Well that was easier than I expected! Just add this to the end of the CurrencyStrengthInit() function:

Code: Select all

   for (int i = 5 * MathMax(SmoothLen, MathMax(SpeedLen, AccelLen)); i > 0; i--)
      CurrencyStrength(Time[i], true);
...and display the oAUD/etc values in start() instead of AUDIndex/etc:

Code: Select all

ScreenMessage = StringConcatenate(ScreenMessage, "Aud: ", oAUD, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Cad: ", oCAD, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Chf: ", oCHF, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Eur: ", oEUR, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Gbp: ", oGBP, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Jpy: ", oJPY, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Nzd: ", oNZD, NL);
ScreenMessage = StringConcatenate(ScreenMessage, "Usd: ", oUSD, NL);
It took a LOT longer for the EMAs to settle than I anticipated. I thought I was setting them at good initial values and they should settle quickly. But I had to run it for 5x more bars than the longest of the 3 length parameters for the values to converge with the indicator. I'm looking to see if I can improve it, but it may not be possible to initialize them properly without actually running through the history.

Why do you have to move oAUD/etc out to the global externs area? I wouldn't have used globals for all those values except they have to retain their values between calls. Good Programming Practice says you should hide as much of the internals as possible so people don't try to do things you didn't intend. Like accessing AUDIndex instead of the oAUD value. :D

If you want to use the global values, I should probably rename them from oAUD to something more sensible, like AUDIndex, and change the raw values to AUDIndexRaw. Coming in the next release.
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:Why do you have to move oAUD/etc out to the global externs area?
So I can find them where I expect to look, in 3 months time when I have no idea how all this works and have to try to find out.
I wouldn't have used globals for all those values except they have to retain their values between calls.
Yep. Exactly why I did this.
Good Programming Practice says you should hide as much of the internals as possible so people don't try to do things you didn't intend. Like accessing AUDIndex instead of the oAUD value. :D
Not my problem if people want to bugger things up. I need stuff where I can find it and where it means something to me :lol:
If you want to use the global values, I should probably rename them from oAUD to something more sensible, like AUDIndex, and change the raw values to AUDIndexRaw. Coming in the next release.
People find it difficult sometimes to reconcile what I do my my assertion that I am merely a mechanic. Mostly, all I do is bolt stuff together. Sometimes I understand how it works. Sometimes I once understood how it works, but have forgotten. I would not even begin to re-code Hanover, for example; not a clue how it works.

I have no idea what your code does or how it works. If we end up with a module I can add to my shell etc, then I shall use it. So will others. Just don't expect me to understand it. :lol: I sometimes appear cleverer than I am because I code as a trader for traders, so I know what people will be looking for. Fact is, a brainbox I am not.

Does the attached look any more accurate?

:D
You do not have the required permissions to view the files attached to this post.
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.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

Yes, that looks good.

Meanwhile I'm working on a slightly improved version that will hopefully spin up faster, so the init function doesn't need so many bars to initialize the EMAs. I'll change the "result" vars to something sensible instead of oAUD, and I might add a sorted list. I.e. I might return an array CurrencyStrengthOrder[] that holds the currency# of the currencies in sorted order. So AUD=1, CAD=2, CHF=3, EUR=4, GBP=5, JPY=6, NZD=7, USD=8. For the example in http://www.stevehopwoodforex.com/phpBB3 ... 160#p13160, CurrencyStrengthOrder[] would hold 6 (JPY), 8 (USD), 5 (GBP), 2 (CAD), 4 (EUR), 3 (CHF), 1 (AUD), 7 (NZD) -- because that's the top-to-bottom order of the final index values. So for the example strategy I mentioned (pick the strongest and weakest currencies, and go long or short the resulting pair), CurrencyStrengthOrder[0] and CurrencyStrengthOrder[7] would give you the strongest and weakest currencies. Would that be useful?

And once I do that, it would probably make sense to return the index values in CurrencyStrengthIndexes[] instead of in AUDIndex, CADIndex, etc. Then CurrencyStrengthIndexes[CurrencyStrengthOrder[0]] would give you the highest index value.

Sound good?
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:Sound good?
Nope. Sounds fantastic.

: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.
Locked

Return to “Ideas for Possible Automation”