Heat Map for iPad, and Soon iPhone!

Posted in News by tharnett on September 2, 2011

About a month ago we released our first mobile app called Heat Map. It works with the iPad and there will soon be a version available for the iPhone (available in a week or so).  Since its release we have received tremendous feedback and we already have some great enhancements in the works for the app. In fact, the Association Association of Individual Investors gave us “App of the Month” in computerized investing last month. So we are proud to have hit the mark for our first app and hope to continue doing so in the future.

For those who don’t know what a heat map is, a heat map lets you visualize all the stocks of a given category in the order of their percentage returns, with different colors and shadings representing the quality and degree of their performance. So in the blink of an eye you can have an understanding of how the market is performing and which stocks are strong, and which ones are not. The Heat Map app has other map types allowing you to quick sort stocks based on other criteria, so check it out and let us know what you think!

Below are two samples:

 

 

Available in the app store
Heat Map for iPad
http://itunes.apple.com/us/app/heat-map/id446869371?mt=8

Delta Divergence Chart Signals

Posted in Footprint® Chart, User Tips by astoeckley on August 22, 2011

We are often asked about one of our commercial indicators, the Delta Divergence signal. As the markets have been particularly active the last few weeks, it is a good opportunity to see how order flow analysis has worked in this environment.

Delta Divergence is based on a simple concept: If prices move out to new extremes of the session, but order flow moves in the opposite direction, this means actual trading activity favors a reversal.

Because the Delta Divergence signals are specifically seeking tops and bottoms in the market, they are rotational indicators by nature. This means that during strong trending periods, they have a potential for failure. But trends occur much less than half the time, and even during multiple-day directional moves, there are often strong rotational moments within the intraday timeframe.

The last couple of days, the markets have indeed rotated up and down, with strong moves in both directions. This “sideways” motion is the most common form of market activity (though usually the ranges are smaller), and it is an ideal setting for studying the Delta Divergence indicator. Click here for a screenshot of today and Friday’s 24 hour sessions, marked with Buy and Sell signals of the Delta Divergence indicator. As you can see, all five signals over the 2 days were profitable, and despite the volatility, the highs of both days were accurately captured by these signals.

While the Delta Divergence indicator may not on its own dramatically improve your trading, many traders depend on it as an extra source of confidence when making decisions. Not all signals are successful, and it is up to the individual trader to decide how to best implement the Delta Divergence within a trading style.

The Delta Divergence indicator requires the Professional version or higher of MarketDelta.

 

TPO Indicator, or Profile Indicator?

Posted in CBOT Market Profile®, User Tips by astoeckley on June 24, 2011

While Market Profile charts are powerful and popular tools that appeal to many traders, MarketDelta also provides two indicators for viewing profiles on candlestick and Footprint charts. These are the “TPO Indicator” and “Profile Indicator.”

The features of these two indicators at first seem similar, so you may find yourself wondering which to use. For example, with both indicators you can show information for the current day profile, or the previous day profile, or both.

So what is the difference?

The TPO indicator always shows data and profile levels based on 30-minute TPO letter durations. Thus, it closely matches what a true, traditional Market Profile chart shows. If you want to monitor Market Profile levels on your intraday chart, no matter what periodicity your chart is set to, use the TPO indicator. It will show the same value area and POC data as a Market Profile chart, no matter how your chart is organized.

The Profile indicator draws value area and POC levels as well, but it uses the periodicity of the chart to determine the information. This primarily applies to time-based profiles, as opposed to volume-based. The cumulative volume for a price is going to be the same, whether you look at a 5-minute or 1.25 range or 1 minute or 233 tick chart. But the number of bars, and thus the number of times a specific price was charted, will widely vary depending on these periodicities. Thus the time-based profiles in the Profile indicator will not look the same as Market Profile charts unless you are using 30-minute candles or Footprints. Additionally, the Profile indicator offers many other features that are not available in the TPO indicator, such as long-term composites, the ability to split a session into up to three different profiles, and more.

So it really depends on your needs and the type of precision you want to see in your profile results as to which of these two indicators you should use.

Composite Volume Profiles

Posted in CBOT Market Profile®, Footprint® Chart, User Tips by astoeckley on June 6, 2011

One of the most popular features in MarketDelta is the ability to see volume distributions over a long period of time. For example, over the last 2 weeks or 2 years, where were the most-traded prices? Here is a quick tutorial.

