Poplular Hedge-trading system: The �Hedge� Rocks Expert Advisor for MT4

Ok, I took out the copy protection stuff and tried to organize things a little before I post it. Almost ready! BTW I have a real job which I have to tend to occasionally so, I am doing this as fast as I can (to the more impatient of you).

Before I post my EA:  The �Hedge� Rocks Expert Advisor for MT4.  I warn you now that I am more of a math dude than a MQL/MT4 programmer:  my programming techniques are much like my surroundings� disorganized and messy.  However, the math is sound and matches the FR trading system to a high degree of precision.  Feel free to clean up my code if you wish.  

Now some caveats:
  1. This EA was never tested on the real thing� only demos. It is still somewhat buggy. Don�t run it on a live account unless you thoroughly test it on a demo account.

  2. I wrote this using the tradeviewforex.com demo account. It is calibrated to use 200:1 leverage with 100K lot sizes and roughly a 10K or 100K account balance.

  3. The sizes of your purchased lots (according to FR) should be no less than .5 to ensure that the ratios between the hedge groups are optimized. It still seems to work fine with less. If you choose the highest leverage or use 10K or �micro� lot sizes to trade, the purchased lots will be higher. If you can�t change your lot sizes or your leverage� than you have to increase the amount you trade� via the Margin Percentage or the account balance� or both. It seems to work just fine with purchased lots of less than .5 but, that is what they say.

  4. I simply copied the FR system as best I could and have no opinion on its validity. They all seem a bit fanatical if you ask me� and that whole direct marketing thing is just not my cup of tea. It certainly can lose in spite what your Cool-Aide-Drinking friends at FR might tell you.

BUGS:

  1. During the placing of the initial orders, sometimes one of two members of a currency group gets rejected by the broker which causes it to sell the remaining pair and reorder the group� causing you to eat the spread on the sold pair. It has something to do with the speed at which some brokers can accept orders.

  2. Rarely, it has a problem getting the historical data and crashes out my little Pearson Correlation routine at the end. I put in a bunch of catches but it still throws an error on rare occasion.

Feel free to ask me questions. I will the EA and instructions next.

[QUOTE=alphaone;42135]

Here it is:

Recommend pairs and time charts?

Drop it on any chart… it doesn’t get any info from the chart that it’s paired with. Currency pairs? EURUSD - USDCHF Best Correlation; GBPUSD - USDCHF second best. The EURUSD - USDJPY not so good. The GBPUSD - USDJPY is the least safe. The higher the risk, the higher the interest.

I can’t get this to work in the strategy tester on MT4. Is there something I need to adjust?

It won’t backtest because it draws both historical data and data from other currencies other than the chart it’s dropped on. It does not seem to be able to access that data under the Strategy Tester. What I suggest is to run it on the MT4 demo then generate a detailed report when you feel enough time has passed.

I like your coding mate!

Can you explain the basic idea of this trading system, please

Cheers

waiting for your instrustions. Thanks.

This Expert Advisor is designed to run under the MetaTrader-4 Platform.

It is a mathematical system which pits one currency pair against another inversely-correlative pair. It uses a very complex mathematical formula to determine the optimal ratios based on your account balance, margin percentage, size of the lots and the leverage you are using.

The system emphasizes three things: Overnight interest, buy low, sell high and profit grabs.

O/N INTEREST:

The short-term, overnight interest rates (or swap rates) are extremely high in Forex. When you leave your positions overnight you will accrue interest. If the currency pairs were perfectly correlated, the net gain/loss would be zero and you would accrue the high interest rates with no risk to your principle.

BL/SH:

The paradigm of buying low and selling high is a staple for all investing. This system sets Buy and Sell limits for each currency bought. Using a complex mathematical formula, the buy and sell limits, as well as the amount to purchase, are optimally set around each currency pair purchased. When the currency pair drops past the Buy Limit, the order is executed, that number of lots is bought and new limits are calculated and set around that price. Similarly, when the currency pair rises past the Sell Limit, an amount determined by the formula is sold short and new limits are calculated and set round the price. The EA monitors the progress of the limit orders once they have been executed into Buy or Sell orders. Just like the profit grabs and drawdown max, the limit orders wait for a particular profit or max loss to be realized. In addition, the program logic also monitors the average variations of the past few hours and calculates the best time to close the order for maximal gain or minimal loss. This algorithm also protects against wild swings in the currency and consequently avoids large losses in favor of modest gains.

[SEE IMAGE 1]

