How to Set Trading Exits Based on the Profit/Loss of the Current Trade + Example Strategy on Dax

Need More Help? Book Your FREE Strategy Session With Our Team Today!

We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.

BOOK YOUR FREE STRATEGY SESSION NOW >>

Among the various methods we can use to manage the exits of our strategies is one based on the evaluation of the profit/loss of the current trade.

With this method, we can decide, for example, to keep a position open beyond the term provided by the strategy (e.g., end of day in intraday strategies) only in case that position has a loss, to try to recover in the next session.

In this video, we'll show you some practical examples that will help you better understand how this type of exit works and its potential.

By watching the video, you'll discover:
-How to code this type of exit using MultiCharts' dedicated function called Open Position Profit
-A strategy for the DAX that has been in use since 2017 and uses this method
-A comparison of the strategy performance with and without the Open Position Profit exit

Enjoy! 😎

Transcription

Introduction

Hey everyone, and welcome back to this brand-new video.

I'm one of the coaches at Unger Academy here, and since you often ask us if it’s possible to derive the profit and loss value of an open trade, today we’re going to be looking together at how to do that and how to apply those concepts to an automated trading strategy.

The OpenPositionProfit Keyword

Alright, as I mentioned just now, many of our students ask us how to give the machine an order that will only be executed if the current trade loses by a certain amount, for example, or even wins within a certain threshold.

This is where a MultiCharts keyword comes in really handy, which is already standard in all platforms and is used to accurately determine the profit or the loss of the current trade, namely the trade that we have open at that moment.

As indicated in the Power Language Editor dictionary, you can refer to this keyword to see exactly what is the behavior of this function.

We can see that… We can see that the output is a numeric value, and basically this numeric value will indicate the unrealized profit or loss of our open position.

It’s called “Open Position Profit,” and it’s meant to be retrieved this way by simply calling it within a signal.

As a side note, this function can only be used in signals, while it can’t be used, for example, in indicators or functions. So it's just available for signals.

Open Position Profit, and here there are also some examples of how it’s used.

It’s said that it will return a value of zero if at the moment the position is at the level of... if the position is flat, so basically if it is at the parity level.

A value of 10 when the open position is at least $10.

This small symbol here represents the currency.

And one more example. For example, if we write -5 here, it means that we’ll have a loss of at least $5 compared to the entry price.

So you see, this function… I mean, this keyword is really very simple to be used in the script of a trading system.

Now, this reserved word has several uses.

For example, you could check if, on a certain day of the week or after a certain number of days on the market, for example, after three days on the market,
the profit or loss of the open trade corresponds to some parameters we’ve chosen, so it might be worth closing the position.

Another example of use would be to check on Friday, that is, on the last day of the trading week, if the profit is at least $1,000, to keep the position open over-week, meaning beyond the end of the week.

The reason for that is that a gain, namely an open profit, of at least $1,000 could protect us from any news or market news that may arrive when the markets are still closed, so, in other words, between Saturday and Sunday, and so it’s, let's say, an additional protection when we go over-week.

On the other hand, if the trade is negative or at break even, the decision could be made to close the trade on Friday.

This way, you wouldn’t risk seeing gaps, for example, between Friday's close and then Monday's open.

Now we’re going to try to see a practical example of a quite old strategy that we’ve developed for the DAX future, which also leverages this type of indication.

A practical Example (with code)

Alright, and here is our strategy.

It’s a strategy that we’ve been using since 2017.

It’s a basic reversal strategy that buys, so opens a long position, when a false breakout of the previous day’s low occurs and sells, so opens a short position, when a false breakout of the previous day’s high occurs.

So these highs and lows are calculated using the so-called "old" session of the DAX, namely the one that goes from 8:00 a.m. to 10:00 p.m., Frankfurt time.

This is very important because, as you know, the session for this underlying asset was recently extended to the night hours as well, but in this case, we’re going to be sticking with the previous version, so the session that starts at 8 a.m. and ends at 10 p.m.

Where did we use Open Position Profit in this case?

We used it in this variable, the variable called "overnight."

This is, as mentioned, a strategy that enters both long and short.

So the short trades will always be closed at the end of the day. But what will happen with the long trades? So in case we are in a long position and the open profit is negative, so if it is less than zero in this case, that is to say, if at 9p.m., so an hour before the market closes, our long position is losing or in any case its open profit is less than zero, what happens?

