Hedge the Hedge Manual v1.2

From JTAWiki
(Redirected from Manual Hedge the Hedge)
Jump to: navigation, search

JTA_Sales.png   Hedge the Hedge Manual v1.2 
From JTAWiki, a project by J Talon LLC

Warning.png Please note that Hedge the Hedge v1.2 can only be used on MT4 build 600+, and all previous builds can only be used on MT4 build 509 and previous.


Hedge the Hedge (HH) was originally conceived as an EA which would trade purely based on Price Action. One thing is guaranteed in Forex: no matter when or at what price you place a trade, the price will eventually move either up or down.

If the price moves in the direction of the trade then all we need to do is set a Take Profit point, and close the trade when it is hit.

If the price moves against the direction of the trade then the easiest way out is to set a stop loss, and close the trade at a certain loss. There are many EAs which work on this principle, and in order to make money they rely on the trade direction decision to be correct more often that they get it wrong.

HH uses a different strategy - if the price moves a certain distance from the first trade it will open a second trade in the opposite direction. The distance between the two trades (here called the channel) is set by the user, and the TP distance used for the first trade is set at a similar distance from the second trade. This does mean that the EA will not work with brokers who do not allow hedging.

The lot size of the first trade can be fixed, or automatically calculated using Money Management. The lot size of subsequent trades is calculated to be of a sufficient size to cover the loss incurred on the first trade and also guarantee an overall profit i.e. it ensures that the Break Even point of all trades lies within the TP point.

Should the price reverse again before the TP is hit for the second trade, HH will open a third trade in the same direction as the first if the opposite channel boundary is reached, setting the TP point and lot size in the same manner as trade #2. In this way every time the channel boundary is hit HH will open a bigger trade in the opposite direction - in effect it is hedging the hedge trade - which is where the name came from.

If you have a more hands on approach when running EAs, you also have the option of manually adding trades to the basket. Note: It is not recommended that you close individual trades manually - it can cause problems placing the channel.

The basket of trades will close when the Take Profit point has been hit, but you also have the choice of increasing the profits using Profit Trailing or a Trailing Stop. Take Profit points are normally kept internally, but you may use the Stealth Mode to send the actual or a dummy TP to the broker in case of loss of internet connection.

HH has our usual Equity Protection functions, such as Equity Stop Losses, Power Out Stop Loss and Emergency Close All.

There are also several means of restricting trading, including a trading time filter, ShutDown and Holiday Shut Down functions.

Trades are tracked using our trade tracking function, with user defined Trade Comment and User Comments.

HH will give you visual feedback information via a display overlay, as well as lines to show BE and TP points and buttons for manual trade execution. You can view the main details of every open chart by using the JTA Dashboard. It will also save statistics in order to allow you to create an equity chart.

Back to Overview



You can download the installation file from our store by using the link in the email sent to you confirming your payment. You should bookmark this link, to ensure that you always have access to download the installation file.


Please follow the instructions on the EA Installation page of our Wiki.


As long as you remain a subscriber, or if you have purchased Hedge the Hedge, you are entitled to receive all upgrades of the EA for free. When an upgrade is released, you will be advised via email to the email address used when you made your payment. If you would like to change your email address, then please send details of the new address to sales@JTAToday.com.

The EA will automatically download any new version to a folder on your hard drive through the Auto Update function, and will display a button on the chart to inform you that a new releae is available. Read more about where the file is stored, and how to install it from the Auto Update page of the Wiki.


If you have problems when installing the files, attaching the EA to a chart, or running it, please go through each of the items on the Experts troubleshooting page of the Wiki.

Error Messages

After you have successfully installed the EA there are many checks made on the Input Parameters and your Account Settings to ensure that there are no problems. If there are problems which are serious enough to stop the EA from trading then you will see an Error Message on the Overlay, and you can get more details of the error and possible solutions on the Error Messages page of the Wiki.

Placing the First Trade

Entry Methods

The placing of trades will only be allowed if AllowTrades is set to true. If AllowTrades is set to false then no trades will be placed, but you will be able to view the details on the chart overlay - see Restricting Trading for details.

Although the EA is based on price action, it makes sense to try to open the first trade with the direction of the trend. There are 2 entry methods - one based on the comparison between two moving averages (MAEntry), and the other based on the Bollinger Bands indicator (BBEntry).

MAEntry has 2 settings: 0 will turn it off; 1 will turn it on.

BBEntry has 3 settings: 0 will turn it off; 1 will turn it on; and 2 will allow it to trade in reverse.

Note: If you set both entry options to 0 then the EA will not open any trades.

If the UseAnyEntry setting is set to false and both entry methods are in use then they must both signal that conditions are correct before a new basket is allowed to open. If UseAnyEntry is true then either entry method can trigger a new basket - and if they indicate a new trade in opposite directions then the BBEntry will override the MAEntry.

You can also restrict trading during times of low price movement by using a filter based on the ATR indicator.

Once a basket has closed, if the entry conditions do not allow a new basket to open immediately then the next trade will always be based on the entry method(s) in use. However if the entry conditions do allow a new trade to open immediately then it will open in the direction of the last trade of the previous basket, which may not necessarily be the same direction as calculated by the entry conditions. For example if you are using the MAEntry and the conditions say go LONG, a Buy trade will open. If the price reverses and the EA opens a Sell trade, which then closes the basket at TP, the next basket will open SHORT, even though the MA may still say go LONG. This ensures that new baskets will keep opening trades in the same direction of the last trade closed.

