• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 8:41am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 8:41am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Hedge and Correlation Strategy 4,238 replies

MT4 MTF Correlation table and Correlation oscillator indicators 155 replies

Double it Then Double it Again - Swing Trading 4H 0 replies

need a programmer to program an alert for double tops and double bottoms 10 replies

Double Tops & Double Bottoms - How do you tackle them? 0 replies

  • Trading Systems
  • /
  • Reply to Thread
  • Subscribe
  • 19
Attachments: InsomiaFX Correlation Double Hedge EA
Exit Attachments
Tags: InsomiaFX Correlation Double Hedge EA
Cancel

InsomiaFX Correlation Double Hedge EA

  • Last Post
  •  
  • Page 1 23 4
  • Page 1 23 4
  •  
  • Poll

  • A Correlated Double Hedge is .. ?
  •  
  •  
  •  
  •  
  • Post #1
  • Quote
  • First Post: Edited May 31, 2013 9:02am May 28, 2013 4:19pm | Edited May 31, 2013 9:02am
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Hello,

this EA has been tested with Exness. You need a broker who offers offset hedges. Broker compatibility: The EA calls currency pairs like "AUDUSDm". Replace the "m" in the EA with your brokers code.



The InsomiaFX Correlation Double Hedge EA system works this way:

AUDJPY/CADJPY have a correlation of around 90% over 1 year which is good. Over the day it changes quite a bit.

  1. Open a 100.000 USD demo account
  2. Attach EA to AUDJPY chart, timeframe doesn't matter


EA will do:

  1. Open hedged AUDJPY/CADJPY (2 orders - Pair 1)
  2. Open the same orders opposite side (Pair 2), margin is now 0 and we have a .. hmm .. correlated double hedge !


With margin 0 we have a very nice buffer for drawdowns plus we double the chance to reach the TP due to two Pairs. Just swap is negative.

For example each order is 40 lots and TP (Take Profit) point of 1000 USD per pair.

Profit will be taken once the correlation goes wild and a pair reaches the TP. Like one order is -1000 and the other +2000. This pair will be closed and recreated. This happens around 5-10x per day.

The drawdown will stop automatically at a maximum due to the double hedge. In this example not more than 20% or so.


Very nice interactive correlation charts:
http://www.myfxbook.com/forex-market.../AUDJPY-CADJPY
http://www.myfxbook.com/forex-market/correlation


Swap loss per day around -80 USD with 40 lots per order. If you disable Pair 2 and thus pay margin for Pair 1, the Swap turns into a profit of ca. 120 USD per day or around 3000 USD/month. Pair 1 still will take the 1000 USD TP whenever reached.

Things to do:

  1. Check the EA for bugs
  2. Test the system if it makes any long-term sense ?
  3. Add correlation formular to EA (mostly done)
  4. Define perfect order entry points based on correlation of last X min
  5. Add lot based compound related to Equity gain to boost this up.


As AUDCAD swings around 8% per last 2.5 years I added code to adjust the lot size based on the same USD value for each pair. However I found the correlation differences per day is up to 50% per pair so it has little effect to adjust the lot sizes now. So that code is inactive. With AUD/CAD around 1.00 just place same lots.

I have it running on 4 Demos since today to check if this system works and find code/logic bugs.

See the pairs shown in the comment and profits in points. Fun to see how the points change around till they hit the TP.

Attached Image (click to enlarge)
Click to Enlarge

Name: Trades.png
Size: 16 KB



Thx for reading and any feedback.

InsomiaFX

Attached Image



As the EA gets updated quite often plz find the latest EA within the thread.

Note: The rar contains a dll which simply boosts the MT4 process priority to high. Its not needed if you don't trust DLLs. Just uncomment the related code in the EA. If you like to use it, put the dll into the same folder as terminal.exe. Needs Windows 7 and .NET Framework 4.0. Source on request.
Attached File(s)
File Type: rar InsomiaFX_Managed.rar   9 KB | 4,231 downloads
  • Post #2
  • Quote
  • May 28, 2013 6:20pm May 28, 2013 6:20pm
  •  Thepipster
  • | Joined May 2012 | Status: Working the mine. | 404 Posts