The idea of �profit grabs,� is simple: since no two currency groups are perfectly correlated, one pair will always lag behind or race ahead of the other. These fluctuations will show up as a net gain or net loss on the pair-group. Sometimes the group will �draw down,� such that the net loss dips down into your equity. Sometimes the group will swing positive and the net gain will add to your equity. A constant state of flux will always exist. The idea is to take the profit when it swings high enough to trigger a grab. Once grabbed, the pair-group is reallocated and the process starts again. Since hedging does not care at what value either of the currency pairs start at, there is no penalty for taking a profit grab and reallocating.

[SEE IMAGE 2]

In summary, the system is designed to hedge two, inversely correlative currency pairs against one another. If this group maintains a reasonable correlation, the position is left overnight to accrue interest. If this group fluctuates in the positive direction past a pre-determined cutoff, profits are taken and the group is reallocated. The whole while, buy limits are waiting for a currency pair to swing low, in order to buy lots or high in order to sell them.

hedge1.bmp (402 KB)

hedg2.bmp (506 KB)

1 Like

[QUOTE=forexea;43490]waiting for your instrustions. Thanks.[/QUOTE]

  1. Copy the file Hedge Rocks.mq4 to the:
    �C:\Program Files\TradeView FX MT4 Prime\experts� Directory and compile it to Hedge Rocks.ex4

  1. Restart the TradeView FX MT4 Prime program

  2. From the Navigator Menu, Drag and Drop the Expert Advisor named “Hedge Rocks” to any chart you want.

  1. The first tab is called COMMON: You will be prompted to check/set the properties for the Expert Advisor: Ensure that: �Allow live trading,� is checked. (you will have to check this every time unless you set this as your default in the program options).

  1. The second tab is called INPUTS: You can change any one of these properties if you would like� or leave the optimized defaults as shown below. This version allows you to trade either the EURUSD or the GBPUSD or both: EURUSD&GBPUSD against one of the two: USDCHF or USDJPY. The default is to trade the EURUSD-USDCHF and the GBPUSD-USDCHF pairs simultaneously. You may change them to fit your trading preference by changing the value from true to false or visa versa.

6 - 8 DELETED (not applicable)

  1. Make sure to press the Expert Advisor button at the top in order to enable the advisor (as shown below)

  1. Make sure that the little smiley face at the top right hand corner of the chart you dropped the EA onto� Is in fact smiling. If it is an unhappy face, you forgot to check �Allow live trading�

  2. The EA is tickwise: Meaning that it waits for an update from the server (a tick) and runs its cycle upon each tick. Before the first tick, it will say, �waiting for tick.� As soon as it receives it, you will see all of the yellow information appear on the chart. If, after a time, you don�t see any yellow text� ensure that you have pressed the Expert Advisor button at the top of your program.

This is a hedging system. The idea is to trade currency pairs which go in opposite directions. All things being perfect, the net gain/loss would always be zero and you would simply accrue the high interest rates. Since the hedging pairs are not perfect, we take advantage of this by :

� Buying high, selling low with Limit orders
� Grabbing windfall profits when the pairs go out of sync, in your favor.
� Always drawing interest on positions left overnight.

The EA is automatic� sit back and watch. Everything is done for you.

Thanks for all of this. I really appreciate as one of my colleague is trading with FR and seems to be farely sucessfull.

Hi alphaone,

I think your EA works very well in my demo-account. Is it also possible to run your EA on a Real-account with leverage 1:400?

thank for your answer.

p.s. sorry for my bad english

The FR people recommend 400:1 leverage and I mimicked their system. So the answer is yes. You may need to modify the grab_profit_factor and play with the properties to suit your tastes.

You said it has been tested with demo accounts before… what are the results like? How many pips (or what is the % return) per trade, per week, per month or whatever timeframe you want to use.

Hi,

Sometimes it works really fast to your advantage. I closed all open trades every time, if I had EUR 50,00.
Sometimes you have to wait some time (maybe 1 - 2 weeks), till you could close your trades with profit.

It�s not possible to give you a correct definition, because the market works like he works.

yours

Hi alphaone,

do you have also other EA�s in your usage?

yours

How to adjust work on other broker?
Please, delete MessageBox - EA test with tradeviewforex.com DEMO at 200:1
and …is poorly correlated (+). It complicates work.

Nice EA! Could you give an idea of how the profit factor works? How, for example should I set it to grab 5% profit?
Michael

Did you figure out how this works?

Lost everything on real account in five days, but first three days were promising :frowning: