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 >>Wouldn't it be nice to be able to overlap two equity lines during the development and optimization of your strategies to compare their performance?
Unfortunately, trading platforms such as MultiCharts or TradeStation don't let you do that.
Yet, comparing different equity lines obtained by varying certain parameters could be very useful during development, especially if you can overlap the two curves to visually compare their performance.
In this video, one of our coaches will show you some lines of code that, when they're added to a trading system, let you export the data of the trades made during the backtest and use it to create and visually compare more equity curves in Excel (and, of course, keep track of all your backtests).
Watch the video now to learn more about this script and how to add it to your strategies and use it to simplify performance evaluation during backtesting!
P.S. Here is the script. It's in PowerLanguage, so for MultiCharts, and it's ready to use!
//Return Type: Numeric
//Function Storage: Series
var: Name(""),MarkP(0);
Name = text ("C:\Users\Utente\OneDrive\Documents\ExportTrades\",symbol,"-",getstrategyname,".txt");
MarkP = marketposition;
if MarkP<>MarkP[1] and MarkP[1]<>0 then print(file(Name),FormatDate("yyyy/MM/dd",DateTime)," at ",FormatTime("HH:mm",DateTime)," : ",positionprofit(1));
if barinterval = 1440 then begin
if TradesToday(d) > 0 then print(file(Name),FormatDate("yyyy/MM/dd",DateTime)," at ",FormatTime("HH:mm",DateTime)," : ",positionprofit(1));
end;
Z_Export_Trades=0;
Hey everyone! One of the coaches of Unger Academy here, and I'd like to welcome you to this brand new video.
When we use trading platforms, I mean the ones that let us backtest our strategies, we can only evaluate one equity line at a time. But is there any practical and straightforward way to manage more equity lines on the same chart so you can compare them more easily?
While you're developing and optimizing your trading system, you open the performance report very often to evaluate the results of the strategy. Of course, you also need to look at the system's equity line, which does nothing but show the cumulation of the trades that took place during the backtest.
The problem is that the trading platforms we generally use, such as MultiCharts or TradeStation, don't feature any tool that lets you make a direct comparison between two equity lines (for example, of two identical strategies or of two systems that differ by just one or two parameters) because you cannot superimpose one equity curve on the other, which would undoubtedly help you better understand the behavior of the strategy in the different cases that you're evaluating.
So what we'd like to do today is share with you a very simple script that, if added to the end of the code of a trading system, will allow you to automate this comparison as much as possible.
So let's go and see how this works. To explain this to you, I'll use one of the strategies we have already built together in a previous video. You can find the link at the top right of the screen.
This strategy is called 'RSI Filter.' It's a pretty good system for Mini S&P 500, and the equity line we've seen in the other video was very similar to this one.
Now let's go and try and go back to the development stage when we were looking for the best parameters to use. Let's focus on the stop loss value and evaluate which values would produce the best results between $1,000 and $1,500 by comparing the results and the equity lines that we would get.
First, let me show you the code of the strategy. Here it is. In this case, I simply added this word, which recalls a function that enables us to export all the trades made by the strategy during the backtest. I used this function for this strategy, but you can use it for any other system that you want to create.
Okay, so what's inside this function? Let's go and check it out together. This function simply creates a text file in our computer, in a folder chosen by us. For example, I saved the file in a dedicated folder called 'Export Trades' in my Documents folder. The platform generates a file, calls it precisely like the symbol to which we are applying our strategy, and recalls the name of the strategy itself.
Then I perform an essential check. I go and check what the market position is throughout the backtest. For each bar, and so each time there is a recalculation, I check the market position and store it into a variable called 'MarkP.' Then I make the comparison.
I check the current value of the market position compared to the value of the market position of one bar ago and, at this point, I also added another condition with the word 'and,' so that both conditions must be verified, and this new condition requires that the market position of the previous bar must be different from zero.
So what does this mean as a whole? This means that one bar ago, we were actively trading because our position was different from zero, and that then our market position has changed, so either we exited a long position to enter a short position or exited a long or short position to be flat.
So if we find ourselves in these conditions, and so if a trade has just been closed, we'll print the file. And here's the 'Print' command followed by 'file.' Then I recall the file's name in which I want to save the data, which is the name written in this line. And then, I use 'FormatDate' and 'FormatTime' to write the date and time when the trade was closed.
Then I write 'positionprofit(1)', which is a keyword that simply indicates the profit or loss of the newly closed position.
Moving forward, I also added these three lines in case I used daily bars. Since it would be a bit more difficult to use these types of conditions in this case, I used a different function called 'TradesToday'.
In any case, I recommend using this function for only intraday timeframes because, if you used daily bars, there could be entries and exits that occur within the same bar, and you know very well that it's definitely not convenient. So that's why I suggest using this function only for intraday timeframes.
Now let's go and see the results of what we just did. After compiling the strategy with the word that recalls the function in the last part, we open Windows Explorer and see if a .txt file was actually generated in the Documents>Export Trades folder.
The file is here, so let's open it. Okay, you can see, here is the list of all our trades, each with time and date values that correspond to the time and date in which each position was closed.
At this point, we can import this table, for example, as it is, in Excel to keep track of all the backtests that we carried out.
These data will allow us to simply recreate the equity line with different inputs and parameters, so we can evaluate the strategy not just by looking at the numbers on the optimization tables, but also by seeing how the equity line changes.
Here is the example I've just mentioned. The red line is the equity line of the system using a stop loss of $1,000, whereas the blue line is the equity of the same strategy but with a stop loss of $1,500.
I hope this video was useful to you!
If you want to learn more about our method for developing automated strategies based on the work of the 4-time world trading champion Andrea Unger, below, in the description of this video, I leave you a link to a completely free webinar that will let you further explore the world of systematic trading.
And also in the description, you'll find the script of the function you can use with PowerLanguage, so in MultiCharts.
Thank so much again for watching and will see you in our next video.
Bye-bye for now!
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 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.