You may override this function, and force HH to always open a new basket based on the entry conditions by setting AlwaysMA to true. There is no corresponding setting for the BBEntry method because if the price has changed direction and forced a second trade to open in a basket it is unlikely that the BB entry method will still be indicating that a trade can be opened.

Moving Average Entry

If MAEntry is set to 0, then this entry method will be turned off.

If MAEntry is set to 1, the EA will compare the values of two moving averages - a slow and fast MA - and will place a LONG trade if the Fast MA is above the Slow MA, and a SHORT trade if the Fast MA is below the Slow MA.

The settings for both Fast and Slow MA can be set by the user with the following parameters:

MAFastPeriod - sets the number of periods (bars).
MAFastMethod - choose from:
0 Simple moving average,
1 Exponential moving average,
2 Smoothed moving average,
3 Linear weighted moving average.
MAFastPrice - choose from:
0 Close price.
1 Open price.
2 High price.
3 Low price.
4 Median price, (high+low)/2.
5 Typical price, (high+low+close)/3.
6 Weighted close price, (high+low+close+close)/4.
MASlowPeriod - sets the number of periods (bars).
MASlowMethod - choose from:
0 Simple moving average,
1 Exponential moving average,
2 Smoothed moving average,
3 Linear weighted moving average.
MASlowPrice - choose from:
0 Close price.
1 Open price.
2 High price.
3 Low price.
4 Median price, (high+low)/2.
5 Typical price, (high+low+close)/3.
6 Weighted close price, (high+low+close+close)/4.

Note that there is no means of setting the timeframe for either MA because they both use the TF of the chart that the EA is attached to. If you need to use a different TF for the MA calculations then simply change the chart time frame.

There is also no setting for this entry method to trade in reverse, but this can be achieved simply by reversing the settings of the Fast and Slow MA periods i.e setting MAFastPeriod greater than MASlowPeriod.

Bollinger Bands Entry

If BBEntry is set to 0, then this entry method will be turned off.

If BBEntry is set to 1, then a SHORT trade will be placed if the price passes the Upper Bollinger Band plus BBDistance, and a LONG trade if the price passes the Lower Bollinger Band minus BBDistance.

If BBEntry is set to 2, then the BBEntry will trade in reverse, i.e. a LONG trade will be placed if the price passes the Upper Bollinger Band plus BBDistance, and a SHORT trade if the price passes the Lower Bollinger Band minus BBDistance.

The value of BBDistance in effect creates a wider channel parallel to the Upper and Lower Bollinger Bands, which will reduce the number of entry opportunities. However you can also enter a negative value for BBDistance which will make the channel become narrower than the upper and lower bands.

The settings for the Bollinger Bands can be set by the user with the following parameters:

BBTF - sets the Time Frame
BBPeriod - sets the number of periods (bars)
BBDeviation - sets the standard deviation for the bands
BBPrice - choose from:
0 Close price.
1 Open price.
2 High price.
3 Low price.
4 Median price, (high+low)/2.
5 Typical price, (high+low+close)/3.
6 Weighted close price, (high+low+close+close)/4.

ATR Entry Filter

The Average True Range (ATR) filter will allow you to stop new baskets of trades opening when the price movement is small. New baskets will only be allowed to open when the calculated ATR is greater than the value set in ATRMinimum.

The settings for the ATR filter can be set by the user with the following parameters: ATRTF - sets the Time Frame ATRPeriod - sets the number of periods (bars)

The Trading Times label on the overlay will display a message if the ATR filter is restricting a new basket opening.

Back to Overview

Setting the Channel

Initial Settings

The initial channel size is set with the Channel parameter, and the first trade of a basket will form one of the boundaries - if the first trade is LONG then it will form the upper boundary, and if SHORT will form the lower boundary.

There is a limit as to how small the channel can be - it can not be less than the spread of the chart because that would cause multiple trades to open instantaneously when the entry conditions are met. In order to avoid this, and because the spread can vary during different trading conditions, the minimum Channel size should be set to a value higher than the expected maximum spread.

Placing the Second and Subsequent Trades

If the price reverses before the Take Profit point is reached and it passes the opposite boundary of the channel, then HH will open another trade in the opposite direction to the first, so that the direction of the basket trades is reversed. In this manner HH is trying to set the TP point in the direction that the price is currently moving.

Resizing the Channel

While the initial size of the channel is fixed in the parameters, there are two methods of resizing it during operation. The first is a simple Channel Resize Percentage, and the second is based on the Bollinger Bands indicator.

Channel Resize Percentage

If CResizePC is set to 0, then no resizing of the channel will be performed - it will remain fixed at the original Channel setting (unless the Bollinger Bands Resize is in use).

If CResizePC is a value greater than 0 then after every second trade the channel size will be increased by that percentage. For example if the original channel was 50 and CResizePC is set at 10 there will be 50 pips between the first and second trade, but then the channel will be resized to 55 pips (50 + 10% (5) = 55). The channel size has increased by 5 pips, which will place the upper channel 2.5 pips higher and the lower channel 2.5 pips lower. Once 2 trades have been placed at these new channel boundaries the channel size will increase by another 10% - that is another 10% of the original channel size, and not 10% of the new channel size, so the new channel will be 60 pips wide. Again both boundaries are moved out by 2.5 pips.