I like correlationhedge ideas....but who knows a broker that has 0 margin for these hedged currencies, that accepts US customers?

So, is the TP about 3-4 pips?
Too close for pips, switching to points.
 
 
  • Post #3
  • Quote
  • Edited 8:08pm May 28, 2013 6:54pm | Edited 8:08pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
I think hedges for US customers can be worked around if you open a company in another country and use that company to register with a broker. I normally live in Canada but own a small company in Europe. Similar concept how Apple avoids to pay taxes which was in the news a bit recently ..
Managed accounts could be a way, too.


The TP is a personal choice. The higher you set it, the longer it will take to reach it and the more unlikely you will reach it. Better 3x 1000 then 1x 2000 .. Most of the time the pairs hang around in a loss and move into profit quite seldom for a short time. With TP 1000 and 40 lots its just enough to not get a loss due to slippage when the orders are closed in sequence. Silly we can't close orders in parallel with MT4. I guess a TP 2000 is more safe. Just play around with it and see what works best over a week or so. At 40 lots, 1 pip is ~400$ so its very time critical to close a pair quick without delays.

This EA would work better on a different platform than MT4 but I haven't tested others so far. Any recommendations ?

Today the Exness Demo server seems to be sick as I have problems to close orders since some minutes.

Another offset hedge broker is: AFX aka https://www.supertradingonline.com/en/ What other brokers have offset hedges ?
I will test AFX now. Otherwise my orderclose code is buggy ..


This EA can be developed further. Lets assume a typical grid trading system with shorts and longs. You define the grid width with x pips as usual and instead to place a short, long or both at one grid level you place .. this - a correlated double hedge. We don't care about the grid itself but about the time differences when the pairs are placed on the grid. As based on that we get different correlations to start with plus different prices for each pair. I haven't analysed the deeper mechanics of optimal entry points for correlated double hedged pairs but sense that randomness will do good here.

By having more pairs we increase the chances that one hits the TP. Swap would be the same if the total order volume stays the same.
 
 
  • Post #4
  • Quote
  • May 28, 2013 9:27pm May 28, 2013 9:27pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
EA Update in OP

- fixed bug in OrderClose
- rewrote code to Print correct profit when pair is closed


Besides that, I noticed a behavior from grid trading:

  1. if Pair 1 is closed and reopened, the distance to Pair 2 has increased. As such the Drawdown is increased.


Why ? Lets say Pair 1 has a profit of -20.000/5.000, thus 15.000 negative. Pair 2 would be in a similar range, just the opposite which holds the DD stable. Thats great and how it should be. But things change if lets assume Pair 2 hits the TP. We take the profit and recreate a new Pair 2. The new Pair 2 will be like -1000/-1000. Thus we get an unbalance in the account as we have a higher DD. This could lead to an increasing DD over time. Needs to be demolized over a longer period.

This of course does not happen if only Pair 1 is traded alone. (Just uncomment the Pair 2 code). What if Pair 2 gets outsourced to a second account ? I took the green mind cleaning Anti-Double Hedge pill already so will think more about that tomorrow ..

 
 
  • Post #5
  • Quote
  • May 28, 2013 11:16pm May 28, 2013 11:16pm
  •  hewtwok
  • | Joined Sep 2006 | Status: Member | 308 Posts
keep up the goodwork

question time:
pair 1 we buy A/J and buy C/J or buy and sell the other?
 
 
  • Post #6
  • Quote
  • May 29, 2013 10:25am May 29, 2013 10:25am
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Pair1 = AUDJPY LONG (Order 1A) + CADJPY SHORT (ORDER 1B) = Swap Positive 120 USD/Day at 40 Lots