Using the Profile indicator, you can see this information easily. However, you must have access to good minute-based historical data, such as from DTN Market Access or IQFeed. If you do not have the price history on file, then you cannot view the composite volume profile.

First, download as much minute data you need for the period you wish to study. In this example, I will look at the composite for the last year for the ES, so I start with a minute download:

Then, I look at any ES multi-pane chart, such as a footprint or candlestick chart, and change its view period to time period I wish to study:

After you are done, look back to the beginning of your chart to make sure it starts at the time that begins your study period.

Finally, add an instance of the Profile indicator. One way to do this is to use the Insert button on your keyboard, then find the Profile indicator in the list.

You will want to structure your Profile settings as follows:

You can also use the “auto peak” option if you want to have the indicator automatically create horizontal reference lines at the high-volume and low-volume nodes in the profile. You can adjust the sensitivity for this setting as well. Both options are near the bottom of this window:

When you are done, depending on your stylistic preferences, you will have a volume composite for the last year, like so:

Operating Systems

Posted in User Tips by rmular on May 6, 2011

Upgrading from Windows XP Home/Professional 32-bit

To upgrade to Windows 7, the first step will be to backup your data. Microsoft requires that the hard drive be reformatted and configured for the Windows 7 Operating System in order to load the new operating system files. We recommend that you backup all of your files to an external hard drive before proceeding with the upgrade.  Microsoft offers a program called “Windows Easy Transfer” which will help remove the complication of manually transferring your files through an automated less intensive process. To download, click here. For MarketDelta users running the Windows XP Operating System, make sure to manually backup the entire Mktdelta folder located in C:Program Files. The Mktdelta folder contains the data_f folder that is responsible for personalized charts, indicators and preferences.  To determine which version of Windows 7  you should install, click this link on Edition Comparisons. Although the 32-bit version of Windows 7 is available, we recommend that you upgrade to the 64-bit version regardless. Commonly asked questions as well as technical references regarding the 64-bit architecture will be discussed further is the remainder of this article. To determine if you PC’s hardware, devices, programs and whether or not your system supports the 64-bit version of Windows 7, run the “Windows 7 Upgrade Advisor”. To download, click here.

For More Information on the Full Step-by-Step Process on Upgrading to Windows 7, click here.

Why choose a 64-bit Operating System?

The main advantages to running a 64-bit Operating System is the ability to address greater than 4 GB of RAM and the ability to process twice the amount of data at a time. Previous versions of 32-bit Windows such as Windows XP 32-bit were only capable of addressing approximately 3.5 GB of memory. Rendering intensive tasks such as video/photo, music and mathematics benefit from 64-bit because the ability to address more than 4 GB of memory and process a larger amount of bits per processing cycle. In general, a PC running a 64-Bit Operating System with 64-bit applications will in general feel much smoother compared to a 32-bit environment. A user will notice that 32-bit applications run smoother on a Windows 7 64-Bit operating system because the PC is able to take advantage of using more than the 4 GB of memory for the other applications running on the system. For example, If your PC has 8 GB of memory and a 32-bit application is using all 4 GB of the memory that the architecture can take advantage of, the remaining 4 GB can be used for the Windows 7 system process including other 64-bit applications that can take advantage of addressing the additional memory.

Will 32-bit programs run on a 64-bit computer?

Yes. Microsoft has included a technology called WOW64, which is a subsystem capable of running 32-bit applications on a 64-bit Operating System. Additionally, users should know that although a 32-bit application can run on a 64-bit Operating System, the program is still limited to the constraints of a 32-bit software environment. A 32-bit application is capable of addressing 4 GB memory total. The 4GB allocation is divided evenly into two parts, with 2GB dedicated for kernel usage, and 2GB for application usage. Each application receives its own 2GB, but all applications have to share the same 2GB kernel space.

Where to buy Windows 7 64-Bit?

A copy of Microsoft Windows can be purchased at any retail store or online. Make sure to buy the OEM version of Windows 7 64-Bit which is simply the Manufacturer version of Windows lacking the retail box and documentation. There is absolutely no difference between the Retail or OEM’s version. Click this link to be transferred to Newegg where an OEM copy of Windows 7 64-Bit can be purchased. The cost is significantly reduced when buying an OEM version of Windows.

Is MarketDelta compatible with a 64-bit Operating System?