If CResizePC is a value less than than 0 then the channel size will be reduced by the set percentage every second trade. Other than the channel size reducing, the resize operation is calculated exactly the same as above. In order to prevent the channel size becoming negative the value of CResizePC will be restricted so that the maximum trades will be allowed to open and still have a positive channel size.

Note that if the Bollinger Bands Resize is also in use then that function will take precedence, and the Channel Resize Percentage will be ignored as soon as CBBTrades are open.

Bollinger Bands Resize

If the value of CBBTrade is set to 0 then this function will not be used.

If the value of CBBTrade is set to a value greater than 0 then when that number of trades is open in the basket the channel will be based on the Upper and Lower band of the Bollinger Bands indicator.

The settings for the Bollinger Bands can be set by the user with the following parameters:

CBBTF - sets the Time Frame
CBBPeriod - sets the number of periods (bars)
CBBDeviation - sets the standard deviation for the bands
CBBPrice - choose from:
0 Close price.
1 Open price.
2 High price.
3 Low price.
4 Median price, (high+low)/2.
5 Typical price, (high+low+close)/3.
6 Weighted close price, (high+low+close+close)/4.

Note that if the Channel Resize Percentage is also in use then that function will be used until the number of trades in CBBTrade is reached, when the Bollinger Bands Resize will take precedence.

Back to Overview

Manual Trading

Adding Trades Manually

It is possible to place a manual trade to either add to an existing basket, or to create a new one. In order to use the BUY and SELL buttons on the display you must have dButtons set to true. It is also possible to place trades using the Knight-Fire tool provided by ianj, but you must ensure that the correct magic number and lot size are entered.

If there is not a basket of trades open then the lot size of the new trade will be set to the normal Starting Lot size.

If there is already a basket open and the manual trade follows the normal alternating sequence then the lot size used will follow the normal lot size calculation. If the trade is placed against the normal sequence then the lot size will normally be the Starting Lot.

Warning.png Placing a trade against the normal alternating sequence, and in some cases even following the sequence, may cause unexpected results when placing the Channel and Take Profit point. Please use this feature with care.

If ConfirmButtons is set to true then you will be asked to confirm the trade placement. However if ConfirmButtons is set to false, you will only be asked to confirm the trade if it goes against the normal pattern of trades, for example if you click the BUY button when the last trade opened was also a BUY trade.

Warning.png If you use ConfirmButtons then the time taken to place the trade will take longer, and it is possible for the price to have changed so much that the trade is rejected by the broker. Please check the Terminal/Experts log for any error messages and be prepared to place the trade again if required.

Closing Trades Manually

Warning.png It is not recommended that you close individual trades in a basket. Doing so can have unexpected results, and can cause problems when placing the Channel, and calculating Take Profit points.

If you need to close trades manually then we recommend that you close all the trades of a basket, which can be achieved quickly by clicking the ECA button.

Back to Overview

Money Management

First Lot Size Calculation

If UseMM is set to false, then the lot size for the first trade will be based on the value set in StartLot.

If UseMM is set to true then the starting lot size is based on the portion balance (set with PortionPC), adjusted by the value set in Aggression. An Aggression of 1 will produce a starting lot size of roughly 0.01 for each $5,000 USD of Portion Balance. This ratio will vary depending on the leverage of your account and the currencies being traded.

If your account is a Nano account then you should set the NanoAccount parameter to true. This will effectively multiply your account balance by 10 to offset the fact that the contract size of the currency being traded is only 10,000 units instead of the normal 100,000.

Star full 256.png
If you are trading on a Nano account with a reduced balance because of the reduced contract size then you should leave NanoAccount set to false.

If you are trading metals or stocks then please check the contract size of a normal Forex symbol and set the NanoAccount parameter accordingly.

Warning.png If you set NanoAccount to true when your account is not a Nano account then all lot size calculations will be 10 times their proper values, and you will certainly increase drawdown and the chances of hitting Equity Protection.

Currency Conversion

If you are using Money Management and your live/demo account is not held in USD, then it is important that the formula used in calculating the starting lot size is consistent with our back tests, so our proprietary Currency Convertor will automatically convert your Portion Balance into USD before performing the MM calculation.

In order for Currency Conversion to work the Currency Symbol for your account currency/USD must be visible in the Market Watch window - you will see an error message if the EA can not find it. If the Currency Symbol has a Prefix or a Suffix then these should be entered in the appropriate parameter on the input screen (F7).

Warning.png The Currency Convertor can not work when back testing because MT4 is not capable of using currencies other than the one under test. When back testing you should always use a demo account in USD.

The overlay display will show you the Portion Balance currency conversion, and also the approximate ratio for the portion balance for every 0.01 lot.

Recovery Mode

Recovery mode is used to increase the starting lot size of the first few baskets after an Equity Stop Loss hit. The theory is that after an EP hit the next few trades are likely to follow the current trend, and will all be single trade baskets. Because they only have one trade open before hitting TP it is fairly safe to increase the starting lot of those trades in order to increase the profits and recoup some of the losses from the EP hit.

