Many people here on Forex Factory have been very kind to me with my occasional needs for coding help.
Attached is an EA I coded, which does need a Forex account that allows hedging for it to be useful. Putting it online here for others to use is simply to give something back to this forum and as a way to say thank you.
It is a "Trade Manager" type EA, not a trading strategy.
It works as follows:
For all 3 areas (Free Margin, Equity Profit and Equity Loss), when it starts up (or you restart MT4), it calculates the difference between sell and buy lots that are open as well as your opening equity and free margin levels.
At pre-set trigger points that you set in inputs, it will open a trade to balance lots.
Eg, With Equity Loss and Equity Profit, it makes the lots equal to lock in the profit or limit the loss. With free Margin, it opens an opposite order to leave 50% of the trade in favor of the direction you have.
The trigger points and lots info are shown on the chart so that you know where things are at.
Free Margin -
In inputs, you can select the % of Free Margin at which point the 50% balance trade gets opened. That is, "extern int FM = 0.3" means that when Free Margin gets down to 30%, it will open an opposite trade equal to 50% of the open lots. This leaves the majority of your open lots in favor of the direction you wanted, but prevents your account from any margin calls.
TakeProfitFM is the pips of profit this trade can be closed at.
Equity Loss -
In inputs, you can set the maximum loss of equity you will accept before an opposite order will balance your buy/sell lots. That is "extern double MaxLoss = 0.25" equals 25% loss of equity to my account will trigger a balancing trade that makes buy and sell lots equal.
When this trade is opened, it resets the MaxLoss level at the set % lower.
NOTE: This code tracks best price/equity. As your account improves equity/profit, it tracks and changes the MaxLoss tigger point according to the new/higher level.
TakeProfitML is the pips in profit this trade can be closed at.
Equity Profit -
In inputs, you can set the maximum increase of equity you will accept before an opposite order will balance your buy/sell lots. That is "extern double HeapsProfit = 0.25" equals 25% profit on equity to my account will trigger a balancing trade the makes buy and sell lots equal. This is to lock in a profit, which emotionally we often see disappear before our eyes before we take action.
When this trade is opened, it resets the HeapsProfit level at the set % higher.
TakeProfitHP is the pips in profit these trades can be closed at.
The way to use this EA is to attach it to any chart. It is not related to time frames. Any other EAs you use of course run on their own charts. That is, this is a "stand-alone EA" that I use not for the primary trades I open, but to cover my butt when things go good or bad.
Any comments welcome, but please don't think I'm interested in adding lots of functions - my coding skill is only a few rungs up the learning curve ladder.
Attached is an EA I coded, which does need a Forex account that allows hedging for it to be useful. Putting it online here for others to use is simply to give something back to this forum and as a way to say thank you.
It is a "Trade Manager" type EA, not a trading strategy.
It works as follows:
For all 3 areas (Free Margin, Equity Profit and Equity Loss), when it starts up (or you restart MT4), it calculates the difference between sell and buy lots that are open as well as your opening equity and free margin levels.
At pre-set trigger points that you set in inputs, it will open a trade to balance lots.
Eg, With Equity Loss and Equity Profit, it makes the lots equal to lock in the profit or limit the loss. With free Margin, it opens an opposite order to leave 50% of the trade in favor of the direction you have.
The trigger points and lots info are shown on the chart so that you know where things are at.
Free Margin -
In inputs, you can select the % of Free Margin at which point the 50% balance trade gets opened. That is, "extern int FM = 0.3" means that when Free Margin gets down to 30%, it will open an opposite trade equal to 50% of the open lots. This leaves the majority of your open lots in favor of the direction you wanted, but prevents your account from any margin calls.
TakeProfitFM is the pips of profit this trade can be closed at.
Equity Loss -
In inputs, you can set the maximum loss of equity you will accept before an opposite order will balance your buy/sell lots. That is "extern double MaxLoss = 0.25" equals 25% loss of equity to my account will trigger a balancing trade that makes buy and sell lots equal.
When this trade is opened, it resets the MaxLoss level at the set % lower.
NOTE: This code tracks best price/equity. As your account improves equity/profit, it tracks and changes the MaxLoss tigger point according to the new/higher level.
TakeProfitML is the pips in profit this trade can be closed at.
Equity Profit -
In inputs, you can set the maximum increase of equity you will accept before an opposite order will balance your buy/sell lots. That is "extern double HeapsProfit = 0.25" equals 25% profit on equity to my account will trigger a balancing trade the makes buy and sell lots equal. This is to lock in a profit, which emotionally we often see disappear before our eyes before we take action.
When this trade is opened, it resets the HeapsProfit level at the set % higher.
TakeProfitHP is the pips in profit these trades can be closed at.
The way to use this EA is to attach it to any chart. It is not related to time frames. Any other EAs you use of course run on their own charts. That is, this is a "stand-alone EA" that I use not for the primary trades I open, but to cover my butt when things go good or bad.
Any comments welcome, but please don't think I'm interested in adding lots of functions - my coding skill is only a few rungs up the learning curve ladder.
Attached File(s)
Equity and Free Margin Manager.mq4
9 KB
|
2,946 downloads