What happens is that this variable will be True. So, if we lose, we see it in this line, we won’t close at the end of the day but after two days.

So, we’ll keep the trade open beyond the end of the first session because we’ve seen that this still brings some pretty interesting benefits to the strategy.

On the other hand, if the overnight variable is False, then the trades will be closed intraday, and this applies to both the long and the short trades.

Here is our strategy at work.

As mentioned earlier, it will enter on false breakouts, so it’s a strategy that is based on a reversal approach.

However, the peculiarity, in this case, concerns the exits.

So, you can see that all of these positive long trades are closed at the end of the day because the open position profit was positive at 9 p.m. when the check takes place
and consequently, it wasn’t necessary to hold the position overnight and we closed it at the end of the day.

Here, for example, in this trade, you can see that the strategy had entered a long position. When the check occurred, then in the evening, an hour before the close,
the Open Profit and Loss was certainly lower than the entry price, which was about here, while the close was lower, so the Open Position Profit was lower than zero.

The strategy kept the position open and closed it only the next day.

On the other hand, as you can see, the short trades are always closed at the end of the first trading day.

So, this is a kind of management that is a little bit different than the standard management.

In this case, unfortunately, it didn’t pay to keep the position open beyond the end of the day because as you can see a stop loss occurred.

But, in the vast majority of cases, it does pay, if the strategy is in red at that point at the end of the session, to keep the position open for another session in the hope that the market will recover so we can close our trade at a profit.

Results and Comparisons

Let's have a look at the results of the strategy, which are as follows.

This strategy was codified in 2017, about this point here.

And as you can see, it has experienced its moments of ups and downs, but we can certainly say that it did pretty well overall.

Both the equity line short and even more the equity line long show some very interesting performances.

So, the Open Position Profit has definitely proven to be an excellent ally of systematic traders.

Let's also take a look at the average trade that this strategy produces.

As you can see, the overall total average trade is €389.

Just to make a comparison, it would be interesting to see what would have happened if we didn't use the "overnight" variable in the strategy's script.

To make such a comparison it's sufficient to comment on all the entries where this variable is called.

In this way, the strategy will always open and close the long and short positions within the same session.

And it won’t hold open positions even if the Open Position Profit should be less than zero.

Here, we can see that the strategy always closes also the long trades.

Let's take a look at this. Here, for example, in this case. Do you remember? Theoretically, this trade wasn’t closed before.

Let's take a look at the results. You see, now the average trade drops. Not drastically, I mean, the strategy remains quite good, of course, but the slope and consistency of the gains decrease.

Consequently, on the DAX market, and why not, maybe on other markets as well, you can consider keeping your positions open beyond the end of the session even if they are losing.

Because this could somehow protect our account and save us from losses that might be recouped the next day.

So, guys, if want, hey, please go and give it a try too!

This is a kind of exit that could be very useful.

As mentioned earlier, it's quite versatile and can be used in many ways in strategies.

And if there is anyone among you who is interested in the world of systematic trading, I recommend that you go and click on the link in the description of this video.

From there, you can watch a presentation by Andrea Unger, the only 4-time world champion in real-money trading, or you can get our best-selling book, "The Unger Method" by covering only the shipping costs, or you can even book yourself a free strategic consultation with a member of our team.

And if you liked this video, please be sure to leave us a Like, go and subscribe to our channel, and click on the notification bell to stay updated on the release of all our new content.

And with that, we look forward to seeing you in our next video, until then, bye-bye!

Need More Help? Book Your FREE Strategy Session With Our Team Today!

We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.

BOOK YOUR FREE STRATEGY SESSION NOW >>
Andrea Unger

Andrea Unger

Andrea Unger here and I help retail traders to improve their trading, scientifically. I went from being a cog in the machine in a multinational company to the only 4-Time World Trading Champion in a little more than 10 years.

I've been a professional trader since 2001 and in 2008 I became World Champion using just 4 automated trading systems. 

In 2015 I founded Unger Academy, where I teach my method of developing effecting trading strategies: a scientific, replicable and universal method, based on numbers and statistics, not hunches, which led me and my students to become Champions again and again.

Now I'm here to help you learn how to develop your own strategies, autonomously. This channel will help you improve your trading, know the markets better, and apply the scientific method to financial markets.

Becoming a trader is harder than you think, but if you have passion, will, and sufficient capital, you'll learn how to code and develop effective strategies, manage risk, and diversify a portfolio of trading systems to greatly improve your chances of becoming successful.