See the screenshot in the OP, shows all the orders and to which pair they belong.
 
 
  • Post #7
  • Quote
  • May 29, 2013 10:42am May 29, 2013 10:42am
  •  hewtwok
  • | Joined Sep 2006 | Status: Member | 308 Posts
Quoting InsomiaFX
Disliked
Pair1 = AUDJPY LONG (Order 1A) + CADJPY SHORT (ORDER 1B) = Swap Positive 120 USD/Day at 40 Lots See the screenshot in the OP, shows all the orders and to which pair they belong.
Ignored
Thanks.
i missed out on the pic. sorry my bad.
 
 
  • Post #8
  • Quote
  • May 29, 2013 10:48am May 29, 2013 10:48am
  •  pepesan
  • | Commercial Member | Joined Dec 2012 | 90 Posts
I do not like hedging trading system at all. If your trading position is in the wrong direction of the market, it's better to cut your loss and start a new trading analysis.

------

trade NFP
 
 
  • Post #9
  • Quote
  • May 29, 2013 11:36am May 29, 2013 11:36am
  •  djnato
  • | Joined Jan 2012 | Status: Member | 3 Posts
Interesting i'll leave test.
Congratulations thank you for sharing
 
 
  • Post #10
  • Quote
  • Edited 1:11pm May 29, 2013 12:52pm | Edited 1:11pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Quoting pepesan
Disliked
I do not like hedging trading system at all. If your trading position is in the wrong direction of the market, it's better to cut your loss and start a new trading analysis. ------ trade NFP
Ignored
Pepesan, this EA eliminates any impact of direction changes of the market. In a simplified way, CADJPY can be around 1:100 today and 1:345 tomorrow. We don't care. Profit is taken due to correlation swings. So this EA cannot be on the wrong side of the market as any side is the right side. Even a massive market crash like we had with the JPY some days ago will not have any impact. The Drawndown won't change. (unless the pairs shift away after closing and recreation, thats a different thing I work on)

Work needs to be done to figure out the optimal entry point for Pair orders. Should we enter when the correlation is very strong (1/-1), medium (0.5/-0.5) or unknown (0) ? Guess I will demo that once I put the correlation formular into the EA so we get some data to play with.


Another advanced idea: Instead to place the orders in reality, we could place the 2 Pairs as "virtual orders". These virtual orders become an indicator. If a pair has a huge profit difference due to a messed up correlation, we could place a real order and wait for the correlation to come back. It will come back as the 1 year period says it will do so. Profit taken after some time passed. Repeat ..

In gird trading we also hope that prices swing back (check USDCAD, AUDCAD). But if we just hit a 10 year peak we may have to wait another 10 years for the price to come back, maybe never. With correlation, the swing back will happen much faster. A couple of times per day.
 
 
  • Post #11
  • Quote
  • Edited 7:13pm May 29, 2013 4:56pm | Edited 7:13pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
EA Updated and posted only here:

  1. Option to limit Drawdowns when 2 Pairs are used
  2. Option to trade only Pair 1 alone


Lets discuss the new Parameters:

VAR_DoubleHedge = true

When enabled, both Pairs will be traded. There will be no margin used and swap will be negative
When false, only Pair 1 will be traded. There will be margin and the swap will be positive (assuming you stick with AUDJPY/CADJPY).


VAR_DDLimit = 0

This is a simple Drawdown Lock.

0 means this parameter will not be used = OFF (dangerous !!)

Lets set this to 10.000 (USD).

IF 2 Pairs are open and one Pair is negative more than 10.000 than NO Pair will be closed. Lets wait for correlation to turn around.
IF only 1 Pair is open but is negative more than 10.000 then NO other Pair will be created. Lets wait ..

Once the Pairs go below the 10.000 USD limit (like 9500), trading resumes, pairs can be closed and recreated.

Or course profit opportunities are blocked during a DD lock but better than a margin call ..