Recovery Mode can be turned on by setting UseRecovery to true.

RecoveryMult will set the multiplier to increase the Starting Lot by, and RecoveryTrades will set the number of new baskets which will use the increased starting lot.

If you are in the unfortunate position of having a second EP hit while Recovery Mode is still trying to recover from the first then the Recovery Level will increase. The Recovery Level will also affect the lot size of the Recovery Trades - at Level 2 the RecoveryMult value will be doubled, and at Level 3 it will be trebled etc. The number of Recovery Levels allowed can be restricted by using RecoveryMax. Once the number of RecoveryTrades has closed at each Level, then the Level is reduced and the next set of Recovery Trades is opened, until the Recovery Level reaches 0.

Warning.png Use Recovery Mode with care - increasing the lot size of the following baskets will increase the chance of having another EP hit if the price starts ranging again, and will exacerbate the problem instead of relieving it.

Back to Overview

Lot Size Calculation

Once the initial trade has opened at the calculated lot size, the price movement may trigger a second and subsequent trades. It is important that the lot size of these trade is sufficient to cover the potential losses on the open trades in the basket, and also to ensure that all trades close at an overall profit when the price reaches the set Take Profit point. In order to do this the EA will ensure that the Break Even point of all open trades is on the right side of the Take Profit point by dynamically calculating the lot size based on the losses on open trades and the open price of the new trade.

Because a small increase in the lot size at lower basket sizes can cause a much exaggerated increase in lot size when more levels are opened, the EA will calculate the smallest lot size possible while still ensuring a profit.

Back to Overview

Profit Taking

Take Profit

The Take Profit point of every trade is set TakeProfitPips away from the trade open price, so that every time a new trade opens the price always has to move the same distance before hitting the TP point.

The pip profit of the first trade will always be TakeProfitPips. However for the second and subsequent trades there will be a smaller pip profit because the break even point of the basket will move closer to the TP point, and despite the increase in the lot size the actual value of the profit will probably be smaller.

The calculation of the lot size at each new level will include an element of profit until the number of trades equals BreakEvenTrade, when the profit element will be set at 0. However because of the rounding up of the lot size it should still provide a small profit when the basket is closed, especially when using ProfitTrailing.

Profit Trailing

In order to increase the profits from a basket you can set ProfitTrailing to true. This will allow the profits to grow as the price continues past the Take Profit point, and will only close the basket when the profit value drops by the percentage set in MaxRetrace, as long as the remaining profit is still greater than or equal to the profit target.

Note that if ProfitTrailing is in force then it will take precedence over the Trailing Stop.

Warning.png If UseStealth is set to false then the broker will automatically close the trades at the fixed Take Profit point, and Profit Trailing will be disregarded.

Trailing Stop

The Trailing Stop feature is also used to increase the profits from a basket, and will become active when the TSLPips is changed from its default value of 0.

If TSLPips is a positive value then the trailing stop will trail the price by the value of TSLPips.

If TSLPips is a negative value then it will still be treated as positive trailing stop, but the size of the stop will be reduced as more profit is made.

The point at which the trailing stop will start is set to the Take Profit point, unless the BreakEvenTrade has been reached, in which case it will be the Break Even point.

Note that if ProfitTrailing is in force then it will take precedence over the Trailing Stop.

Warning.png If UseStealth is set to false then the broker will automatically close the trades at the fixed Take Profit point, and the Trailing Stop will be disregarded.

Back to Overview

Stealth Mode

The user has the choice of whether to send the Take Profit to the broker by using the UseStealth setting.

If UseStealth is set to false then the TP point as calculated by the EA will be sent to the broker, and they will automatically close all trades when this point is reached.

Warning.png If Stealth Mode is not in use then neither Profit Trailing or Trailing Stop will work because both of these functions rely on the price passing the set TP point before they close the trades.

Note: If there is more than one trade open, then the trades on the 'losing' side of the channel will need their Stop Loss adjusting for the spread. Those accounts which have a variable spread would result in a modification to the stop loss every time the spread changed, which would overload the connection to the server. To avoid this, the stop loss is calculated using an average spread value which is updated every tick. Because the average spread may differ from the actual spread at the time the basket closes you may see one half of the open trades close, leaving the other half still open. At this point you should either intervene manually to close the remaining trades (use the ECA button), or wait until they hit the broker stop loss. It is also possible that the PA will reverse before hitting the SL, in which case the losses will be reducing and you should close them manually to allow HH to continue trading.

If UseStealth is set to true then the Take Profit point will be kept internally by the EA. While this will stop any price manipulation by any disreputable broker, it does mean that if your internet connection is lost then the trades will continue with no TP point. This can be fixed by setting SendDummyTP to true. The EA will calculate the normal TP point, and then add/deduct the value set in DummyTPPips and send this new TP point to the broker.

Stealth Mode has no effect on POSL, which will always send the stop loss to the broker.

Back to Overview

Equity Protection

Equity Stop Loss Protection

Equity Protection was developed to prevent a total blowout of your account. No matter what entry methods are used, or how you determine the trend, there is no way to 100% guarantee that the first trade of the basket will open in the right direction. We must therefore accept that Hedge the Hedge will sometimes get it wrong, and will need to open a basket of trades in order to trade out of the situation.