Yes! The MarketDelta program is a 32-bit application that has been updated to work seamlessly on a Windows 64-bit Operating System.

“Initial Balance” Strategy: Part 12 – Alternate Methods

Posted in RTL by astoeckley on April 27, 2011

(This is a continuation in our blog series on creating a trading system from start to finish. Want to see more? Click here for our main RTL support page, which links to all the articles in this series and many more tutorials. Questions? Click here for the RTL Community Forum where you can get help on your programming.)

Today, we demonstrate the flexibility of RTL and show an entirely different method you could have used to code this system, yet have the same results. RTL is a basic programming language, and as such it can take any form desired by the programmer. The programmer’s creativity determines the flow of the system’s logic, and different programmers may approach the same task in different ways.

To demonstrate this, we will alter how the system triggers all the exits: the stops, scales and final targets. You may find that today’s methodology is more elegant than the prior methods introduced in this article series. No method is better than the other; they are simply different approaches.

Here is the primary change we will make to the system:

Instead of calculating the exit levels within each exit rule, we will instead determine all our exit points up front at the moment we enter a trade, as part of the entry rules. This will make our separate exit rules very simple and easy to understand. It also lets us adjust the stop levels to breakeven without actually adjusting the stop exit rules. Before, we had a total of 4 stop-loss exit rules. 2 for the long trades and 2 for the short trades. One stop level was the initial stop set at the time of entry. Another stop rule set the breakeven level for when the trade exited at its first profit scale. But now we will effectively combine these two stop levels into one single rule and adjust the stop-loss level on the fly, letting us have fewer rules in our system.

The Main Rule

We are going to introduce 3 additional V# variables. At this point, it is a good idea to define all your user variables in the Main rule of the system as a comment. This makes it easier to troubleshoot your system later, or for other programmers to understand how you coded the system. Our new Main rule shall look like this:

We have not actually made any change to the logic of this Main rule. But we have added numerous comments to the end that serve as a form of documentation for our system. Most notably, we have declared that our subsequent rules will use three new user variables, V#6, V#7 and V#8, and each of these will hold the actual price level of our exit targets.

Delete the prior Breakeven Stop Rules

As mentioned, we will not need the two old breakeven stop rules, so you can delete them now. We will still keep the two other general stop rules we created.

Special Note: Because our new stop rules are going to cover all stop scenarios, you might want to use this method for complex stop scenarios where you have multiple adjustments to stops, such as with trailing stop strategies. This would greatly reduce the number of rules you might need in your system since you won’t have to code multiple stops as individually separate trading rules. This will be more obvious below.

The New Entry Rules

As part of our Entry rules, we will set all the exits in advance, and assign them to our three new user variables:

Short Rule:

