“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.

“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.

“Initial Balance” Rotation Strategy: Part 8 – Stop Loss

Posted in RTL by astoeckley on March 9, 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.)

Our trading system currently has 7 rules:

  • 2 entry rules; one for long, one for short
  • 2 profit target rules, for each long or short
  • 2 end-of-day exits, for each long or short
  • 1 “Main” rule that currently limits the number of trades per day to just 1

You can see all seven rules in our Trading Rules list for this system, which we have already setup:


Once a system enters a trade, long or short, it ignores all other entry rules (except in the case of multiple entries, which are a special case that we will discuss soon). The system only considers the exit rules once a position is active. If a profit target rule is met, the system exits at that price, for a profit. If this target is never met, then our system waits until the end of the day and exits then.

Most traders add additional exit criteria to their trading, “stop losses,” which limit the amount that a position can move against them before exiting and accepting a loss.

Considerations

It is important to understand the reality of this type of exit rule. While it may seem to positively benefit a trading system, by reducing the size of your losses, it can also whipsaw you out of potentially winning trades. For example, a trade might move against you by 3 points before reversing and leading you to profit. If, however, your stop loss takes you out at a 2-point loss, this trade is a loser instead of a winner.

On the flip side, a trade that moves against you by several points could have been a much larger loser without a stop loss.

There is a very delicate balance that traders must carefully consider when choosing stops that work for them.

Today, we will build the stop loss rules into our system. During our optimization phase, which is our next article in this series, we will analyze what are truly the best profit and stop loss levels for our strategy.

The Rules

An exit for a specific loss amount is not unlike an exit for a specific profit amount.

You can either create new signals from scratch, or just open the existing profit target rules and Save As with basic modifications.

For example, we previously built this rule for exiting a long at a 5-point profit:

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

We set V#1 as the Rule Price so we got out right at that price, even if it was intrabar.

Here is the code for a similar long stop-loss rule:

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

This provides a 2-point stop level. The stop loss for a short position would be:

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

When you add the stop signals to the rule list, you may want to use a quantity of “All”. This way, if you later create multiple exits, entries, etc, the stop will always exit whatever position you have, regardless of its amount:

Very Important: As always, the order of the rules in your trading system is crucial to its behavior and backtest results. Remember, the rules are evaluated from the top rule to the last rule for each bar on the chart. If you place your new stop loss rules after the entry rules, it is conceivable that you could enter and get stopped out all on the same bar. If instead your entry rules are the last rules in your list, then your exits, whatever they may be – targets, stops or end-of-day – will always be on at least the bar following your entry.

Backtest Results

Here is a sample trade that shows the stop working:

If you do a lot of backtesting, you will see that stops very often reduce long-term profitability. Here is same 250-day backtest we’ve performed before, using 2-point stops we’ve created here:

This is about half the profit we had before adding stop loss rules for 2 points.

If you want to test the strategy by removing the stops, one way to do so without erasing all your RTL code we’ve created is to simply change the stop to something particularly large, like 50 points. Since it will usually never get triggered, you can compare a more meaningful stop to results without stops, but still keep the stop rules in place.

Avoiding Re-Entry after a Stop Exit

While I won’t go into all the different programming possibilities for different scenarios, here are some issues to consider as you code stop rules.

If you get stopped out, the conditions for an entry may still exit. If you do not limit your trades, as described in our last article, our current backtest system will immediately get you back into a trade, because the entry rules we created simply require that the low has reached or extended beyond the 2X IB level. Thus, when the stop is triggered, the entry rule is still valid and the system gets you back in.

As a more advanced technique, you could allow for multiple entries except when a stop order is triggered. You could add an IF/THEN statement to the stop loss rule that sets a V# to a number, similar to what we did last week, and then use this V# as the condition to limit new entries. It would be similar to the code used in the Main rule last week, but placed inside the stop rules instead of a Main rule, using the condition of the stop rule as the IF condition.

Alternately, and without an IF/THEN statement, you could instead change the entry rules to only enter when prices are, for example, within a 1-point range extending beyond the 2XIB. Currently our entry rules are not this specific. This way, if the stop rule was beyond this range, it would not re-enter immediately after the stop exit, but it could re-enter if prices came back to the 2XIB.

There are  many different ways to code a system like this, and it is open to individual creativity and requirements.

“Initial Balance” Rotation Strategy: Part 7 – Trade Frequency

Posted in RTL by astoeckley on March 2, 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.)

When you consider the system we have built thus far, it is apparent that once a position exits for a profit target, the system may still enter the same trade again on the same day, as we have not created any RTL code that would suggest otherwise. Just because you get your profit does not mean the market will not return to your entry level. Currently, the system enters the trade again. Many traders may not wish to enter the trade again, although in some cases it might actually be effective in overall backtests. You may wish to test both scenarios.

Consider this trade, created from the backtest. Here I have changed the profit to just 1 point to make it easier to identify:

So, how to limit the system from only taking one trade per day?

Backtests often require rules that do not actually take actions, but instead set a framework for managing the system. This will be an important part of optimization, which is the subject of a future article.