However opening extra levels in a basket at increasing lot sizes will increase the drawdown on the account, and could result in losing the whole of the balance.

Hedge the Hedge will protect you from losing all the account balance by using Portion Control to allocate only a fraction of the total account to this chart, and by using MaximumDDpc to limit the amount that can be lost. If the drawdown of the trades opened by this chart reaches MaximumDDpc, then all open trades will be closed.

If the EA ever gets to the stage where a new trade needs to open because the opposite channel has been reached, but there is not enough margin available on the account to allow a trade of the correct lot size then all trades will close. It needs to do this because:

If no trade was allowed to open, then the price would either continue until the account hit a margin call, or it would reverse and allow the basket to close at the set TP point. At best this is a 50:50 chance, and the margin call would not necessarily select the trades from this chart to close - it could close any trade from any chart so HH could drastically affect any other open trades on your account.
It could open a trade with the maximum allowed lot size to use up the rest of the margin. Unfortunately this could cause 3 problems:
If all the margin is used up then there is a very high chance that a small movement in price would cause a margin call, with the same dire consequences as mentioned above.
The opening of the new trade would use up a large chunk of margin, leaving very little of your portion balance available for trading, which then gives a very high chance of the drawdown percentage hitting the MaximumDDpc level, and closing all the trades anyway.
The lot size on the trade which is allowed to open may not be sufficient to overcome the losses on the other trades, and may not place the BE and TP point on the correct side of the channel.
Warning.png You are still able to select the maximum number of trades which are allowed to open in a basket, but this setting has much more serious consequences than our other EAs.

Because HH relies on opening another hedge trade to shift the BE and TP point to the opposite side of the channel, if the total number of trades is reached and the price reverses once again the EA will not allow the next trade to open when the channel boundary is crossed. If this trade can not open, then all trades in the basket will close. It needs to do this because the price could either continue in the same direction and the account would hit a margin call, or the price could reverse and allow the basket to close at the set TP point. There is only a 50:50 chance of having a suitable outcome, and because a margin call could affect other trades on your account the best solution is to automatically close all trades when the maximum trades are open.

Warning.png However you are able to set CloseAtMaxTrades (build 1.0.08 onwards) to false and the basket will remain open. This will allow you to monitor the basket, and manually open trades to help it to close. DO NOT set this parameter to false if you do not intend to monitor the EA regularly.

Power Out Stop Loss (POSL)

