Currency strength (like Hanover)

Place your new trading idea here to see if someone can automate it.
Locked
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

Close. :) I just haven't been able to spend any time on it. I'll get it out in the next day or two.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

FYI I wanted to let people know I haven't abandoned this. I'm working on it, but Empty4's crapitude combined with my inexperience and screwups are making it slow going. I wrote up 3-4 big "sq, why is it doing THIS!?" posts but eventually I managed to figure most of them out. :)

Right now I've got some bizarre behavior that causes the indicator to display the values for one period (about 1/24/11 to 3/7/11) repeatedly, about 6 times, before it "should" be displaying anything... but it doesn't do it consistently enough to figure out what's causing it.
Weird.gif
This rewrite is going about 10x harder than the previous ones for some reason. After about 4 hours of this I don't have any hair left to tear out but I'll try to work on it some more tomorrow night.
You do not have the required permissions to view the files attached to this post.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

It's putting up a ferocious fight but I hope to beat it into submission eventually...
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 »

Remember the Steve approach. Beat the damn thing over the head with a mallet until it gives up and slinks away.

Mind, I don' t always know which particular blow did the trick and cannot always replicate it 6 months later. :lol:

: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 »

Just so long as the damn thing doesn't find its OWN hammer. It was beating me up pretty bad last night.
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 »

Oh boy, I know how you feel.

I know I should get to grips with indi coding, but I simply cannot face it.

Up-an-at-em, tiger.

: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 »

The basic idea of coding indicators is really very simple. Just declare buffers and place the values you want into them. For most simple indis, I suspect that is all that's required. I'm sure you could do it, Steve. :D

It gets much more complicated when you're trying to use past values to calculate future values. I tried to carry values forward from one bar to the next, only to find the indi doesn't always execute the bars in consecutive order. Learning how to work around that took a while.

Then complicate the issue further by pulling in 7 parallel data streams, calculating EMAs of array values (NOT price bars), and a few other bits & bobs, and it rapidly reaches the hair-pulling stage. I did not pick a simple challenge for my first indicator. Thank God for sq's advice or I would be jumping out the window! (Which wouldn't be terribly effective since I'm on the ground floor, but it might be satisfying.)

Unfortunately I got pulled away tonight and did not get home until I'm half asleep. No hair pulling tonight.
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

I had a deadline this week and couldn't spend more time on this beastie. Now it's the weekend so I don't have any live ticks. That's how I got into trouble LAST weekend. :oops: So I'll be doing a limited amount of debugging this weekend.

But I wanted to post what I have for comment. Sq, your advice has been invaluable! Could you take a look at my current code and see what you think of it? I'm not sure I'm taking the right approach here. This is a complex setup and Empty4 is mighty particular about how you do things.

I'm doing a multi-step calculation:
* Gather 7 USD pairs and calculate raw currency-strength indexes
* Optionally smooth the result with an EMA.
* Optionally calculate "relative" values -- the deviation from a long EMA. This scales all the indexes into a similar range and gives you an indication of the direction it's moving. This is basically taking the first derivative to get the "speed" of the index.
* Optionally calculate another level of relative value, basically getting the "acceleration" of the index. This will let us trade like the example I posted earlier, where you short while the index is going down, buy when it's going up.

I have arrays for all of these -- for the 7 pairs, the raw index values, the relative "speed" values, and the smoothed speed. I calculate values for one, then use that array to calculate values for the next one, hoping to avoid any Empty4 surprises that way. The final "acceleration" value goes into the display buffer.

Am I doing this the right way? It seems to me that it won't work when Empty4 invokes the indicator on just the last few bars, because the various arrays won't have the full history to do their EMAs &etc on. Or do they retain their values across calls since they're global? Or do I have to recalculate the ENTIRE buffer on each tick (or maybe just each bar) to ensure I've got valid data for the whole history?

Stripped down, with just one currency for simplicity, here's what I'm doing. I've attached the full indicator if you want to look at all the grubby details.

Merci beaucoup sq!!!
Gary