Attached File(s)
File Type: mq4 InsomiaFX_Demo.mq4   12 KB | 1,898 downloads
 
 
  • Post #12
  • Quote
  • May 29, 2013 5:51pm May 29, 2013 5:51pm
  •  Gumrai
  • Joined Oct 2012 | Status: Member | 1,959 Posts
Double hedge?
Am I missing something here?

Long AUDJPY
Short AUDJPY
Long CADJPY
Short CADJPY

How is it possible to make profit from 2 opposite positions?
If AUDJPY rises by x pips, then the long position will make x pips profit, but the short position would make x pips loss, cancelling each other out.
Same with CADJPY.

From the time that all 4 positions are open, it is impossible to make profit and you will be losing on the swap.
Please Do Not PM Me With Coding Enquiries
 
 
  • Post #13
  • Quote
  • May 29, 2013 6:29pm May 29, 2013 6:29pm
  •  txfxtrader
  • | Joined Jan 2012 | Status: Member | 105 Posts
Did you happen to see the pip difference in AUDJPY/CADJPY in 2007?

2007.10.01
0:00
107.80

2007.10.01
0:00
122.36

delta: 14.56
 
 
  • Post #14
  • Quote
  • Edited 7:08pm May 29, 2013 6:38pm | Edited 7:08pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Hey Gumrai, nice to see you here.

The system is called "Correlation Double Hedge" not Double Hedge.
We want the double hedge to remove margin and thus have more money to survive drawdowns. Swap is negative, yep.
But you can run this with VAR_DoubleHedge = false and have only Pair 1 with margin and a positive swap. What's better is up to the individual trader I guess.

Profits are done by each pair separated from each other. If Pair 1 (Order 1A & 1B) as the sum has a profit, we close this Pair. Throw this on a demo account and see how it works.

txfxtrader, pip differences (2.5% right now) and lot size differences (0.5%) related to USD base value can be adjusted if needed. Not a big deal for now. If we get down to details we also should be aware that CADJPY normally changes with a larger pip difference than AUDJPY. Thats fine tuning stuff for the future. First lets see if this concept works at all over a couple of weeks.
 
 
  • Post #15
  • Quote
  • May 29, 2013 6:46pm May 29, 2013 6:46pm
  •  txfxtrader
  • | Joined Jan 2012 | Status: Member | 105 Posts
Had the data to share...here's the last 85 months at the close.
Attached Image (click to enlarge)
Click to Enlarge

Name: 85_months.png
Size: 19 KB
 
 
  • Post #16
  • Quote
  • May 29, 2013 7:30pm May 29, 2013 7:30pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Next I will extend the DLL to calc the correlation for us, so we can test different order entry points. Should be ready in a couple of days.


How to calculate the correlation coefficient ?

http://office.microsoft.com/en-001/e...005209023.aspx

I like C++/CLI to code MT4 dll's. The correlation code works like this:


Inserted Code
    array<double>^ array1 = gcnew array<double> { 3, 2,  4,  5,  6 };
    array<double>^ array2 = gcnew array<double> { 9, 7, 12, 15, 17 };
 
    array<double>^ array_xy  = gcnew array<double>(array1->Length);
    array<double>^ array_xp2 = gcnew array<double>(array1->Length);
    array<double>^ array_yp2 = gcnew array<double>(array1->Length);

    for (int i = 0; i < array1->Length; i++) array_xy  = array1 * array2;
    for (int i = 0; i < array1->Length; i++) array_xp2 = Math::Pow(array1, 2.0);
    for (int i = 0; i < array1->Length; i++) array_yp2 = Math::Pow(array2, 2.0);
                
    double sum_x     = 0;
    double sum_y     = 0;
    double sum_xy    = 0;
    double sum_xpow2 = 0;
    double sum_ypow2 = 0;

    for each (double n in array1)    sum_x += n;        
    for each (double n in array2)    sum_y += n;
    for each (double n in array_xy)  sum_xy += n;
    for each (double n in array_xp2) sum_xpow2 += n;
    for each (double n in array_yp2) sum_ypow2 += n;
                
    double Ex2 = Math::Pow(sum_x, 2.00);
    double Ey2 = Math::Pow(sum_y, 2.00);
 
    double Correl = 
    (array1->Length * sum_xy - sum_x * sum_y) /
    Math::Sqrt((array1->Length * sum_xpow2 - Ex2) * (array1->Length * sum_ypow2 - Ey2));
 
    Console::WriteLine("CORREL: " + Correl);
 
 
  • Post #17
  • Quote
  • May 29, 2013 7:51pm May 29, 2013 7:51pm
  •  Gumrai
  • Joined Oct 2012 | Status: Member | 1,959 Posts