SET(V#1,(SESST + (SESST – SESST_LOW))) AND HI >= V#1  AND TIME >930 AND TIME < 1400 AND V#2=0 AND SET(V#6,V#1-V#5) AND SET(V#7,V#1-V#3) AND SET(V#8,V#1+V#4)

Long Rule:

SET(V#1,(SESST_LOW  – (SESST – SESST_LOW))) AND LO <=V#1  AND TIME >930 AND TIME < 1400 AND V#2=0 AND SET(V#6,V#1+V#5) AND SET(V#7,V#1+V#3) AND SET(V#8,V#1-V#4)

The underlined portion represents the new parts of this rule. Note that the math used for each of the three user variable levels is the same math we previously used in our individual exit rules.

The Stop Rules and Final Exit Rules

Since our exit rules no longer need to contain logic for the actual math needed to calculate the price level, we can remove that logic from those rules and make them particularly simple rules. Consider our new Long Stop and Short Stop rules:

Stop rule for long -

Stop rule for Short -

Pretty clear and concise!

The final exit rules are equally as basic:

Long exit -

HI >= V#7

Short exit -

LO <= V#7

Rules don’t get much more basic than this!

Rule Prices

We have another efficiency that is now built-in to this system: except for our entry rules, we no longer need to calculate and assign the Rule Price to V#1 using the SET token because each of these rules already has a user variable calculated for the price level, something that didn’t exist before. So change the Rule Price for these rules to match the user variable of the rule itself, as follows:

You can use the “Modify Rule” button to do this.

The Scale Out Rules

Since we are adjusting stop-loss levels on the fly, our scale out rules need to accomplish two things:

  1. They need to obviously contain the logic to exit at the first profit target, and do so only when we have not taken any exits before (this is already in these rules).
  2. They now need to adjust the stop-loss level for V#8 so our single, combined stop rules will function as expected in all cases

We will use the IF…THEN logic to reset the V#8 variable. Here is the new first-exit rule for a long trade:

The second line in this code should be obvious; like our other exit rules, it is simplified for V#6 but must still include the POS_SIZE token from previously; and the Rule Price is set to V#6.

The first line basically repeats this logic as a condition; IF the condition is true, THEN it resets our stop-loss level, V#8. Note the semicolon at the end of this line; this is required in RTL (and most programming languages) to signify the end of one statement before beginning another.

Here is the short scale-out rule:


That’s it! We now have a new RTL environment for the exact same strategy. Here is all that it accomplished:

  1. It removed 2 rules from the system.
  2. It significantly simplified our exit rules and let nearly all the parameters of the strategy be laid out in just two rules, the two entry rules.
  3. It makes the program more flexible should you choose to move stops around even further; no new stop rules will be necessary.
  4. It documents the user variables in the Main rule.

Finally, press the Backtest button, and………..

Same exact backtesting results as in Part 10 of this series, which uses different RTL for most of the rules.

In Conclusion

This blog series has demonstrated the power of RTL and introduced a wide range of techniques for many different scenarios. We hope you have enjoyed it and will continue to experiment with RTL for your own ideas now that its possibilities are made obvious. Your strategy may be entirely different than the IB Rotational Strategy discussed in this series, but the programming concepts and techniques are the same.

“Initial Balance” Rotation Strategy: Part 11 – Realization

Posted in RTL by astoeckley on April 20, 2011

(This is a continuation in our blog series on creating a trading system from start to finish. Want to see more? Click here for our main RTL support page, which links to all the articles in this series and many more tutorials. Questions? Click here for the RTL Community Forum where you can get help on your programming.)

Realization is a simulation of real trading. It is not just backtesting, it is the actual trading process re-enacted for the most accurate picture of a strategy’s past results.

We now have a trading system based on the Market Profile’s Initial Balance range that has backtested well in many different scenarios. Our current incarnation allows for two exits to our trade, so we can “scale out” and move our stop-loss levels to break-even (the entry price) after the first profit is taken.

In our last article, we performed the backtest for the same 250-day period as in all other tests and, after $5 round-turn commissions, found a net profit of $3,970 for 2 contracts when using a 2-point stop, 5-point total profit, and a 2-point scale-out.

Using optimization, we can see that we would have increased profit substantially if we instead went for 15 point profits, a 9-point stop and a first scale of 4 points.

Here’s the problem

It is fun to know today what would have worked in the past. But last year, if we had started trading this system, we would not have had the luxury of optimizing it from price action that would occur in the future. We only know what has already happened, not what we would have done with knowledge we didn’t yet have. Just because we know now that the prior year worked well with 15 point profit targets, does not mean that we would have actually used this in our strategy at that time — because we didn’t know that this was going to be optimal in the months that followed.

It is for this reason that optimization cannot show you potential profits for the future, even if it can help you structure a strategy and give you ideas.

Realization

However, MarketDelta does offer a featured called “Realization” that accurately captures the real results you would have enjoyed in the past, if you optimized, traded off that optimization, then optimized again later, and continued to adjust your strategy based on recent market conditions. In this way, you can see the effects of optimization on real-time performance.

Realization works as follows… You set an “Optimization period” — this is the amount of time to include in each optimization. Then you set a “Realization period” — this is how often you optimize based on prior data and alter your strategy based on the results of that optimization.

MarketDelta runs an optimization, then performs a simple backtest using these optimization results for the period following the optimization. Then at the end of that period (the realization period), it runs another optimization and uses those results for the next backtest. This process continues until all the data is tested.

It effectively captures how you might have traded a system and only uses optimization results for past data when calculating the actual backtests on future data.

To set it up, just press the Realize button in the Optimization window.

Make your settings, then press Realize. For these settings, we get these results:

This is a real result that could have occurred without knowing the prices of the future. Still profitable, but the reality is obvious: not as profitable as a straight-up optimization for the entire period. If your system can perform well in the Realization phase, you have many reasons to be more confident.

If we alter our realization for different trading behavior, we would alter our profits over the 250-day period:

These settings include more data in each optimization along the way, and then re-optimize every 30 days. If you traded this system, you would not change your profit targets and stops as often, and these levels would be based on more price history. Here are the results for this realization:

Somewhat comparable.

Now let’s try a test for more aggressive changes over time to the strategy. Suppose we optimize every 10 days based on the most recent 10 days, and then use those results in trading for the following 10 days, before repeating this procedure:

Keep in mind that your strategy is likely to change much more dramatically every 10 days since it is using optimal results from a short testing period for each change.

Here are the results:

Here are our best Realization results yet; so, at least for this strategy, frequent optimization and strategy changes proved profitable over the long term.

This would not necessarily be the case with other strategies.

“Initial Balance” Rotation Strategy: Part 10 – Scale-outs

Posted in RTL by astoeckley on April 6, 2011

(This is a continuation in our blog series on creating a trading system from start to finish. Want to see more? Click here for our main RTL support page, which links to all the articles in this series and many more tutorials. Questions? Click here for the RTL Community Forum where you can get help on your programming.)

So far in this series, we have built a trading system based on an all-in, all-out trading style. That is, we enter all at once, and then exit the position all at once. However, many traders use a “scale-out” method whereby you gradually liquidate a position as it becomes more and more profitable. This allows you to lock in small partial profits and hold on for larger profits all in a single trade. Of course, it requires that you trade more than a single contract so you have “bullets in the gun,” so to speak, as the market moves more and more in your favor.

Today we will add to our existing system by creating rules and changing signals so we can take advantage of this method. Our system is already built to buy and sell 2 contracts. We will add one scale-out so each contract exits at a different time.

Another important benefit: After the first scale-out, most traders move their stop-loss to a break-even level (the original entry) so that losses are not possible on the trade once the first profit is locked in.

We shall create the rules that add these new scale-outs for long and short trades, and additional break-even stop-loss rules for each, for a total of 4 new rules.

Here are the steps to pull this off:

1. Change all existing rules, except for the entry rules, to a rule quantity of “All.” Since we have either partial or full positions now, this is the easiest way to make sure that, for example, the final (second) scale out isn’t set to liquidate 2 contracts when only 1 contract remains. We will keep the current exit rules as our second scale-out rules. To modify each of the affected rules, click on it in the Trading Rules list, change the quantity in the upper right, then click the Modify Rule button.

2. Change the Main rule to accommodate a new user variable should you choose to optimize this system, as per our last article in this series. In this example, I’m assigning V#5 to the profit target for the first scale-out (V#3 is already set as the main profit target, for our second scale-out):

Here I am keeping 5 points as the main profit target, and using 2 points as the first scale-out, with a 2-point stop-loss.

3.  Create the two new scale-out rules: one for long trades, one for short trades. The easiest way to do this is to open the existing SELL rule (for exiting a long) and immediately use the Save As button to save as a variation, such as SELL_SCALE. Then we use the POS_SIZE token (“position size”) as part of the signal, so this rule only triggers when you are carrying the full position. This allows the system to trade past this level after a scale-out and return to this level without exiting again before the second scale is reached. Change the user variable to V#5 instead of the V#3 in the second scale signal. The POS_SIZE token is always the value of your current trade size. It is 2 when you are long 2 contracts, zero when you are flat, and -2 if you are short two contracts. Here our our two new scale-out rules:

When you create rules from these new signals, use a rule quantity of 1 since you are only exiting part of the position.

4. Create two new stop-loss rules, where the stop loss is set to the ENTRY with a rule quantity of ALL. Also, use a POS_SIZE of 1 or -1 (depending on long or short trade) so the stop loss only triggers after the first scale out is completed:

Our 13 trading rules for this system after making these changes:

Last time we tested this all-in, all-out strategy using 5-points profits or 2-point losses (or end-of-day exit). The result from that backtest was a 250-day profit of $2420. Adding these new scale-out rules, we see a significant increase in net profit as losses are trimmed and profits locked in:

It’s worth noting, however, that the system is still not as profitable as it was prior to introducing stop-loss rules at all, as we noted in Part 7.

Anticipation or Prediction?

Posted in User Tips by tharnett on March 22, 2011

It may seem like semantics, but I invite you to consider the not so subtle differences between the two words in the title. Prediction is about a belief that something WILL happen. Anticipation is being READY for what might possibly happen and having a plan for what to do. This shift in attitude can be difficult to accept because prediction doesn’t require much work, while anticipation does.

Traders should be very familiar with these terms. Each day we are faced with many opportunities, but they are only opportunities if we are prepared for them. Simply trying to predict the outcome once price arrives at a particular level is meaningless. The Footprint chart provides way to anticipate when a market may pause or reverse based on some simple patterns that only the Footprint can show. This helps anticipate market moves because it is focuses not on price alone, but on volume and order flow which drive and support price moves. It is this interplay between price, volume, and order flow which the Footprint visualizes so well.

Two helpful resources for learning more are the FAQ showing some “Meaningful Footprint Patterns” and our PDF Guide to Reading the Footprint Chart.

“Initial Balance” Rotation Strategy: Part 9 – Optimization

Posted in RTL by astoeckley on March 18, 2011

(This is a continuation in our blog series on creating a trading system from start to finish. Want to see more? Click here for our main RTL support page, which links to all the articles in this series and many more tutorials. Questions? Click here for the RTL Community Forum where you can get help on your programming.)

What is truly the best profit target to wait for?

  • Do you get out after 3 points of profit or hold on for 6?

What is the best stop-loss level to maximize long-term profits?

  • Should you exit after a 2-point loss or give your strategy much more breathing room?

These are the type of questions that Optimization can answer.

Whereas “Backtesting” is taking a strategy and testing it against historical data, “Optimization” is tweaking a strategy against historical data to see how you could have increased profits, minimized losses and changed nearly any quantifiable aspect of the strategy itself to make it as successful as possible… in the past.

An optimization is basically a large set of multiple similar backtests. The software plugs in values for any variable you wish, such as the profit target, the stop-loss level, or other components of the strategy, and runs a backtest. When that test completes, it runs it again with slightly different values for these variables. It can run this hundreds or even thousands of times, called iterations, and then it reports on which combination of values offered the best rewards.

Today we will show you how to take our existing Initial Balance Rotational Strategy and optimize it to find the best profit targets and stop-loss values for an all-in, all-out trading style with this strategy.

Note: It is important to understand that optimization is, by definition, curve-fitting. It alters a strategy based on what would have worked in the past. This does not at all necessarily mean that the most ideal settings for previous periods in time will also be the most ideal settings for the present or future. But the entire goal behind backtesting and optimization is to develop ideas, and for that this can be useful information.

We currently have 9 rules in our system:

  1. The Main Rule limits the strategy to 1 trade per day
  2. The Long entry rule buys at the 2xIB Low
  3. The Short entry rule shorts at the 2xIB High
  4. The Long exit rule; after a specific target is met
  5. The Long stop-loss rule; after a maximum loss occurs
  6. The Short exit rule
  7. The Short stop-loss rule
  8. End-of-day exit for Long positions, if profit and stop targets are not met
  9. End-of-day exit for Short positions

We will not add any more rules to this system today. Instead, we will tweak these rules to make them ripe for optimization.

We want to optimize for the best profit target and stop-loss parameters. Currently, these numbers are hard-coded into the rules. For example, the Long exit rule is:

HI >= ENTRY+5 AND SET(V#1,ENTRY+5)

This means that the system exits the trade when prices reach our Entry price plus 5 points; thus, we get out at a 5-point profit.

The Long stop-loss rule is:

LO <= ENTRY-2 AND SET(V#1,ENTRY-2)

If we are long and the price drops 2 points below our entry, we exit. This is also hard-coded into the RTL itself.

The Short rules are just mirror images of these two Long rules.

The first step is to remove these hard-coded values and replace them with user variables. This will allow the optimization engine to substitute different values for these levels as it process multiple iterations.

In every instance where you see a specific value that you wish to optimize, change it to a corresponding V# number. For example, profit targets could be V#1 and stop loss amounts could be V#2. You do not want to use V# numbers you already use elsewhere in the system, such as V#1 which is used for the actual entry rule and V#2 which is used in the logic to limit the trades to once per day, or use any V# numbers that you use in your charts or elsewhere in the program.

We will use V#3 for our profit targets and V#4 for stop-loss values.

The Long exit rule will now be:

HI >= ENTRY+V#3 AND SET(V#1,ENTRY+V#3)

And the Long stop-loss rule is:

LO <= ENTRY-V#4 AND SET(V#1,ENTRY-V#4)

The Short rules are also similar.

Be sure to press Save on each RTL window after you edit the code.

If you were to run this Backtest with these modified rules, you would not get meaningful results because the Backtest itself would have no values to insert for these variables. The Optimization engine will insert values, but not a regular Backtest. So we must add new RTL for the “Main” rule that sets these variables for a regular backtest.

Our Main rule currently says:

IF (POS=1) THEN (SET(V#2,0));
IF (POS_SIZE != 0) THEN (SET(V#2,1));

We will add one line to this:

IF (POS=1) THEN (SET(V#2,0));
IF (POS_SIZE != 0) THEN (SET(V#2,1));
IF (CTX != CTX_OPTI) THEN (SET(V#3,5) AND SET(V#4,2));

This line uses the RTL Token “CTX” which means “System Context.” We know from last time that “!=” means “not equal.”

In plain English, this RTL statement means,

“If the system context is not optimization, then set V#3 to 5 and set V#4 to 2.”

This means that if we run a backtest, which is not an optimization, it will plug these values into these user variables so we have the same results as we did before when these values were hard-coded into the rules themselves.

It is possible for this statement to contain many many V# variables if you are optimizing many different parts of a strategy. Thus, you may find it useful to add notes in this Main rule that identify which variables stand for which values. You could add this:

IF (POS=1) THEN (SET(V#2,0));
IF (POS_SIZE != 0) THEN (SET(V#2,1));
IF (CTX != CTX_OPTI) THEN (SET(V#3,5) AND SET(V#4,2)); /* V#3=profit, V#4=stop-loss */

In RTL, you can start a comment line with /* and end it with the mirror of this, */ — everything between these two symbols is entirely ignored by the program and can be in any format you wish.

Save the rule, then save the system itself, by pressing Save at the top of the Trading System window.

If you press “Backtest” now, you should see the exact same identical results as we had before we made all these changes. But now the system is ready for Optimization.

Before you run any optimization or backtest, make sure you have enough historical data on file to cover the settings in the “Setup Backtest” area. If you do not, you must download data before running either a backtest or optimization. You will generally have better luck getting many years of data if your system uses minute history rather than tick history.

Press the Optimize button on this window, and you will see the Optimization screen. In this new window, you specify the variables you want to optimize. In this case, they are V#3 and V#4. Then you set the testing range for each variable, and the increments to test within this range. So we might test all combinations of profit targets and stop-losses from 1 to 10 points, in 1-point increments. As you make these changes you will see the total number of iterations building at the top of the screen. You can then adjust what type of information will appear in your optimization report and, most importantly, how you want to prioritize the sorting of these different tested combinations. For most people, sorting by either “Net Profit” or “Average Profit Per Share” will be the most useful. Note that the Net Profit option includes the commission fees set in the backtesting settings themselves, as described in an earlier part of this series.


(Click image for a better view.)

When ready, press Optimize.

The time it takes for the optimization to complete depends on these factors:

  1. How many days of data you are testing. This is set in the backtesting setup.
  2. The periodicity you are testing, as this affects the number of actual bars the system will study. A 1-minute periodicity, as set in the system screen, will take much longer than a 10-minute periodicity.
  3. The number of iterations; this is based on the total number of V# variables you are testing and the number of data values in each V#. Increasing your increment (step) amount will reduce the number of iterations, but give you less comprehensive data for the test.

Complex backtests over many years of data with small periodicities and large iterations in the thousands can take hours to run.

As the test runs, it alerts you to its progress and how much time is remaining, as well as other information:

Our results are below:

Last week, we noted that adding a 2-point stop-loss cut our 5-point profit target backtest’s net profit in half, from approximately $5,000 to around $2,500. Today we see that a wider stop of 9 points and a profit target of 3 points has provided the best results so far, nearly $7,000. However, it is worth noting that other combinations below it in the list, such as 6 point stops with 4 point profits, also perform well, so there is a good mix here of different targets and stop-loss values to accommodate different trading styles.

You could then take these values for V#3 and V#4 and use them in the Main rule instead of the previous values of 5 and 2. If you ran a regular backtest after doing this, you should see the same results as this optimization report shows, but then you could study the individual trades as well.

If you modify any rules in your system and wish to re-run the optimization, remember to always Save the system first.