**EDIT: updated/cleaned up source, 05:00 GMT 4/28/12.

Code: Select all

// Indicator buffers
double	AUDbuffer[];

// Arrays to hold pair data and calculated index values
double AUDUSD[], AUDindex[], AUDspeed[], AUDsmooth[]; 

void start()
{
   double minArraySize;
   double AUDEMA;
   
   minArraySize = <<size of shortest chart of the 7 USD pairs>>;
   
   // Resize all arrays to the size of the shortest pair
   
   ArrayResize(AUDUSD, minArraySize); 
   ArrayResize(AUDindex, minArraySize); 
   ArrayResize(AUDsmooth, minArraySize); 
   ArrayResize(AUDspeed, minArraySize); 

   // Set them all as series so they access data in same direction as the bars data

   ArraySetAsSeries(AUDUSD, true); 
   ArraySetAsSeries(AUDindex, true); 
   ArraySetAsSeries(AUDsmooth, true); 
   ArraySetAsSeries(AUDspeed, true); 

   for(int i=limit-1; i>=0; i--)
   {
      AUDUSD[i] = iClose("AUDUSD",0,i);

      // Calculate currency strengths for each currency for this bar

      AUDindex[i] = <<currency index>>;

      // Optionally smooth the resulting lines with another EMA.
      
      if (SmoothLen > 1.0)   // Smooth the raw speed value
      {
         AUDsmooth[i] = iMAOnArray(AUDindex, 0, SmoothLen, 0, MODE_EMA, i);
      }
      else                    // No smoothing
      {
         AUDsmooth[i] = AUDindex[i];
      } // if Smooth

      // If SpeedLen > 1, calculate the distance between the index and an EMA of the index.
      // This is the "relative" value compared to its recent value --
      // basically the "speed" the index is moving.

      if (SpeedLen > 1)
      {
         if ((minArraySize-i) > SpeedLen)    // Don't start calculating EMA until we have sufficient data in speed array
         {
            // Calculate the difference between the current value & the EMA.
         
            AUDspeed[i] = AUDsmooth[i] / iMAOnArray(AUDsmooth, 0, SpeedLen, 0, MODE_EMA, i) - 1.0;
         }
      }      
      else
      {
         // If not calculating Speed, just use the smoothed index value (and call it speed anyway :-)
      
         AUDspeed[i] = AUDsmooth[i];
      } // if not Speed
   
      // Finally, optionally calculate the "acceleration" of the smoothed line.
      // We do this by just doing another "relative" calculation -- basically taking the 2nd derivative.

      if (AccelLen > 1.0 && SpeedLen > 1.0)     // Calculate accel; only works properly if calc Speed first
      {
         AUDbuffer[i] = AUDspeed[i] - iMAOnArray(AUDspeed, 0, AccelLen, 0, MODE_EMA, i);
      }
      else
      {
         AUDbuffer[i] = AUDspeed[i];
      } // if accel
   } // for i
} // start()
You do not have the required permissions to view the files attached to this post.
User avatar
nanningbob
Trader
Posts: 4564
Joined: Sun Dec 04, 2011 1:23 pm

Re: Currency strength (like Hanover)

Post by nanningbob »

Gary I want you to know that I am very interested in your final product. Take your time, do it right but I really like what you are doing here.

nanningbob
I trade http://www.stevehopwoodforex.com/phpBB3 ... =38&t=3964,
I talk about my philosophy of trading here.
http://www.stevehopwoodforex.com/phpBB3 ... =38&t=3627
"The key to converting something useful to others is simplicity. Complexity is the enemy to execution." Tony Robbins
garyfritz

Re: Currency strength (like Hanover)

Post by garyfritz »

Thanks NB. I am unfortunately a bit stuck at the moment. I sent up a flare for sq (who has been an incredible help on this so far) but he hasn't gotten back to me yet. Between that, and being swamped up to my eyebrows with work (in, like, my real job, ick), I haven't been able to put any thought into it all week. I WILL get back to it, hopefully with a few pointers from sq.
Locked

Return to “Ideas for Possible Automation”