We can create a rule at the beginning of our trading rules list that is processed at the beginning of every bar, before any other rules are studied. This introduces some new RTL techniques and tokens:

  1. POS_SIZE – This token is a variable that equals your current position quantity. It is positive if you are long and negative if you are short. If no position is active, it equals zero.
  2. IF/THEN – This is a standard technique in nearly all programming languages, and is called a condition. It lets you run an algorithm or process only if specific criteria are met.

Here is our “Main” Rule:

Note that a semicolon is required to separate multiple lines inside a single trading rule.

The symbol “!=” means “not equal.”

Now, we have to alter our entry rules to consider the current value of V#2 before taking the trade:

All you have to do is add “AND V#2=0″ to the end of each entry rule so it will not execute unless no other trade has occurred during the day, as per our Main Rule.

Here is our long rule now:

SET(V#1,(SESST_LOW  – (SESST – SESST_LOW))) AND LO <=V#1  AND TIME >1030 AND TIME < 1500 AND V#2=0

Once you make these changes to the long and short entries, and add the Main Rule, you’ll see that the same chart signal shown above now looks like this:

If you run a backtest for the same 250-day period using this tweak of limiting the trade once per day, you will see that we have further improved our net profits over this time, by limiting trades to once per day, and taking a 5-point profit target or end-of-day exit:

As we will discover next time, you need to consider these limits in strategies that incorporate a stop loss; after all, you don’t want to get in immediately after you are stopped out!

We will discuss stop loss rules in the next article.

Auction Market Theory Chart – RTL Discussion

Posted in RTL by astoeckley on February 23, 2011

A few weeks ago, we unveiled an exciting chart that helps anyone understand the auction process during the trading session. We’ve been pleased with all the great feedback on this chart and are happy that many users are making it one of their main charts. Click here to see that chart and download a definition. The chart is free for anyone to use, provided you subscribe to a Professional version of MarketDelta, which makes these RTL indicators viewable. You do not need to understand RTL yourself to use this chart.

We’ve had some requests to explain how the RTL was crafted to make this chart possible. As promised in our previous article for this chart, today I summarize the code that creates these signals.

This article is best for those already familiar with the RTL interface. I provide here a basic overview of these signals. You can look at the chart’s signals yourself to best understand the whole architecture and the details. If you are brand new to RTL and want to know the basics of creating signals and indicators, please see our RTL Support page, which includes links to many tutorials for RTL.

Included Indicators and Signals

If you double-click the chart, you will see a list of all the elements in this chart, including the RTL indicators and signals:

The 8 signals starting with “amt_” are those that indicate the “Responsive Buying,” “Initiative Selling,” etc. There are 8 of these because the chart is basically divided into 4 quadrants, and each quadrant can have 2 signal possibilities: buying or selling. The 4 quadrants are the areas above and below the previous day value area, and the same areas for the current day value area.

Additionally, there are two signals starting with “once_” that indicate the range extension that may occur during the day: either range extension up or range extension down.

The final three signals, two for “sessionstart” and one called “time_devstudy” simply look at the time of day and use this to plot relevant information on the screen. These create the chart notations “Session Start,” “Studying Previous Day Value Area” and “Studying Developing Value.”

The chart also contains a hidden pane, which has a simple, single custom indicator:

Finally, while not referenced in this element list, because it is not added directly to the chart, there is a custom signal, “time1100,”  included in some of the other signals:

Key Technique: This signal and others that provide once-per-session annotations use the same principle mentioned in this article from our Initial Balance blog series for limiting the frequency of signals.

The Basics

This “time1100″ signal simply consists of this:

After the market is open 90 minutes, it signals, and in this case, the signal marker creates the notation “Studying Developing Value” :

(The included indicator was originally named time1100 since in the Eastern Time Zone, 90 minutes after session start is 11 a.m.)

The “sessionstart” indicators use a different setting for the POS token which is only true once, and thus does not require signal limiting like the “time_devstudy”:

The hidden custom indicator, “BarDeltaCI,” has the following simple code:

This code is necessary for the “amt_” signal markers to include the net buying and selling activity as a reported number next to the signals’ text annotations. The VPS token here is simply set to find the net delta of the entire bar. You could also use the VB token instead.

Because signal markers can annotate the results of custom indicators only, and not standard indicators, this custom indicator is hidden and pulled into the “amt_” signals:

This is what allows us to see the numerical results in the signal itself:

The signals that determine if there is range extension look like this:

After the first hour, if the low of a bar drops below the lowest low of the first hour, we have negative range extension, and the signal marker for this signal notates this:

The positive range extension would be the flip side of this but basically the same code.

The Auction Market Theory Signals

The heart of the chart, of course, are the signals for auction activity. The code is similar for all these signals, but varies with respect to studying the previous day value area or the current day developing value. Here is the RTL for the morning session responsive selling above previous day value area:

The “tpo” token differentiates between VA High and Current VA High, which breaks the chart into the four quadrants mentioned earlier.

In plain English, this algorithm simply says:

If the price moves above the prior day’s value area high by 2 ticks or more, and the net delta (VB) is negative and it is during the first 90 minutes of the session, then create the signal.

This same formula is the same for all 7 other similar signals, just the specifics vary with respect to time of day, positive or negative VB and current or previous value area.

The signal marker then determines what to show on the chart when this happens, and this is where we pull in the custom indicator and flash the text annotation:

Finally, the presentation of the chart itself, with the Footprint data in front of a candle, is nothing more than a basic “overlay” chart. Click here for our introduction to overlay charts.

This should open your eyes to the relatively straightforward method of creating complex RTL setups. Usually, the individual signals are quite simple; it’s the combination of many separate simple elements that allow for creating a powerful interface.

BEGIN MarketDelta TRADING SIGNAL DEFINITION for time1100
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=time1100
BARCOUNT=AUTOMATIC
ELEM=TIME: Bar Time - hhmm.ss
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=POS > 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for time1100
BEGIN MarketDelta TRADING SIGNAL DEFINITION for time_devstudy
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=time_devstudy
BARCOUNT=AUTOMATIC
ELEM=signal_time:Scan/Signal:SIGNAL[ ] time1100,0 PREFS: 168,168,255,1,0,0,time1100,0,5,0,F,106660760,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,F,,F,F,F,2,895895,3,T,0,F,,1,F,T,
ELEM=SSTAT:Signal Statistics:SSTAT[ ] 20,time1100 PREFS: 0,0,255,1,0,0,time1100,0,9,F,F,3,255,0,0,1,0,0,106662816,20,0.000000,T,620620,2,1,
SIGNAL=signal_time=1 and SSTAT=1
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for time_devstudy
BEGIN MarketDelta TRADING SIGNAL DEFINITION for sessionstart
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=sessionstart
BARCOUNT=AUTOMATIC
ELEM=POS:Position Indicator:POS[ ] Result 1 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,1,6,744744,10,
SIGNAL=POS=1
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for sessionstart
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_respsellVAPrev
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_respsellVAPrev
BARCOUNT=AUTOMATIC
ELEM=HI:High
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=tpo_devhi:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,3,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=HI > (tpo_devhi+2*TINC) and VB <  0 and POS < 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_respsellVAPrev
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_respbuyVAPrev
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_respbuyVAPrev
BARCOUNT=AUTOMATIC
ELEM=LO:Low
ELEM=tpo_devlow:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,4,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=LO < (tpo_devlow-2*TINC) AND VB >  0 AND POS <= 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_respbuyVAPrev
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_initsellVAPrev
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_initsellVAPrev
BARCOUNT=AUTOMATIC
ELEM=LO:Low
ELEM=tpo_devlow:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,4,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=LO < (tpo_devlow-2*TINC) AND VB <  0 AND POS <=90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_initsellVAPrev
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_initbuyVAprev
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_initbuyVAprev
BARCOUNT=AUTOMATIC
ELEM=HI:High
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=tpo_devhi:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,3,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=HI > (tpo_devhi+2*TINC) AND VB >  0 AND POS <= 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_initbuyVAprev
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_initsellVA
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_initsellVA
BARCOUNT=AUTOMATIC
ELEM=LO:Low
ELEM=tpo_devlow:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,1,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=LO < (tpo_devlow-2*TINC) AND VB <  0 AND POS > 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_initsellVA
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_respbuyVA
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_respbuyVA
BARCOUNT=AUTOMATIC
ELEM=LO:Low
ELEM=tpo_devlow:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,1,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=LO < (tpo_devlow-2*TINC) AND VB >  0 AND POS > 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_respbuyVA
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_respsellVA
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_respsellVA
BARCOUNT=AUTOMATIC
ELEM=HI:High
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=tpo_devhi:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,0,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=HI > (tpo_devhi+2*TINC) and VB <  0 and POS > 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_respsellVA
BEGIN MarketDelta TRADING SIGNAL DEFINITION for amt_initbuyVA
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=amt_initbuyVA
BARCOUNT=AUTOMATIC
ELEM=HI:High
ELEM=VB:Volume Breakdown:VB[ ] PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,0,0,5,10,10001000,F,F,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0,,,32767,0,0,
ELEM=TIME: Bar Time - hhmm.ss
ELEM=tpo_devhi:TPO Indicator:TPO[ ] PREFS: 0,0,0,0,0,0,157,157,255,2,2,0,176,176,255,1,2,1,255,174,174,2,2,0,255,204,204,1,2,1,0.250000,0,10011001,T,T,30,0,70.000000,F,F,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
ELEM=TINC:Tick Increment
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=HI > (tpo_devhi+2*TINC) AND VB >  0 AND POS > 90
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for amt_initbuyVA
BEGIN MarketDelta TRADING SIGNAL DEFINITION for extensionDown
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=extensionDown
BARCOUNT=AUTOMATIC
ELEM=TIME: Bar Time - hhmm.ss
ELEM=LO:Low
ELEM=SESST:Session Statistics Indicator:SESST[ ] Stat 1 PREFS: 255,0,0,1,2,0,0,128,0,1,0,0,1,4,60,6,10011001,0,1,0,5,F,F,1020,
ELEM=POS:Position Indicator:POS[ ] Result 5 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,5,6,744744,10,
SIGNAL=POS > 60 and LO < SESST
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for extensionDown
BEGIN MarketDelta TRADING SIGNAL DEFINITION for once_extensionDown
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=once_extensionDown
BARCOUNT=AUTOMATIC
ELEM=signal_extensionDown:Scan/Signal:SIGNAL[ ] extensionDown,0 PREFS: 0,0,0,0,0,0,extensionDown,0,0,0,F,106687488,0,0,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,F,,F,F,F,2,895895,0,F,0,F,,1,F,T,
ELEM=SSTAT:Signal Statistics:SSTAT[ ] 20,extensionDown PREFS: 0,0,255,1,0,0,extensionDown,0,9,F,F,3,255,0,0,1,0,0,106689544,20,0.000000,T,620620,2,1,
SIGNAL=signal_extensionDown = 1 and SSTAT = 1
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for once_extensionDown
BEGIN MarketDelta TRADING SIGNAL DEFINITION for extensionUp
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=extensionUp
BARCOUNT=AUTOMATIC
ELEM=TIME: Bar Time - hhmm.ss
ELEM=HI:High
ELEM=SESST:Session Statistics Indicator:SESST[ ] Stat 0 PREFS: 255,0,0,1,2,0,0,128,0,1,0,0,0,3,60,6,10011001,0,1,0,5,F,F,1020,
ELEM=POS:Position Indicator:POS[ ] Result 7 PREFS: 0,255,0,1,0,0,255,0,0,1,0,0,7,6,744744,10,
SIGNAL=POS > 60 and HI > SESST
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for extensionUp
BEGIN MarketDelta TRADING SIGNAL DEFINITION for once_extensionUp
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=once_extensionUp
BARCOUNT=AUTOMATIC
ELEM=signal_extensionUp:Scan/Signal:SIGNAL[ ] extensionUp,0 PREFS: 0,0,0,0,0,0,extensionUp,0,0,0,F,106693656,0,0,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,F,,F,F,F,2,895895,0,F,0,F,,1,F,T,
ELEM=SSTAT:Signal Statistics:SSTAT[ ] 20,extensionUp PREFS: 0,0,255,1,0,0,extensionUp,0,9,F,F,3,255,0,0,1,0,0,106695712,20,0.000000,T,620620,2,1,
SIGNAL=signal_extensionUp and SSTAT=1
- Comments
END MarketDelta TRADING SIGNAL DEFINITION for once_extensionUp
BEGIN MarketDelta CUSTOM INDICATOR DEFINITION for Bar_deltaCI
COMMENT=NONE
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9
DATAFEED=TransAct
NAME=Bar_deltaCI
BARCOUNT=AUTOMATIC
ELEM=VPS:Volume Price Statistics:VPS[ ] VUP PREFS: 0,0,255,1,0,0,0,0,255,1,0,0,6,15,921921,100,2,
INDICATOR=VPS
- Comments
END MarketDelta CUSTOM INDICATOR DEFINITION for Bar_deltaCI
BEGIN MarketDelta CHART DEFINITION for amt
COMMENT=Auction Market Theory Order Flow Analysis
SOURCE=DeBuG
PLATFORM=Windows 7 (6.1, Build 1DB0)
DATE=01/27/2011 14:19
VERSION=10.3.9 (Build #32815 Jan 25 2011 14:53:44)
DATAFEED=TransAct + DTNMA
NAME=amt SIZE=655,934
PERIODICITY=4,12500 (1.25 Range)
PIXELS=121:0
LOOKAHEAD=0
RMARGIN=0
CFLAGS=262144 CFLAGS2=154113
VIEWPERIOD=1,1,3,3378792600,3378982690 (Last 3 days)
COLORS=0,16777215,0,15724527,15263976,0,16777215,0
DESC=amt: ESH1 (1.25r), ESH1 (1.25r) 1.25 Range, Session 2
SESSION OVERRIDE=2 Index Options: Hours: 09:30 to 16:15
TICKER=ESH1:CME:31 SECTYPE=3 DISPLAY=12 ALIAS=@ES#
TICKER=ESH1:CME:31 SECTYPE=3 DISPLAY=12 ALIAS=@ES#
PANE #1 PCT=0.298906 PFLAGS=272 SCALE=1,-4800.000000,4500.000000,0.000000,0.000000,0.000000,0,0
PANE #2 PCT=0.998785 PFLAGS=33944 SCALE=65,1290.403583,1299.197701,0.250000,1.000000,17.000000,0,8
PRESET: TPO_1 ,#145 DESC: TPO[ ] LABEL: F RECALC: 1,1 PREFS: 0,0,0,0,0,0,192,192,192,2,2,0,0,0,0,3,2,0,192,192,192,2,2,0,255,255,255,1,2,1,0.250000,0,10011001,T,T,30,0,70.000000,F,T,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
INDICATOR: BUTN #94 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: BUTN: TPO_1  LABEL: F RECALC: 0,0 PREFS: 4,0,0,101951440,600600,,145,TPO_1 ,0,0,,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] time_devstudy,0 LABEL: F RECALC: 0,0 PREFS: 0,0,255,1,0,0,time_devstudy,0,5,3,F,106658704,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,Studying Developing Value (DVA),F,F,F,2,895895,3,F,60,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] sessionstart,0 LABEL: F RECALC: 0,0 PREFS: 0,0,255,1,0,0,sessionstart,0,5,3,F,106664872,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,Studying Previous Day Value Area (VA),F,T,T,1,895895,3,F,60,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] sessionstart,0 LABEL: F RECALC: 0,0 PREFS: 64,0,0,1,0,0,sessionstart,0,5,3,F,106666928,0,24,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,SESSION START,F,F,F,2,895895,3,F,30,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_respsellVAPrev,0 LABEL: F RECALC: 0,0 PREFS: 198,99,0,1,0,0,amt_respsellVAPrev,0,5,1,F,106668984,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,VA: Responsive Sells,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_respbuyVAPrev,0 LABEL: F RECALC: 0,0 PREFS: 0,128,0,1,0,0,amt_respbuyVAPrev,0,5,0,F,106671040,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,VA: Responsive Buys,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_initsellVAPrev,0 LABEL: F RECALC: 0,0 PREFS: 206,103,0,1,0,0,amt_initsellVAPrev,0,5,0,F,106673096,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,VA: Initiating Sells,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_initbuyVAprev,0 LABEL: F RECALC: 0,0 PREFS: 0,128,0,1,0,0,amt_initbuyVAprev,0,5,1,F,106675152,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,VA: Initiating Buys,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_initsellVA,0 LABEL: F RECALC: 0,0 PREFS: 255,0,0,1,0,0,amt_initsellVA,0,5,0,F,106677208,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,DVA: Initiative Selling,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_respbuyVA,0 LABEL: F RECALC: 0,0 PREFS: 168,168,255,1,0,0,amt_respbuyVA,0,5,0,F,106679264,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,DVA: Responsive Buying,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_respsellVA,0 LABEL: F RECALC: 0,0 PREFS: 255,0,0,1,0,0,amt_respsellVA,0,5,1,F,106681320,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,DVA: Responsive Selling,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] amt_initbuyVA,0 LABEL: F RECALC: 0,0 PREFS: 168,168,255,1,0,0,amt_initbuyVA,0,5,1,F,106683376,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,DVA: Initiative Buying,F,F,F,2,895895,5,T,50,F,Bar_deltaCI,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] once_extensionDown,0 LABEL: F RECALC: 0,0 PREFS: 255,128,0,1,0,0,once_extensionDown,0,5,3,F,106685432,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,NEGATIVE RANGE EXTENSION,F,F,T,1,895895,3,F,10,F,VAL,1,F,F,
INDICATOR: SIG #10 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: SIGNAL[ESH1 (1.25r)] once_extensionUp,0 LABEL: F RECALC: 0,0 PREFS: 0,128,0,1,0,0,once_extensionUp,0,5,3,F,106691600,0,16,,F,0,0,0,0,0,F,0,F,F,F,F,0,0,0,0,0,0,0,0,0,0,0,0,F,F,0.000000,0.000000,0,0,0,0,0,0,0,0,0,T,POSITIVE RANGE EXTENSION,F,F,T,1,895895,3,F,0,F,VAL,1,F,F,
INSTRUMENT: ESH1:CME:2 PERIODICITY: 4,12500,1 TYPE: 24,2 COLORS: 37632,12255232,1,0 [Alias: @ES#]
FOOTPRINT: 1,13,8,0,9,0,0,0,0,0,0,3651,0,0,0.000000,0,0,0,0,0,,1,
SESSION #2. Index Options: Open,UnPosted, Hours: 09:30 to 16:15
INSTRUMENT: ESH1:CME:2 PERIODICITY: 4,12500,1 TYPE: 3,2 COLORS: 25600,16746632,1,0 [Alias: @ES#]
FOOTPRINT: 1,0,2,0,9,0,0,0,0,0,0,64,0,0,0.000000,0,0,0,0,0,,0,
SESSION #2. Index Options: Open,UnPosted, Hours: 09:30 to 16:15
INDICATOR: TPO #145 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: TPO[ESH1 (1.25r)] LABEL: F RECALC: 0,0 PREFS: 0,0,0,0,0,0,192,192,192,2,2,0,0,0,0,3,2,0,192,192,192,2,2,0,255,255,255,1,2,1,0.250000,0,10011001,T,T,30,0,70.000000,F,T,F,F,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
PANE #3 PCT=0.001631 PFLAGS=144 SCALE=1,-4800.000000,4500.000000,0.250000,1.000000,0.000000,0,0
INDICATOR: CI #40 ASSOC: ESH1:CME:2 PERIODICITY: 4,12500,1,FP,4,0,8,0,9,0,0,1,0,0, DESC: CI:Bar_deltaCI[ESH1 (1.25r)] VPS LABEL: F RECALC: 0,0 PREFS: 0,51,255,2,2,0,Bar_deltaCI,0,0,0,F,106697768,0,255,0,0,0,0,0,1,70.000000,F,0.000000,F,50.000000,F,F,10011001,1,0,0,0,F,F,0,0,255,1,2,0,33488896,33619712,21672,4.000000,8.000000,12.000000,
- This chart definition references 16 RTL objects (scan/signal/custom indicator)
END MarketDelta CHART DEFINITION for amt

“Initial Balance” Rotation Strategy: Part 6 – Profit Targets

Posted in RTL by astoeckley on February 16, 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.)

In our previous article of this series, we introduced the backtesting engine in MarketDelta and completed a simple 250-day backtest of the strategy discussed so far. The results were quite decent, especially considering that the exit strategy we tested used simple end-of-day exits with no trade management.

Today we consider what effect new profit target rules will have on our system; we exit the trade after a 5-point profit target is met. We will look at many additional exit strategies in the coming weeks, so stay tuned.

Our previous backtest included 4 rules:

  1. The long entry
  2. The Short entry
  3. The end-of-day long exit
  4. The end-of-day short exit (called a “cover”)

When we add the profit target rules, we need to keep all these rules, because if the profit target is not met, we still need to exit at the end of the day.

We will add 2 new rules:

  1. Long exit after a 5-point profit
  2. Short cover exit after a 5-point profit

Profit target rules are quite simple, and they use the ENTRY token to determine the exit price.

Click the “New” button right above the Signal list to create each new signal.

Our long exit simply looks like this:

And the short exit is nearly the same, but uses “covershort” as the rule action:

The rules appear in the list, however, since each bar evaluates the rules from the top rule to the bottom rule, the ordering is important. We don’t want the end-of-bar rule to trigger and then another rule also trigger on the same bar at the end of the day. So make sure those two last-bar exit rules remain at the end of the list. Our six rules now show in the System window:

As we can see, this simple 5-point forced exit has increased our net profit significantly over the 250-day backtest period:

A sample trade, after adding the system to a chart:

Of course, adding this profit target means that we miss out on larger trades that could go more than 5 points; but we also gain winners from trades that made money but gave it up by the end of the day.

In the next article we will show how you add stop loss rules, and in the following article we introduce optimization so we can determine the best levels for both stops and targets.

Note: All backtesting examples are for illustrative purposes only and not a recommendation to trade these signals.

“Initial Balance” Rotation Strategy: Part 5 – Backtesting 101

Posted in RTL by astoeckley on February 3, 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.)

Backtesting is the process of taking a trading idea and applying it to historical price data for the purpose of testing the method’s long-term profitability. It is fairly straightforward to imagine a potentially rewarding trading strategy, but how do you build confidence that it works over time? Backtesting investigates how it would have performed if you had traded it every day over the course of a few months or years, whatever your preference.

Today we kickstart a multi-part series for backtesting in MarketDelta. We use as the strategy the 200% Initial Balance rotation pattern identified in Parts 1 thru 4 of this series. The RTL code used for the backtesting expands upon the custom indicators and signals already discussed in the earlier parts of this series. If you have not read these, see the “Case Study” on this page.

It is very important to outline some notable drawbacks to backtesting:

  1. Markets are constantly changing, and their flux alters volatility, participant’s attitudes and the way in which they behave. Backtesting cannot study the future; it focuses only on events that already occurred. A system that performed well in a previous year will not necessarily perform well in the following year. But backtesting does provide a meaningful clue on the overall success of a trading concept.
  2. Backtesting assumes that you traded your system rigidly, with great discipline, following the exact conditions of the trading rules without error or improvisation. In reality, discretionary traders rarely react this way, unless they strictly buy and sell from computer-generated signals.
  3. Market “slippage” prevents you from consistently entering or exiting at precisely the specific levels included in backtesting. You must consider this when studying the profit reports from a backtest. Real results, even if followed rigidly, are usually a bit different than a backtest suggests.

However, despite this caution, backtesting grows in popularity and can effectively contribute to your work — as long as you maintain this perspective.

Exit Signals

So far in this series, we have focused only on coding the trading signals that accurately determine when to enter a trade based on our strategy.

As we will see, a backtest is more involved with the exit signals. How you close a position has dramatic influence on whether the entry signal worked.

Consider the following ways you could exit a trade:

  1. Close the entire position at a specific profit target
  2. Close the entire position at a specific price level or event determined by a signal, regardless of the trade’s profit at that time
  3. Scale out, by closing parts of the position at different times, as it becomes more and more profitable
  4. Stop-loss: closing a position after a maximum loss threshold is reached
  5. Time target: close a position at a specific time (such as end-of-day)

Additionally, you may have multiple entries in combination with multiple exits.

In reality, most traders naturally do a combination of all these on every trade. This makes backtesting complicated. In this series, we will discuss all these scenarios.

Today, we look only at a very simple closing strategy: the end-of-day exit. This strategy is important for all future techniques as well; if a trade has not stopped out for a loss, but has also not met a profit target, you would likely still exit at the end of the day.

In today’s introduction to backtesting, we simply enter once and hold until the last minute of the trading session, and then exit. We will investigate what happens if you enter a short at the Double IB High or a long at the Double IB Low and hold it until the end of the day.

Create a Trading System

To start, use the RTL button, the File > New menu, or the Open > Trading System menu to open the Trading System window:

If you have not already, hit the New button to create a new system.

Create Backtest Entry Signals

We already created 2 trading signals in this blog series: the long and short signals at the Double IB High and Low. While these signals were good for charting, they need some modification for the system rules.

In backtesting, each signal typically involves more than just entry/exit criteria; it also sets variables used to manage the system’s actions.

Consider this RTL code for one of our signals:

LO <= (SESST_LOW  – (SESST_HIGH – SESST_LOW)) AND TIME >1030 AND TIME < 1500

(The times, 1030 and 1500 listed, are for Eastern. Adjust accordingly for your time zone.)

We want our backtest to presume that we entered right at this 2X IB Low, so the “Rule Price” for this action will be a user variable, V#1, that is set to be equal to the 2x IB Low. We set the user variable as part of the signal using the SET token. When you specify a specific entry price as we do here, the backtest will enter at, or nearest, this price on the signaling bar. You could choose other Rule Price options, such as the Close of the current bar, the Open of the next bar, or other variations. But by using SET and entering at the exact level then our backtest accurately emulates real-time trading behavior.

To set a variable, the syntax is as follows. We want to set variable V#1 to the value of the 2x IB Low.

SET(V#1,(SESST_LOW  – (SESST_HIGH – SESST_LOW)))

Now, we combine this with our existing signal, and we get:

SET(V#1,(SESST_LOW  – (SESST_HIGH – SESST_LOW))) AND LO <= (SESST_LOW  – (SESST_HIGH – SESST_LOW)) AND TIME >1030 AND TIME < 1500

However, there is no need to duplicate the math, so we can simplify this as:

SET(V#1,(SESST_LOW  – (SESST_HIGH – SESST_LOW))) AND LO <=V#1  AND TIME >1030 AND TIME < 1500

Note how the LO <= V#1 is a replacement for the full arithmetic, since this math is included in the SET statement.

Thus, the signal we use for the backtest is not the same as the signal we used in charting. Create this new signal for backtesting in one of two ways:

  1. If a similar chart signal already exists, find it in the signal list, double-click to open, then press Save As right away and give it a new name. Make your edits with the above SET statements and Save again.
  2. If creating the signal from scratch, press the New button next to Signal (not the New button at the top of the window, which is for starting a whole new system).

The signal will appear in the signal list after it is created.

Note: You can filter the signal list by typing the first few characters of signal names into the “Find” box below the Signal list. If you name all your signals for a system with the same prefix, such as IBx2_long, IBx2_short, etc, then you can filter for “IBx2″ and just see the signals you need for the current backtest project.

You will then need to create a similar signal for the Short side of this strategy.

Create a Trading Rule

Once the entry signals are in place, we create Actions for these signals. How many to buy? At what price?

Click once on an entry signal you created, in the signal list. Choose the appropriate Action from the column to the right. For short entry signals, do not choose “Sell” – rather, choose “Sell Short.”

Choose the number of contracts you plan to trade with this Action, and specify “Contracts” or “Shares.” Note: if your strategy is an all-in/all-out system, without multiple scale-outs, then the profit per-share (or per-contract) is going to be the same regardless of how many contracts you choose here. For today’s backtesting, enter any number you want, but make sure you use the same number for each entry and exit signal.

For the “Rule Price,” select V#1 since our signals will set this variable directly.

For Periodicity, choose “one minute.” Since it is easy to acquire several months, or even years of one-minute data, we recommend this for backtesting signals such as those used in this system. For most strategies, this is sufficient. If you use Tick data, you have limited access to how far back you can backtest since it is difficult to acquire vast amounts of Tick data. Additionally, the backtesting can take much longer as it much look at thousands of times the amount of data.

The “Rule Marker” and the “Intra-bar” check box do not apply to backtesting; these settings are for charting the rule after it is created. This optional step lets you verify where the rule would normally trigger. As we’ll see in a moment, you can do this more comprehensively by sending the entire trading system to the chart instead.

Press the Add Rule button and your new rule will appear in the Trading Rules list.

Do this again with the other entry signals in your system.

Create the Exit Rule

For backtesting purposes, we will have our strategy exit at the close of the last bar of the session.

First, click “New” above the signal list. Enter the following simple RTL code to specify the last bar of the day:

POS = 1

When you save this Signal under a desired name, it will prompt you for the POS token settings. Choose Bars from End of Session. This means that we exit 1 bar from the end of the day.

You only need one signal, even though we will create two exit rules from this same signal (one to exit the Long, another to exit the Short).

Create the long exit rule in the same way: click the new exit signal in the list, choose the number of contracts, and choose Sell. Use “Close” as the Rule Price, and select 1-minute Periodicity.

Repeat this process again for the short exit rule, using “Cover Short” as the Action. The program will offer a warning that you are adding the same signal more than once; this is fine.

When you are finished, you will see all the rules:

Click image for a larger view.

Trading Rules List Order

The order of the rules in your trading rules list can be very important. When the backtest runs, it studies each bar in succession, and evaluates all your trading rules in order, from the first rule to the last. If you have an Exit rule above an Entry rule, and the logic of your RTL code permits it, then it is possible for the system to generate an Exit followed by a new Entry all on the same bar, if they are in this order. If, however, you had the Entry above the Exit, this would not happen on a single bar.

In this system, both our entry signals and exit signals have a Time attached to them, thus the order of the rules for this case is arbitrary and makes no difference. But for more complex systems, it can be quite important, so keep this in mind.

Also, the system considers the current portfolio status of Long or Short when it studies each rule for each bar. If the system is Long at a particular point in time, it will ignore all entry signals and only look for a “Sell” signal that exits the Long position — or, if you have a BuyMore action, or a Reverse action, it will consult those as well. All Short signals or CoverShort rules are ignored while the position is Long.

Setup the Backtest

One the system is built, you have to tell the software how to perform the backtest. Press the Setup Backtest button:

Click to see a larger view.

An explanation of the numbered items in this window:

  1. You can backtest on a single symbol, or an entire quote page. For example, you could test against the entire Dow 30 stocks, allowing for multiple entries per day. Here, we are testing the E-Mini.
  2. If your strategy allows for multiple purchases throughout the session, you can specify the absolute max size of exposure. This does not apply to our current backtest.
  3. Commissions are a very significant part of trading results. There are two ways to approach commission costs in a backtest:
    1. Leave them at zero, and then subtract them yourself when you look at the “Average Profit Per Share” of the backtest report. If your average profit is $20 per contract, and your round-turn commission per contract is $5, then you know your actual profit results are $15 per contract. This is the easiest solution.
    2. If you wish to have the commissions automatically calculated into the backtest, you have to break it down in the following ways: Are you paying a flat rate for the trade, regardless of its size, or are you paying a per-share/per-contract commission? Are you paying a single commission for the entire round-trip, or do you pay a commission for both entry and exit? For futures traders, you typically pay a single round-turn commission for each contract. These Commissions fields are flat rate, unless you enter a comma. If you are not on a flat rate commission, your Entry is 0 plus a comma plus your per-contract fee. Then your Exit is also zero. So “0,5” would be a $5 commission per round-turn. Or you could enter “0,2.5″ for both Entry and Exit, to break it up equally.
  4. How far back do you want to test? You can specify an exact start and end date for the backtest, or go back a set number of days from the current day. You must have price data downloaded into MarketDelta for the time period you are studying. Use the Download button on the main MarketDelta toolbar and specify 1-minute data and as many days as you require.
  5. Our strategy depends on regular trading hours (RTH), so select Session 2. Remember, our exit is 1 bar from the close of the day, which would mean at 4:14 pm Eastern Time. You could optionally select Session 0 if you want to exit at 3:59 pm, when the stock market closes.
  6. Choose which backtest reports interest you. The “Average Profit Per Share” and “Total Net Profit” are on the Day by Day report. Where it says “Report Round Trips As”… This is important! Most day traders think of an entry and an exit as a single contract transaction. Choose “1″ if this applies to you. Otherwise, the report will show half your net profit per share, since it breaks it up between the entry and the exit.
  7. If you already ran a backtest and just want to see the reports again, click Display Latest Reports so you don’t have to wait for another backtest to complete (which can sometimes take a long time).

Press OK to save this Setup.

Run the Backtest

Finally, press the Backtest button to run the backtest.

When completed, the reports pop up. According to the Day by Day report, a 250-day backtest for Session 2 of this strategy reveals that a basic end-of-day exit for only 2 contracts yields $3070 of net profit when accounting for $5 round trip commissions:

The report shows a positive net profit, including commissions. Now, considering our strategy, it is fairly clear: markets are rotational indeed.

We will have much more to discuss on backtesting in coming articles.

Note: All backtesting examples are for illustrative purposes only and not a recommendation to trade these signals.

Visualize the Trades

Open any chart, and set it to the same session as your backtest. Then, in the backtesting window, press the Send to Chart button at the bottom. The TSYS indicator is added to the chart. It shows every trade in the backtest, when you entered and when you exited. Colors denote profits and losses during the trade:

Or, you can add the Trading System indicator to any chart you wish, and select your new system.

Chart of the Week – Auction Market Theory Order Flow

Posted in Footprint® Chart, RTL by astoeckley on January 28, 2011

This week, we share with you a particularly informative chart that will appeal to anyone studying or learning auction market theory. This chart uses the RTL capabilities of MarketDelta to analyze order flow in the context of value areas. If you are new to auction market theory, we can recommend books by James Dalton, one of a few pioneers in the study of Market Profile. Additionally, click here for a discussion on Market Profile strategies and terminology, or click here to see a PDF that specifically discusses Value Areas.

Auction market theory analyzes price movement in and out of value areas, as determined by Market Profile concepts. This price movement, in market ranges that are out of balance, is either “initiative” or “responsive.”

Today’s chart uses several RTL signals to annotate what kind of auction behavior is unfolding. Because these are custom signals, the chart will only function in a Professional version of MarketDelta. It is also worth noting that this particular chart will take a few extra seconds to load due to the calculations it contains.

In a future article in this blog, we will discuss the RTL techniques used to create this chart. Today, we focus on its features.

It is important to note that the style of the chart, its strategy for the annotations and other tweaks provide flexible room for customization when using RTL and can be altered by anyone (click here for tutorials on RTL). This chart currently evaluates auction behavior in the context of the prior day’s value area for the first 90 minutes of the session, when the current day’s developing value area is still unfolding. Then, it switches its analysis to the developing value area, and the annotations distinguish between which method is used at any point in time.

Another nifty feature is real-time alerts for range extension above or below the Initial Balance area.

Click on each of the images below to see an explanation of all the features on the chart. You can download the chart definition right here: auction analysis.