Quoting InsomiaFX
Disliked
Hey Gumrai, nice to see you here. The system is called "Correlation Double Hedge" not Double Hedge. We want the double hedge to remove margin and thus have more money to survive drawdowns. Swap is negative, yep.But you can run this with VAR_DoubleHedge = false and have only Pair 1 with margin and a positive swap. What's better is up to the individual trader I guess. Profits are done by each pair separated from each other. If Pair 1 (Order 1A & 1B) as the sum has a profit, we close this Pair. Throw this on a demo account and see how it works....
Ignored
Yes, but if you close the correlated pair that is in profit, what remains is net exposure to AUDCAD
If AUDCAD continues in the same direction you would soon be losing heavily.

If you simply trade Pair 1 (Order 1A & 1B), you again have net exposure to AUDCAD
Please Do Not PM Me With Coding Enquiries
 
 
  • Post #18
  • Quote
  • Edited 10:09pm May 29, 2013 9:48pm | Edited 10:09pm
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Every pair that gets closed will be recreated instantly unless that's prevented by the VAR_DDLimit parameter to avoid huge drawdowns.

Net exposure to AUDCAD is relevant over the long term only if a pair won't close for weeks or so. Look how much AUDCAD changes in 48 hours. Its very little.

The EA has a code example to adjust the CADJPY lot size to match the AUDJPY lot size based on the same USD base value. So whenever a pair is closed, the lot size for the next pair can be adjusted and any difference in AUDCAD will be removed. Thats also where the pip price differences can be matched in as pointed out by txfxtrader and any differences in daily volatility between AUDJPY and CADJPY. But thats all fine tuning stuff.

As pairs are expected to close and reopen several times per day, any unbalance in AUDCAD should be irrelevant, at least for short term demo testing.
Remember, the correlation can mix around a pair by more than 50% within minutes. Correlation is they key here to decide about profits or losses, everything else is pretty unimportant.

If you trade Pair 1 only, you do that mostly to collect swap. Its a very stable, very rewarding swap cash cow. On top of that, you can cash in any correlation profit. If you adjust the lot sizes as I pointed out above, any AUDCAD changes are automatically set to 0 as Pair 1 will be recreated after it has been closed.

In fact, if you are a swap only trader, I cannot think of any other way to prevent losses due to net exposure then to close the pair with correlation. Cash in a nice bonus profit and recreate the swap pair. Remove any net exposure difference which may have occurred by adjusting the lot sizes with same USD value.
 
 
  • Post #19
  • Quote
  • May 30, 2013 4:17am May 30, 2013 4:17am
  •  dokopy
  • Joined May 2013 | Status: Member | 821 Posts
EA does not open any position.
Please excuse the bad English via Google Translate.
 
 
  • Post #20
  • Quote
  • May 30, 2013 8:14am May 30, 2013 8:14am
  •  InsomiaFX
  • | Joined Jan 2013 | Status: InsomiaFX | 35 Posts
Do you use Exness ?
https://www.exness.com/trial_account

If yes, you need to open AUDJPY and attach the EA to that chart.

For all other brokers you need to change the currency pair code as explained in the OP.
 
 
  • Trading Systems
  • /
  • InsomiaFX Correlation Double Hedge EA
  • Reply to Thread
    • Page 1 23 4
    • Page 1 23 4
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023