Hedge the Hedge does not have to use a Take Profit or Stop Loss which is sent to your broker (see Profit Taking and Stealth Mode. In the unfortunate event of you losing your internet connection, Hedge the Hedge will not be able to monitor trades, so will not be able to close them at a profit, but worse, your open trades will not have any of the above methods of Equity Protection.

In order to maintain Equity Protection you can set UsePowerOutSL to true. This will allow Hedge the Hedge to send a stop loss to your broker, based on the value of POSLPips (default 999) from the break even point of the basket.

When the basket opens the first few levels, the lot sizes are small so a movement of 999 pips will result in a small loss, and will be nowhere near the 50% set in MaxDDPercent. However, as lot sizes increase at higher levels, a movement of 999 pips will cause a much higher loss, so the value of POSL is reduced to limit the maximum loss to MaxDDPercent + 1%. The additional 1% is included so that POSL can not interfere with the normal logic of Hedge the Hedge.

Once POSL has been set by Hedge the Hedge, it can not be removed manually because Hedge the Hedge will automatically reinstate it. In order to remove it, you must leave UsePowerOutSL at true, but change POSLPips to 0. After the next tick, all stop losses should have been removed from the basket trades, and you can change UsePowerOutSL to false.

For the best setting of POSL you should set POSLPips to a value slightly larger than the channel size plus TakeProfitPips. This will ensure that should the internet connection be lost the basket of trades will close if the price passes the point at which the next channel trade should open.

As long as UsePowerOutSL is set to false, you can also set a manual stop loss on any trade, and they will not be overwritten by Hedge the Hedge . Assuming that the trade has not been closed normally by Hedge the Hedge, your broker will close the trade at the SL you have set.

Emergency Close All (ECA)

This is a way of simply getting out of all trades on this chart. A user may have several EAs on their account, or several charts running Hedge the Hedge, and it might be difficult to find every trade relating to this chart and close them out.

The quickest way of initiating ECA is to click the ECA button on the chart, if you have dButtons set to true. If you have ConfirmButtons set to true you will be asked to confirm your action. If ConfirmButtons is set to false then all trades will be close immediately. Once the trades have closed the button will revert to its normal colours, and internally the value of EmergencyCloseAll will be set to false so that further trades will not close automatically.

You can also use the ECA button against the chart summary on the JTA Dashboard if it is active, which acts exactly the same as the button on the chart as described above.

You can also initiate ECA by using the EA's Input Parameters (F7), and setting EmergencyCloseAll to true. Once you click OK, Hedge the Hedge will close ALL open trades on this chart, and the display overlay will warn you that EmergencyCloseAll is set to true. This is as a reminder to change the setting back to false, because if Hedge the Hedge opens more trades and you decide to change the parameters for another reason but do not change EmergencyCloseAll back to false, Hedge the Hedge will once again close all trades.

Hedge the Hedge will close all trades immediately but will continue trading. Depending on what entry method you are using, you may get an immediate placing of a new trade if entry conditions allow. If you also want Hedge the Hedge to stop trading after ECA, you should set ShutDown to true at the same time as setting EmergencyCloseAll to true.

Back to Overview

Restricting Trading

Setting the AllowTrades parameter to false will not allow the EA to open or close any trades on this chart, even though the overlay display will still be updated. You can use this setting to ensure that you have entered other parameters correctly, and the chart portion and starting lot size are to your expectations. Once you are satisfied you can set AllowTrades to true.

Star full 256.png
It is recommended that you leave AllowTrades at false when you load Hedge the Hedge on to a chart, then when the overlay has settled down after a few ticks, and the 'Waiting for next tick ...' message has been cleared, you should click the 'Allow Trades is set to false' button on the chart, which will then allow trading without having to change the EA's Input Parameters again.

However, even with AllowTrades set to false you will still be able to use the buttons on the chart to open a new BUY or SELL trade, or close all trades with the ECA button.

Warning.png AllowTrades is set to false by default - you must change it to true to allow the EA to trade.

Once the EA has started running there are several other settings which can be used to restrict trading:

Time Filter

You can specify at what times Hedge the Hedge should trade by using the time filter. The time settings are based on the start and stop times during each day of the week, with an additional setting for Non-Farm Payroll Fridays.

The start and stop times are based on the 24 hour clock, and can be entered as whole hours (8-15), or hours and minutes using a colon (8:30-16:45), or a combination of the two (9-16:48).

You can set as many trading times during each day as you like by separating each start and stop time with a comma (0-5:30,11-16:45,20:30-24). It is important that each stop time is greater than the previous start time, and each start time is greater then the previous stop time (if any). Each different Start-Stop period during a day is called a session.

To start trading at midnight, set the start hour as 0 (0-?), and to stop at midnight set the stop hour as 24 (?-24). If one day's stop hour is 24, and the next day's start hour is 0, then trading will continue over midnight, and the two periods will be treated as one session.

If you don't want to trade at all during a day, then leave that day's trade times blank.

The start and stop times are based on either your local time, the broker's time, or GMT. All our backtests are based on GMT times, but you have the choice of using local or broker time if you wish. Here is how the settings should be entered:

GMT Time Settings
Enter the start and stop times for each of the sessions that you want to trade each day based on GMT.
The EA needs to know what the time difference is between GMT and your broker, which you can set with BrokerTimeOffset. (Your brokers' web site should have details of what their GMT offset is - if not drop them a line). This time difference can also be calculated automatically if AutoGMTOffset is set to true.
Local Time Settings
Enter the start and stop times for each of the sessions that you want to trade each day based on your local time.
The EA needs to know what the time difference is between your local time and your broker, which you can set with BrokerTimeOffset (Take the Broker Time from the Overlay and deduct your local time. Enter this time difference in BrokerTimeOffset - if the difference is negative make sure you enter a negative value). If you are using local time settings then you must ensure that AutoGMTOffset is set to false.
Broker Time Settings
Enter the start and stop times for each of the sessions that you want to trade each day based on your broker's time. Remember that you may need to change the trading times if your broker is subject to Daylight Saving changes.
The EA does not need to make any adjustments for the GMT offset, so make sure that BrokerTimeOffset is set to 0 and AutoGMTOffset is set to false.

You can choose how the trading times are displayed on the overlay by the use of the DisplayBrokerTimes setting. If set to true then all trading start and stop times will be displayed at the broker's time zone. If left at the default of false the times will be displayed as the user's input times, as they were previously.

The display overlay will inform you of the stop time of the current trading session or the start time of the next trading session in Green. If there is a basket of trades open and the session has ended, the display will show the start time of the next session in Yellow. The broker time offset will be shown in brackets after the broker time, and will be displayed in blue if set manually, or green if calculated using AutoGMTOffset, and the Local Time:GMT difference will also be shown in green if positive and red if negative.

Shut Down

ShutDown is a way of telling Hedge the Hedge to stop trading after the current basket is closed. Once the basket closes, Hedge the Hedge simply will not place any more trades until ShutDown is reset to false.

ShutDown can be set to true in the parameter settings of the EA, or simply by clicking the SD button on the chart if dButtons is set to true. You can also use the SD button on the JTA Dashboard. If using the Buttons, you will be asked to confirm your action if ConfirmButtons is set to true.

The colour of the button will be reversed when ShutDown is true, and the chart display overlay will also inform you when it is turned on. You can turn ShutDown on and off as often as you like by clicking the SD button.

Once the basket closes the overlay will display that trading has stopped, and that you will have to set ShutDown to false in order to continue trading. Again, this can be done simply by clicking the SD button.

Holiday Shut Down

Setting UseHolidayShutdown to true will stop Hedge the Hedge from trading during the dates specified in HolidayDates.

The HolidayDates are entered in the format [day]/[month]-[day]/[month], and if there is more than one holiday period they must be separated by a comma. All dates are inclusive, so Hedge the Hedge will restart trading the day after the final holiday date. The next holiday period will be displayed on the display overlay if it is enabled, giving confirmation that the dates have been entered correctly.

You can also automatically set Hedge the Hedge to shut down over the Easter period. This is also controlled through the HolidayDates parameter, but the information is entered in the format 'E-2+3', where the E tells the EA that it is an Easter break, the -2 will shut down for the 2 days before the Easter weekend, and +3 will stop trading for 3 days after the Easter weekend. The date of the Easter weekend is automatically calculated, and both the - and + portions must be present. If you do not want to restrict trading during one of the periods then enter -0 or +0, but note that the EA will not trade on either Good Friday or Easter Monday.

If a basket is open when the holiday shutdown starts, Hedge the Hedge will continue to monitor the trades, and will still open new levels if required, and the Holiday dates will be displayed in orange.

Limiting Open Charts

Hedge the Hedge will allow you to restrict the number of charts with open trades. This means that you could set up 10 charts all running Hedge the Hedge, but only allow 3 of them to have open trades at once. The other 7 will wait patiently until one of the three closes their basket, and will then open a new basket if entry conditions allow. You can also restrict a chart from opening a new basket if the Drawdown on another chart is over a set limit. Both of these restrictions can be applied to only Hedge the Hedge charts, or to charts from any of JTA's EAs.

Because the control of the number of open charts and drawdown needs to be controlled from a central location, this function is run from the JTA Dashboard, which is where you will find all the relevant parameters.

Back to Overview

Trade Tracking

Hedge the Hedge keeps track of all open trades by using a unique magic number.

I say unique because it uses an algorithm based on:

  • The EA name,
  • The EANumber,
  • The chart on which Hedge the Hedge is running, and
  • The time frame of the chart.

This algorithm produces a number between 1 and 2,147,483,647, and while it is extremely unlikely that different instances of any of our EAs would result in the same magic number, it is possible. It is therefore recommended that once Hedge the Hedge has been added to a chart that you check other instances of all EAs to ensure that the magic number is indeed unique (Use the [[JTA_Dashboard|JTA Dashboard for a quick check).

In order to run Hedge the Hedge on 2 or more charts with the same pair and timeframe, then all you need to do is to alter the EANumber, so the first chart has an EANumber of 1 (default), the second an EANumber of 2, etc. This will generate a different magic number for each chart.

There is no need to use a different EANumber to differentiate between a Hedge the Hedge chart and TF when used with other EAs like Evolution and Blessing because they have a different EA name, so will have different magic numbers.

You can bypass the automatic magic number generation by setting a magic number of your own. This is achieved by setting the EANumber to any unique number greater than 99. This EANumber will then become the magic number.

Warning.png Bear in mind that if you change the Time Frame of a chart on which Hedge the Hedge is trading, then a different magic number will be generated.

This means that any open trades on that chart will no longer be monitored. If the TF was changed accidentally, changing it back will allow Hedge the Hedge to carry on trading as normal. However if you want to change the chart TF permanently, you can still monitor any open trades by changing the EANumber to the magic number (displayed at the top right of the chart) BEFORE the TF is changed.

You can keep track of which instance of Hedge the Hedge opened / closed which trades by using the TradeComment parameter. By default this is set to the EA name and version, and can be changed to anything of your choice. You can view the Trade Comment in the 'Trade' and 'Account History' tab of the 'Terminal' window of the MT4 application. If the 'Comment' column is not visible, right click anywhere in the Terminal window, then left click 'Comments'.

It is recommended that you change TradeComment from the default EA name and version, so as not to inform your broker which EA is in use.

Warning.png MT4 build 600+ puts a limit on the number of characters which can be used in the trade comment to 31. Please ensure that your TradeComment is 31 characters or less to enable it to display in the Comment column.

If you are not using the default settings then you can also use the UserComment on the display to identify which settings are in use on this chart. The default setting will show the EA name and build number, but it can be changed to anything you like.

Back to Overview

Feedback Information

Display Overlay

The Overlay will show you a wealth of information, most of which is fairly self explanatory. However there are times when a label will display a different message, or will change colour, so here are some of the subtle changes that you may not notice at first:

Trading Times - this label will normally display in the default display colour if you are displaying the trading times as at the broker's time zone (DisplayBrokerTimes is set to true) or in green if DisplayBrokerTimes is set to false, and will give details of when the current session will end or when the next session is due to start. If there are open trades in the basket when a session comes to an end, the next start time will be displayed in yellow.

This label will also show, in red, some of the reasons why trading has been prevented, for example:

The EA is still processing the first tick after being loaded,
AllowTrades has been set to false.
The spread is greater than MaxSpread
The ATR filter has prevented trading.
Trading has been stopped because of an error in the settings - check the Terminal Experts tab for the reason why.

If Currency Conversion is in use because your account is not held in USD, then the conversion label will display in red if there is an error in the conversion.

The total number of open BUY and SELL trades is normally displayed in DeepSkyBlue. It will be shown in Orange when the BreakEvenTrade has been reached, and in Red when the maximum trades has been reached.

The Drawdown percentage normally displays in DeepSkyBlue, but it will change to Green at 10%, Yellow at 20%, Orange at 30%, and Red at 40%.


Hedge the Hedge is a very complex EA, and in order to ensure that each function is working correctly it is sometimes necessary to enable a Debug print.

Under normal circumstances there is no need to set Debug to true. However there are some occasions when you might find the additional information useful.

With the complex changes to our dll file there are many additional errors which you may encounter. In order to obtain details from the dll another parameter is provided, DebugDLL, which will output messages to a log file.

Warning.png It is highly recommended that you do not set DebugDLL to true unless requested to do so by a member of the JTA team. It will generate a very large log file which will eventually fill your hard disk.

Display Lines

If dLines is set to true then the following horizontal lines will be displayed on the chart at various times:

Green Dash-Dot line - MT4 line to show the open price of a Buy or Sell trade.
DodgerBlue Dash-Dot-Dot line - Line to show the Upper channel boundary.
FireBrick Dash-Dot-Dot line - Line to show the Lower channel boundary.
Orange Solid line - line to show the Break Even point of the open trades.
Gold Solid line - line to show the Take Profit point of the open trades.
Gold Dash line - line to show the Trailing Stop point of the open trades.

The colours of the MT4 open trades arrows will match the colour of the Upper and Lower channel boundaries.

The colours of the MT4 close trades arrows will display in Gold if the basket closed at a profit, and Red if closed at a loss.

Display Buttons

The display overlay also has the option to display several buttons on the chart. Set the parameter dButtons to true to display them, and to false to remove them.

As soon as a button is pressed, its colours will reverse so that you can see that the function has been triggered, and they will revert back to normal once it has finished. The only exceptions to this is the ShutDown (SD) button, which will remain in the reverse colours all the time that ShutDown remains true, and the F, M and P buttons which will be disabled for 5 minutes in order to prevent overloading your computer with multiple clicks.

There are 5 buttons which affect the overlay display, which are the B, O, T, E, and D buttons. These buttons act as follows:

  • D - will turn the Debug information on/off. Note that this will also change the setting of the Debug parameter, with the associated printing of the Debug information in the Experts or Journal tab.
  • E - will turn the Entry condition information on/off.
  • T - will turn the open Trades information on/off.
  • O - will turn all the remaining Overlay information on/off.
  • B - will remove all Buttons, other than the B button, from the screen.

There are 3 buttons which provide links to pages on our web site, which are:

  • F - will open your web browser and take you to the Blessing Pro! Forum.
  • M - will open your web browser and take you to the Blessing Pro! Manual on the Wiki.
  • P - will open your web browser and take you to the Blessing Pro! Parameter page on the Wiki.

The following buttons affect how the EA trades, and you can choose whether these buttons will execute as soon as you press them, or whether they display a messagebox with details of the action to be taken which you have to confirm, by setting the parameter ConfirmButtons. These buttons are:

ECA - see Emergency Close All for operation details.
BUY - see Adding Manual Trades for operation details.
SELL - See Adding Manual Trades for operation details.
SD - See ShutDown for operation details.
Reset - This button will allow you to reset the Maximum Drawdown percent as shown on the display overlay. It will also reset the Maximum Drawdown value and date/time which is displayed if you have Debug set to true. Note that if you have a basket of trades open when the Reset button is pressed, the Maximum Drawdown percent and value will be set to the Drawdown and Minimum Profit figure on the overlay, and the date/time of that drawdown will be set to the date/time at which the button was pressed.

These buttons will only appear under certain circumstances:

  • If you are using the JTA Dashboard then a DB button will also be visible on the chart, which will bring the DashBoard chart to the top when clicked.
  • When AutoUpdate has downloaded a new version you will see a 'New Version Available' button next to the EA name and build number on the chart overlay.
  • If your CID has changed you will see a 'Open CID Swapper' button, which will allow you to change your own CID.

All the buttons will act as they should while back testing in visual mode. The only difference while backtesting is that the Strategy Tester is unable to display a message box, so whether ConfirmButtons is set to true or false the buttons will always act as though it was set to false.

You can change the font size of the button text with the dButtonFontSize variable.


When back testing on a chart, the Strategy Tester report will supply you with summary details of the account balance and relative drawdown. You can also see a graph of how the balance increased, together with the equity at that point. The problem with this graph is that each point is displayed only when a trade closes. It does not show the balance and equity over time, which is what the Statistics settings will allow you to do.

In order to produce a statistics report, you must set SaveStats to true. If you want to save the statistics for a forward test, you should leave the StatsInitialise parameter at its default setting of false so that new data will be added to the existing file. When you are backtesting it will automatically be set to true so that a new statistics file is created for each backtest. So you only need to change StatsInitialise to true when you would like to close an existing stats file and start a new one. You also need to decide how often to store the statistics information, and setting StatsPeriod to 3600 will save the statistics data once every hour, which provides a reasonable number of data points for a 2 or 3 year back test.

For a detailed explanation of what to do with this data read the Creating an Equity Chart page on the Wiki.

Thanks to ianj for providing the idea and original code.

Back to Overview

JTA Dashboard

If you have installed the JTA Dashboard on another chart, then all the important information from the overlay will also be displayed on the Dashboard.

The chart overlay will also have another button showing DB, which will automatically bring the Dashboard chart window to the top.

Please read the JTA Dashboard Manual for further details.

Back to Overview

See Also

Hedge the Hedge Parameters
Hedge the Hedge Manual v1.0
Hedge the Hedge Manual v1.1

Disclaimer Copyright © 1995-2016 J Talon LLC, All rights reserved