TSCI.pngTutorial 2: Intraday Trading (TradeStation)


For this second tutorial we will explore using Tradescape technology for constructing an intraday trading signaler.

There is a separate Tutorial 2 for the Standalone version of the platform.

Intraday Disorder

Let us begin with an important point. If you are trading futures or currencies or any entity that trades 24 hours a day, you will not have to worry about overnight gaps. A signaler will still have to contend with the wild flurry of activity at certain hours of the day and the near absence of activity at others. The tradescape EM algorithm generally manages this sufficiently well, even when the intraday movements are far from orderly.

tutorial2A.png

This is an example from the commodity data we will be using for this tutorial. There can be wild intraday movements that are hardly indicative of order. These are not overnight gaps. These kind of abrupt movements occur intraday.

Overnight Gaps

If you are trading a security, ETF, or any entity that follows exchange hours, you must make a choice in terms of how to address the overnight/weekend gaps. There are often sharp discontinuities that can play havoc with many signalers that seek to trade the gap. The tradescape EM algorithm manages the order can be extracted from such price movements about as well as can be expected, but the win rate will necessarily be weak. When there is a sharp overnight movement, we can readily assume that this will go against the trade approximately half the time. Since the overnight moves often exceed the intraday movements, those positions are often closed for losses. There are also a lot of chaotic price movements intraday. A 50% win rate is exceptional in this type of trading scenario. Do not be surprised if you are looking at close to 40% win rates on the tradescape signals. Please remember that the tradescape is a map of the tradable order in the price movements. Overnight gaps plus the intraday chaos does not equal order.

If you make the choice to be out of the market everyday prior to the close, the gaps can be mathematically subtracted and the historical entity becomes solely the intraday movements of price. If you do this, you have to be careful. There are entities where all of the long-term profitability rests just in the gaps and where the sum of the intraday movements are net negative. As a case in point, let's look at AAPL for ten years with and without the overnight gaps mathematically removed:

tutorial2A2.pngtutorial2A3.png

An entity can look vastly different with the overnight gaps removed. This was done with 5min bars, meaning the overnight movements and the movement in the first 5 minutes of each day's trading have been mathematically removed. In the original data, we have a 42% robust annual growth trend. With just the intraday action defining the modified entity, we see a -3% robust trend.

All of the Tradescape functions have a Degap option. If this is set, it is assumed you will exit all positions at the closing price of the day and never be in the market overnight. This example should make clear the rationale for our including this option in all tradescape procedures. For intraday traders, this choice with respect to overnight hold of positions is a profound one that dramatically changes the entity you are in actuality trading.

Even with this trading approach of avoiding overnight positions, there can be a decided lack of smoothness at the seams. The mathematical approach enforces continuity, but if the price is racing skyward just before close, and it falls like a brick in the first bar after the next day's open, the joined price point will have a very different behavior prior than after, and any trading algorithm using the prior day's information must account that in some fashion. Alternatively, one can wait until only the present day's data are used for the signal.

Intraday Tradescapes

The basic tradescape procedures process data of any bar density. You can process 1 minute bars as easily as EOD data. A tradescape is entity specific, and it will be data sampling specific. There is no intraday tradescape per se. There is only the tradescape: the entity, the choice of bar density, and the decision as to how to manage any overnight gaps, if present.

Intraday tradescapes are only a convenience that allows a panel of different bar densities to be constructed using just one input data stream. Their purpose is strictly for identifying the data density and time horizon for best trading the measure of order that can be realized from intraday price movements. In our experience, we have seen vast differences between entities with respect to optimal data densities and time horizons.

Note that you can add multiple instances of a single entity to a chart, each at different bar sampling rates, and generate a panel of tradescapes. When you do this, you specify a fixed bar count for each tradescape. This will correspond to different lengths of time for each analysis. Intraday tradescapes use a single input data stream to cover a single time period for each of the bar densities automatically generated.

A Commodity Target

We begin with @YG, the gold mini contract, as our target.

Step 1: Generate a Long Term YG Intraday Tradescape Panel

    In TradeStation, create a 5 minute chart of YG. We will use @YG. Use 1/1/2007 as the First Date. To match the results in this tutorial, select 1/31/2013 as the Last Date:

tutorial2B.png

There will be about 363,503 bars using the above dates.

Intraday Tradescapes Memory Issues

We have routinely processed 10 years of 1min data (1 million bars) in an Intraday Tradescape analysis. This can require up to 500-600Mb of available memory if you want to see all tradescapes, including sub 5-min bars (Reduce=1), and up to 250Mb for 10 years of 5-min bars and above (Reduce=2,3).

We also have built-in reductions for 5min and 10min bars, as we are using here. The reduction we will use (Reduce=4) offers 5, 10, 15, 30, 1hr, and 1 day bars from 5min input data.

Note that when trading at the time horizons typical of 5min or 10min bars, a year's data is certainly sufficient in terms of count of trades. It may not be sufficient, however, for a wide representation of market states.

    Choose the Insert Analysis Technique... option in the TradeStation right click menu in the chart, and select the TSIntraTradescape technique and check Prompt for Format. Click OK. On the Inputs tab, change the WalkFwd to 299046 (this will give five year's analysis prior to the most recent year). Change the Reduce setting to 4; with 5-min input data, this generates of panel of 5min, 10min, 15min, 30min, 1hr, and end of day (as of midnight) tradescapes. Enter 60288 bars for the Reserved period. This represents the most recent year of data. Click OK.

tutorial2C.png

Note that for this continuous representation of YG, there are missing bars, intraday periods where there are no trades.

It can take up to a minute for TradeStation to export the data points. Once that is done, you will see a message in the TradeStation Events Log indicating that the TSIntraTradescape call was successful.

A progress bar will then show the different tradescapes as they are being created (the progress bar can be suppressed by setting InactiveAtLastBar to 2).

This processing can take up to ten minutes (depending on the speed of your computer). Each tradescape consists of 700 different backtests, and for each an EM signal must be constructed and the resultant equity curve analyzed. The 5-min bars will require the greatest analysis time since there are nearly 300,000 bars in the signal and equity plot and there are 700 of these that must be computed to construct the tradescape. The analysis is done independently from the TradeStation environment in a separate process, so you can resume your work in TradeStation while the computations continue.

When the processing is complete, the six intraday tradescapes will be plotted. They cover only long trades.

    Check the Expanded button in the Y-axis Lag Range option to automatically expand the lag fraction bounds. This will allow us to better see the sweet spot we will be targeting.

tutorial2D.png

The Reduce=4 setting produces a 6 panel display. As you will note from the titles, the first panel has 299046 points (5min bars) and covers five years. the second has 149253 (10min bars), the third has 99682 (15min bars), the fourth has 49841 (30 min bars), the fifth has 24920 (1hr bars) and the last is an EOD reference. The difference in dates is a consequence of how the missing bars are accounted in the reduction.

We generally expect to see major differences from the different sampling rates. We look first at the RRt, the default reward to pain. While we expect more reward from more frequent trading and we also expect less pain since we can react more quickly to adverse price movements, faster is not always better.

There is good news. We see a very lag tolerant behavior. Commodities are regarded as strongly trending entities, as in the 'turtle trading' references. A caution is in order as well, however. The price of gold was near $800 when the time period began and almost $1800 when the five year period concluded at the end of January 2012. In such an upwardly moving market, the probability of successful long trades increases even with random entries and exits. We should have a good test, however, as the last year of reserved data consists of about a $100 net drop in price. We want our systems to do well in this blind walkforward.

If we are trading the order in the time series, we want clean neatly defined time horizons that stand out as sweet spots. The 5min bars clearly do not look as strong as the 10min. The definition sharpens in the 15min plot. The 30min tradescape is even sharper as the faster action is essentially washed out and a single EM length 18 peak is present. The 54 EM Length at 10min bars, the 36 EM length at 15min bars, and the 18 EM length at 30min bars are all the same sweet spot. It is simply accessed at three different bar densities.

Note that while it appears the peak is shrinking with increasing bar times, on a percentage basis of price it is similar. Visually we see 54 6, 36 4, and 18 2. At this stage there are many considerations. If there are EMAs anywhere in the signaling algorithm or model, for example, the shorter EM length of the 30min bars may offer an advantage.

Let us start by getting a sense for what our average trade length looks like for this sweet spot.

    Check the Avg Trade Length button in the X-axis Time Horizon option to change the X scaling to the computed average trade length.

tutorial2E.png

In general, a tradescape will cover average trade lengths up to somewhere between 200-250 bars (this is entity dependent). For the 5-min panel, this means the average trade lengths run out to about 200*5min=1000min or about 2.5 days. The 10-min panel covers up to 2000 min or about 5 days (1 week). The 15-min panel covers up to 3000 min or 10 days (2 weeks, the 30-min panel covers up to 6000 min or 15 days (3 weeks), the 60-min panel covers up to 12,000 min or 30 days (6 weeks), and the last EOD panel covers 200-250 days or approximately a year. In general, one signals in the lower half of a tradescape for practical reasons, so the first panel can be thought of as having a little over 1 day average trade duration, the second about 2.5 days, the third about 5 days, the fourth about 7.5 days, the fifth about 15 days, and the last about 125 days as the maximum range represented in the plot.

Our sweet spot is seen as 142*10min=1420min, 92*15min=1380min, 49*30min=1470, or about 24 hours for an average trade length. That cycle is little surprising.

    Check the EM Model Length button in the X-axis Time Horizon option to change the X scaling back to the default EM (Expectation Model) length. This is the standardized information content or time horizon used in all EM-based tradescape plots.

    Click on the tradescape point that is EM length=0 and Lag Fraction=1 in the 30min panel. This gives us an equity curve for the underlying, for the buy and hold:

tutorial2F.png

Clearly gold was on an uptrend during the latter portion of this five year period following the financial meltdown. We have a 16% robust trend (the CAGR realized from fitting every point in the equity curve). We have an underlying RRt of 2.04. In a simple buy and hold across these five years, gold offered more than twice the reward than pain. This is clearly good. We don't expect as much benefit from a long signaling system in this already favorable environment. The average retracement from the all-time high is low, just 7.4%.

We will design our system using this data, acknowledging that the analysis period is not ideal. We would prefer a greater mix of market behaviors, but prior to this start date, the data thins and many missing bars occur especially outside of market hours.

We will primarily rely on the blind walkforward from the very different behavior of YG in the reserved year of data to assess the signaling systems we will test.

At this stage, we only know that we are designing a signaling system using an analysis period consisting of a good measure of strongly uptrending behavior.

    Select the Trend % in the Z-axis Performance Metric dropdown to plot the robust trend surface.

tutorial2G.png

We are now looking at only the robust trend CAGR, the return we could expect from trading the order in the time series, with no regard for the pain associated with trading. We see the superb return at the 30min bars. With full accuracy and low lag, 30-50% annual return is potentially attainable from trading the order in the price movements-if the history persists going forward. Here we know it will not do so.

    Select the RRt-Trend:Retracement in the Z-axis Performance Metric dropdown to restore the RRt surface (default).

Step 2: Select a Sampling Density and Time Horizon for Trading

The next step is to select a sampling density and time horizon for trading.

We will look closely at the three sampling densities.

If there is a highlight (a thick border) around any of the plots, unselect the plot by left clicking anywhere in the graph (except on a point) to clear the selection(s).

Note that there are also buttons in the graph toolbar that assist with this selection process (we will not use them here):

8006.png The Toggle Display of Selected Graphs button, if depressed, will display only the subset of selected or highlighted graphs. Otherwise all graphs are displayed with the selected ones shown with this gray highlighted border.

8007.png The Select All Graphs button selects all of the graphs. After clicking this button, all graphs will be highlighted.

8006.png The Unselect All Graphs clears all selected graphs. After clicking this button, no graphs will be highlighted.

    Double click on the second panel, the 10-min bar plot (do this anywhere except on a tradescape point-the zones around the graph are convenient). You will now see just the 10min bar plot.

    Using the mouse, zoom-in on the principal peaks region:

tutorial2H.png

The EM length 52-54 appears to be a good estimate for the center of the sweet spot.

    Right click anywhere in the plot to clear the zoom-in. Double click anywhere in the graph (except on a point) to restore the 6 panel display.

The graph that was just view was probably highlighted from the double click (there is a gray border around the plot).

    Left click in the 10min plot (anywhere except on a point) to clear the selection. The border will clear.

Let us now look at the 15-min panel. We would expect to find the EM length 54 peak occurring at about EM length=36.

    Double click on the third panel, the 15-min bar plot (do this anywhere except on a tradescape point-the zones around the graph are convenient). You will now see just the 15min bar plot.

    Using the mouse, zoom-in on the principal peak region:

tutorial2I.png

No surprise. The peak occurs at about an EM length of 34. This is the same sweet spot.

    Right click anywhere in the plot to clear the zoom-in. Double click anywhere in the graph (except on a Pont) to restore the 6 panel display.

Again, the graph that was just viewed was highlighted from the double click (there is a gray border around the plot).

    Left click in the 15min plot (anywhere except on a point) to clear the selection. The border will clear.

Let us look now at the fourth panel, the 30-min bars. We would expect this same peak to appear close to EM length 17-18.

    Double click on the 30-min panel plot in order to view just the 30min bar plot.

    Once again, using the mouse, zoom-in on the principal peak region(s) in the lower EM length region:

tutorial2J.png

We have the expected EM length=18 peak.

For the purpose of this tutorial, we will elect to trade the 30-min data.

Step 3: Check the Tradescape from the TradeStation 30min Data

At this point the intraday tradescape procedure accomplished its purpose. We have chosen both a data sample rate and a target time horizon at that set of bars. We can now use the standard tradescape signal analysis routines.

    Choose the Format Symbol... option in the TradeStation right click menu in the chart, and change to 30 min bar data. Be sure the First Date remains at 01/01/2007. Click OK.

tutorial2K.png

    In TradeStation, choose the Insert Analysis Technique... option in the TradeStation right click menu in the chart, and select the TSTradescape technique. We will again set the values for a 5-year history and a 1 year reserved period. Enter 55408 for WalkFwd and 11327 for Reserved, and then click OK.

tutorial2L.png

Note that we cannot simply divide the WalkFwd and Reserved values by 6 to account the 30min bars, since we have to address how missing bars are handled.

Note that there may be minor differences between the TSTradescape call with 30min data and and the TSIntraTradescape panel that reduces the input data to 30min bars. The reduction algorithm that TradeStation uses is different from the one TSIntraTradescape uses mainly with respect to how missing bars are handled. Because missing values can impact the EM length slightly, it is a good idea to rerun the tradescape with the data exactly as TradeStation reduces it.

    Check the Expanded button in the Y-axis Lag Range option to automatically expand the lag fraction bounds. This will allow us to better see the sweet spot we will be targeting.

tutorial2M.pngThe differences are minor. The 18 EM length remains the target. Before we commit to this time horizon target for the signaler, it is worthwhile to explore how stable this EM 18 length is across time. To evaluate, we will generate a progressive tradescape. This is a panel of tradescapes that are sequential in time. Using 30-minute data and a 24 hour traded entity, we have sufficient data to look at the five years within the analysis period separately.

Step 4: Generate a Progressive Tradescape Panel

    In TradeStation, insert a TSProgTradescape analysis technique with the following settings: and then click OK.

tutorial2MA.png

    Check the Expanded button in the Y-axis Lag Range option to automatically expand the lag fraction bounds. Again, we wish to better see the sweet spot we will be targeting.

tutorial2MB.png

Here we see the tradescapes for the five successive one-year periods in the analysis window. We don't expect these to look similar in terms of the magnitude of the performance at higher lags. We fully expect to see less lag tolerance in certain periods as opposed to others. We fully expect to find market periods where the performance realized in trading long is weaker and periods where it is much stronger. We don't want to see significant differences in this optimum 18 EM length across the five periods. Here we do see modest differences. The good news is that this EM length is consistent enough across the different market states represented in this five year period that we can have a greater confidence going forward. There was a very different time horizon or information content pattern during the worst of the financial meltdown, but even there the EM length 18 was still somewhat close to the peak.

Clearly longer time horizon trades worked well in certain periods but not others. The sweet spot we target, however, looks very good in all five panels.

Before we proceed with the signal design, we will run one more preliminary analysis to see if asymmetric signaling will be of value.

Step 5: Generate an Asymmetric Tradescape Panel

    Before we proceed, close all existing instances of the Trading Sciences Platform (in Windows 7 and 8, you can right click and close all in a single step).

    In TradeStation, insert a TSAsymTradescape Analysis technique with the following settings and then click OK.

tutorial2MC.png

We will use the -2 Asymmetry setting to generate a panel of nine different signaling asymmetries. This will take quite a while.

We will let this run in the background and revisit this procedure in step 8 when we explore breakout signals.

Step 6: Evaluate Real World MA Signals Against the YG 30min Tradescape

To evaluate your real-world trading signals you will need to have some experience with TradeStation's EasyLanguage coding. You will need to modify the TSSigEval analysis technique to generate your specific trading signals. At present only binary signals are supported. You must code a 1 for in-market long, -1 for in market short, and 0 for out of market for each trading day. Example functions have been furnished for common MA, epsilon MA, breakouts, and MA crossovers.

If we look at trading order from the perspective of most closely matching the EM signals, it makes sense to begin with differenced moving averages. The signal is taken directly from the smoothed price in the MA. Typically, the slope of the moving average is used to generate binary entries and exits.

While directly signaling from the smooth curve hardly insures an attractive lag, it does generally imply a very low scatter (or standard deviation) in the lag that will be present at each of the signal turns.

The main problem with this type of moving average signaling is the 'whipsaws' that occur when the slope (the difference between the current and prior price) is near zero and the signs oscillate about zero generating a large number of short, usually meaningless trades, which are unlikely to be profitable in any significant way, and often generate losses. The most common way of dealing with this problem is to employ multiple passes of the moving average algorithm. Double and triple EMAs are frequently used, for example. In this tutorial, we will explore 2-pass EMA, SMA, WMA, and hybrids that smoothly transition from the WMA to the SMA. A two pass algorithm can eliminate most of these undesired oscillations, but at the added cost of additional lag.

A two-pass SMA is often a good upper lag limit for tradescape work. Its lag is about as high as you would ever consider in any well-crafted signaling system and its accuracy is often close to complete. An SMA utilizes the information in its window to the maximum measure possible with absolutely zero intelligence.

A two-pass EMA is a good example of a moving average signaler that has a reasonably low lag, but suffers a good deal of inaccuracy, and this typically increases as the length of information processed in a window increases. We will use this two-pass EMA as the lower lag limit.

The two-pass WMA is usually slightly higher in lag than the EMA in practical signaling, but as many authors have pointed out, the properties of an IIR filter and an FIR filter are apples and oranges. Because the performance of an EMA degrades with increasing lengths, the WMA and EMAs often swap positions when a series of time horizons are represented in the test signals. The EMA will tend to fare better at lower time horizons since a lower length EMA was typically used to generate it.

We find it particularly useful to use a "raised" WMA that does not decay close to the minimum weight at the bound. Instead, an adjustable parameter is introduced to specify the height of the weights at the bounds. This creates a moving average that varies linearly between an SMA on one side to the WMA on the other. We do this to sacrifice some of the lag reduction arising from the WMA weighting, in favor of infusing the accuracy, however blind and lagged, of the SMA. In effect, we want an algorithm that can vertically march up and down the tradescape's lag-fraction dimension in order to find an algorithmic point where this fuzzy tradeoff between lag and accuracy results in the best performance.

We use a function we created for TradeStation, TSMA2Sig(Price,MAType,Length), to generate these two pass MA signals. It is written as it is for efficiency; we found more compact coding could increase the signal computation time by up to two orders of magnitude. This function uses a fast SMA for MAType=0, the EMA for MAType=1, the WMA for MAType=2, and a raised WMA function (TSRWMA) for MATypes 3, 4, and 5. In terms of the "distance" between a WMA and SMA, these are 75%, 50%, and 25% (MAType=3 is closest to the SMA, MAType=5 is closest to the WMA).

From our experience, we know that the 18 EM Length zone will typically be covered by 2-pass MAs in the 25-30 length region.

    Use the View | Development Environment option in TradeStation and from the Development Environment, use File | Open, choose Indicator from the dropdown and select TSSigEval. Immediately use File | Save As and rename TSSigEval to TSSigEval_T5.

    Change the line

   String SignalTitle("TSSigEval"), // signal title to be added to the Tradescape plot

      to:

   String SignalTitle("TSSigEval_T5"), // signal title to be added to the Tradescape plot

    Delete all of the lines between these two markers:

   { ---------------------------------------------------------------------------------------------------------------
      Begin user-defined signal region of code, add up to 15 Signals
      --------------------------------------------------------------------------------------------------------------- }

 

   { ---------------------------------------------------------------------------------------------------------------
      End user-defined signal region of code
      --------------------------------------------------------------------------------------------------------------- }

    Insert the following between these two markers:

   Signal[0] = 6.0; // signal count

   Signal[1] = TSMA2Sig(Price,0,25); // SMA

   Signal[2] = TSMA2Sig(Price,3,25); // 75% SMA, 25% WMA

   Signal[3] = TSMA2Sig(Price,4,26); // 50% SMA, 50% WMA

   Signal[4] = TSMA2Sig(Price,5,27); // 25% SMA, 75% WMA

   Signal[5] = TSMA2Sig(Price,2,31); // WMA

   Signal[6] = TSMA2Sig(Price,1,25); // EMA

    Verify the technique and keep the development environment window open--we will revisit this process for the other types of signals.

    Insert the modified TSSigEval_T5 analysis technique with the following settings and then click OK:

tutorial2N.png 

We will again reserve the most recent year of 30-min bar data for a blind walkforward.

Please note that you must insure the TradeStation MaxBarsBack setting (the Maximum number of bars the study will reference in the General tab) is high enough to accommodate the signaling algorithms that will be called. TSSigEval is set to a user-defined value of 125. You will need to increase this if more bars than this are used in the computations.

    Check the Expanded button in the Y-axis Lag Range option to accommodate the higher lag of 2-pass MA signaling algorithms.

tutorial2O.png

We've tweaked the lengths of the MA to get approximately the same time horizon from each, and to have each fall very close to the desired time horizon target of 18 EM Length. Each of the larger points with the numbers in them represent the 6 real-world trading signals. While none of the signals match the EM tradescape in terms of performance, we do like the systems with the higher lag in terms of performance. The WMA (system 5) and the EMA (system 6) do not fare as well, despite having lower lag.

Note that each each trading system point is colored by its RRt relative to the RRt gradient of the tradescape.

This is a good result. We have MA signals that look very strong, and a good indication of lag tolerance historically. We know we little expect to see this performance in the blind walkforward year where the upward trending largely ceased. For this analysis period, we want to see signals that outperform the underlying.

    Place the cursor on the point that is at 0 EM Length and 1 Lag Fraction:

tutorial2P.png

The fitted trend for the five-year analysis period years offers a 16.4% robust CAGR and an RRt reward-to-pain of 2.08.

We know the underlying RRt of 2 would plot as light red with this full-range color gradient, and here we see appreciably better performance than the underlying with all six systems. It is encouraging that the color of systems 1-3, the SMA and the hybrid SMA-WMAs (75-25, 50-50), are near the upper end of the gradient with very high RRt reward-to-pain ratios.

Here we have this difficult tradeoff between accuracy (and the more efficient use of the information content) and lag. Clearly signal 2 has the best reward-pain. This is a 75% SMA - 25% WMA hybrid. In general, all else being equal, we tend to select the system with the least lag. Here we see a penalty for the less efficient use of the information in the WMA. The EMA result is largely expected, as the IIR filter tends to have poorer accuracy.

    Place the mouse cursor on signal 2:

tutorial2Q3.png

The lag is high, nearly 23 bars. With 30min bars and a 24hr traded commodity (48 30-min bars per day), that is nearly half the 24 hr trading day.

As one would expect from an algorithm designed to capture only a smooth central channel, the robust SD is just 2 bars (there is little scatter in the lag of the signals). We capture most of the order in the price movements, a 8.1% coverage error (the percent of instances where the real-world signal failed to match the tradescape's EM reference for this signal's estimated time horizon and lag).

That which should determine any final selection is the equity curve of the backtest and what occurs during the reserved data period.

    Click the system 2 point, the 75-25 hybrid SMA-WMA (note that you can also see the equity curve for any of the tradescape EM signals by clicking on any tradescape point)

    8614.png Select the Customize Titles for Equity Plots option. This selects the metrics shown in the titles and which titles are to be displayed. Check the Avg Retracement Info button. Click OK.

tutorial2Q4.png

This upper plot contains the equity curve for system 3 and for an EM signal representing exactly this same estimated EM length (19.13) and lag fraction (1.19) on the tradescape surface. The yellow equity curve is for the EM signal; the cyan equity curve is for signal 2.

While the EM signal (yellow) outperforms the real-world hybrid MA signal (cyan), the RRt for trading signal 2 increased to 8.4 from 2.1; a four-fold improvement. The robust trend improved to 24% from 16.3%. The main factor in the improvement in reward-pain was the reduction of the pain (the retracement or drawdowns). The average retracement dropped from 7.3% (already very low) to 2.6%.

We hope to see that same benefit in the blind walkforward where we know the signaling algorithm will be more severely tested since there is net loss in the buy and hold for the period.

    Choose the Format Analysis Techniques... option in the TradeStation right click menu in the chart, select the TSSigEval_T5 technique, click on Status to turn it back On, and click on Format. On the Inputs tab, change the Reserved value to 0. Set the WalkFwd value at 11327 and then click OK.

    Once more, Check the Expanded button in the Y-axis Lag Range option.

tutorial2Q5.png

For the one year blind walkforward, the tradescape shows much less lag tolerance in terms of reward to pain at the sweet spot. There is now an indication of split zones (the larger and faster trading region at very high lag), but the good news is that all systems outperformed the underlying for this blind one year period. Further, we see basically the same pattern in the signals that we saw in the analysis period.

If you place the cursor on the point at EM length=0 and Lag Fraction=1 (there is a similar underlying point at .7 and 1.2 lag fraction), we see the buy and hold RRt for this one year is 0.19 and the fitted robust trend is +1.4%. Clearly all of the systems fared far better in terms of reward-pain. If the RRt is less than 1 but greater than 0, the reward does not exceed the pain but there is still profit, the gradient is a grayscale from light to dark gray. Here we see a strong RRt from all signals.

    8619.png Click on the View Equity Curve for a Trading Signal, enter 2 and press OK:

tutorial2Q6.png

There are 125 round-trip trades in the trading year. The RRt increases from 0.2 to 6.0; the average retracement drops to 1.8%. Ignoring the sharper differences in the non-robust estimate of return, we compare the robust fitted trends and see 11.5% as opposed to the 1.4% of the buy and hold. Despite the high lag fraction of the signaler, and the decidedly changed market state, YG's behavior held steady enough that the signaler worked well during this time. There is little attractive about a 42% win rate, but with high lag and intraday trading, this is hardly unexpected. Although a five year history plot doesn't make it easy to see, signal 2 was in the market only 52% of the time.

The higher lag signals 1 and 2 had better reward-pain, which suggests that a higher accuracy may be more important (the more time or lag a signal has to 'get it right', the more accurate it can be in catching price turns-it may simply be too late to capitalize on it). They key point, however, is that a different behavior in this one-year blind study confirmed the relative validity of the original tradescape's time horizon estimate. Despite differences, the sweet spot in the original tradescape continued to work in a very different market state. And further, it was successfully traded by relatively weak (high lag) signals.

Step 7: Evaluate Real World Epsilon MA Signals Against the YG 30min Tradescape

With perhaps the exception of EMAs, whipsaws in trading signals are not typically dealt with by the additional smoothing of multiple algorithmic passes. One doubles the lag in the signal in a two pass procedure and that occurs mainly for the additional accuracy that comes from eliminating fast cycle whipsaws when the slope of the MA is close to zero. Experienced signal designers will sometimes use a single pass differenced MA with an epsilon or fractional threshold to confirm a turn before the signal changes sign. This adds some lag, but normally less than this doubling that occurs with a two-pass sequential algorithm. We will do that in the next step of the tutorial as our examples migrate further away from ordered signaling and start to process more of the 'chaos' in the price movements.

To do this, we will use a function for TradeStation TSMASigEps. This function incorporates a percentage based epsilon signaling that resets with each sign change in the differenced 1-pass MA.

We will begin by evaluating 15 different combinations of 1-pass moving average lengths and 2 different epsilon values.

    From the TradeStation Development Environment, select the TSSigEval_T5 tab (if it is not open, use File | Open, choose Indicator from the dropdown and select TSSigEval_T5). Immediately use File | Save As and rename TSSigEval_T5 to TSSigEval_T6.

Change the line

   String SignalTitle("TSSigEval_T5"), // signal title to be added to the Tradescape plot

      to:

   String SignalTitle("TSSigEval_T6"), // signal title to be added to the Tradescape plot

    Delete all of the lines between these two markers:

   { ---------------------------------------------------------------------------------------------------------------
      Begin user-defined signal region of code, add up to 15 Signals
      --------------------------------------------------------------------------------------------------------------- }

 

   { ---------------------------------------------------------------------------------------------------------------
      End user-defined signal region of code
      --------------------------------------------------------------------------------------------------------------- }

    Insert the following between these two markers:

   Signal[0] = 15; // signal count

   Signal[1] = TSMASigEps(Price,0,40,0.02);

   Signal[2] = TSMASigEps(Price,3,40,0.02);

   Signal[3] = TSMASigEps(Price,4,42,0.02);

   Signal[4] = TSMASigEps(Price,5,43,0.02);

   Signal[5] = TSMASigEps(Price,2,50,0.02);

   Signal[6] = TSMASigEps(Price,0,33,0.03);

   Signal[7] = TSMASigEps(Price,3,33,0.03);

   Signal[8] = TSMASigEps(Price,4,36,0.03);

   Signal[9] = TSMASigEps(Price,5,38,0.03);

   Signal[10] = TSMASigEps(Price,2,44,0.03);

   Signal[11] = TSMASigEps(Price,4,32,0.04);

   Signal[12] = TSMASigEps(Price,5,33,0.04);

   Signal[13] = TSMASigEps(Price,2,43,0.04);

   Signal[14] = TSMASigEps(Price,1,51,0.02);

   Signal[15] = TSMASigEps(Price,1,44,0.03);

    Verify the technique and keep the development environment window open--we will revisit this process for the other types of signals.

    Insert the modified TSSigEval_T6 analysis technique with the following settings and then click OK:

tutorial2R1.png

We will again reserve the most recent year of data.

Again, you must insure the TradeStation MaxBarsBack setting (the Maximum number of bars the study will reference in the General tab) is high enough to accommodate the signaling algorithms that will be called. TSSigEval is set to a user-defined value of 125. You will need to increase this if more bars than this are used in the computations, something that can easily occur when using single pass MAs.

tutorial2R2.png

We varied the MA lengths between 30-50 for the purpose of realizing the time horizon target. All of the different MAs fall near the 18 EM length target. Overall, we achieved approximately a 15% reduction in lag fraction.

We are testing three different epsilon values, 0.02%, 0.03%, and 0.04%. These are much smaller than the 0.25% and 0.40% we used for the EOD data in tutorial 1. For entities traded 24 hours with no overnight gaps, and for the instance where positions are not held overnight, smaller epsilons can be used.

An epsilon band extends this percentage on each side of the prior bar's price when a sign change occurs in the difference computed for the current bar. Until that band is broken, the sign is not accepted. Please note that the epsilon exists to remedy the incomplete smoothing in the MA algorithm. He we use a simple percentage as opposed to a volatility band, although systems designers often implement the epsilon an ATR fraction. Insofar as the purpose of the epsilon is to deal more with the quiet periods where the slope is close to zero, a fixed percentage often suffices. Note that substantially higher epsilon values are not merely compensating for deficiencies in smoothing, but rather add a strong confirmation component to the trading signal.

Signals 1 (.02%) and 6 (.03%) are the SMA, signals 2 (.02%) and 7 (.03%) are for the 75%-SMA-25%WMA hybrid, signals 3 (.02%), 8 (.03%), and 11 (.04%) are for the 50%SMA-50%WMA hybrid, signals 4 (.02%), 9 (.03%), and 12 (.04%) are for the the 25%SMA-75%WMA hybrid, signals 5 (.02%), 10 (.03%), and 13 (.04%) are for the WMA, and signals 14 (.02%) and 15 (.03%) are for the EMA.

The aggregate results fit with our expectation of lag and accuracy and the tradeoff that is routinely observed in such signalers.

    Zoom-in a narrow X-region of the graph:

tutorial2R3.png

Here was have the accuracy-lag tradeoff once more. The low lag of system 9 is attractive, but it is hard to ignore the greater reward-pain in system 2.

    Place the mouse cursor atop signal 9:

tutorial2R4.png

    Place the mouse cursor atop signal 2:

tutorial2R5.png

We have now added a chaotic component to our signaler, albeit a small one. We no longer see low coverage errors with the FIR-type MAs in terms of matching the EM reference signal. The errors are all in the vicinity of 12-20% or higher. The EMA, signals 14 and 15, have the lowest average lag, even though their five year performance is weak in terms of reward-pain. That is not atypical of IIR filters at the lengths used in these signals.

Here we see it is a close call. The win rates are both around 43%. The RRt is higher with signal 2, 9.2 vs 6.2, but the lag is better with signal 9, 185 vs 217. The robust trend is much higher with system 2, 24.4% vs 19%.

At this point, we know now what we are going to see in the blind 1-year walkforward. We know YG's behavior is going to demonstrate this split profile with this shift to a faster time horizon as compared to the five year aggregate. We know in general the lowest possible lag, with respectable performance, tends to be the best defense for the fluctuating optimal time horizons. We can choose robustness, which may not be the best best performance when the entity remains very close to historical norms walking forward. Or we can choose the best performance, knowing we have less robustness in terms of responding to market changes.

Once again we see the Heisenberg-like tradeoff between accuracy in trading the order (usually the signalers with higher lag) and the lower lag (usually the signalers with less accuracy). We would like to choose a favorable tradeoff as well as to seek this robustness across time. The lower the lag, in general, the greater the robustness will be, even if the accuracy is weaker and the aggregate performance historically is poorer.

 For the purpose of this tutorial, let's say half the equity is assigned to system 9 and half is assigned to system 2.

    Click the point 9 trading system.

    Because the EM signal performs so much more strongly at this lower estimated lag of the signaler, in the upper region of the plot, zoom-in the equity curve for the signal and underlying:

tutorial2R6.png

This upper plot contains the equity curve for system 9 and for an EM signal representing this this same estimated EM length and lag fraction on the tradescape surface. The yellow equity curve is for the EM signal. The cyan equity curve is for signal 9. The RRt increased from 2.1 to 6.1. The robust trend is 19.1% vs 16.3%; the gain in RRt comes mostly from a reduction in the pain component, the average retracement dropping from 7.3% to 2.8%. The win rate is 43%. This higher return was realized with just 55% in-market.

    Close the equity window and click the point 2 trading system.

    Once again, zoom-in the equity curve for the signal and underlying:

tutorial2R7.png

This upper plot contains the equity curve for system 2 and for an EM signal representing this this same estimated EM length and lag fraction on the tradescape surface. The yellow equity curve is for the EM signal. The cyan equity curve is for signal 2. The RRt increased from 2.1 to 9.2. The robust trend is 24.4% vs 16.3%; the gain in RRt comes mostly from a reduction in the pain component, the average retracement dropping from 7.3% to 2.3%. The win rate is closer to 44%. The higher return was realized with the same 55% in-market.

    Choose the Format Analysis Techniques... option in the TradeStation right click menu in the chart, select the TSSigEval_T6 technique, click on Status to turn it back On, and click on Format. On the Inputs tab, change the Reserved value to 0. Set the WalkFwd value at 11327 and then click OK.

tutorial2R8.png

We note that this year of changed market state resulted in higher EM lengths being estimated for the trading signals. The difference is small, but in the opposite of the direction desired.

    Zoom-in a narrow X-region of the graph:

tutorial2R9.png

We liked signals 2 and 9 in the design step. We like them as well in the blind one year walkforward.

For this one-year blind period, we need to improve upon a 1.4% robust trend and an RRt of 0.19.

    Click on the system 9:

tutorial2R10.png

We do so handily, a robust trend of 13.3% and RRt of 6.7. In this more trying period, the lag at the turns of this mixed order-chaos type of signaler increased, from 18 to 20, the epsilon coming much more into play. The win rate is only about 34%.

    Click on the system 2:

tutorial2R11.png

We also do well, a robust trend of 10.7% and RRt of 6.6. The lag at the turns increased here as well, from 21 to 23, again the epsilon coming more into play. The win rate is 35%.

Note that the epsilon can reduce lag as compared to the two-pass signalers, but the scatter of the lag becomes greater, and the accuracy generally worsens. In this case, the additional complexity only slightly improved the reward-pain.

Step 8: Evaluate Real World Breakout Signals Against the YG 30min Tradescape

In the first tutorial, we discussed price band signaling. This adds a certain chaotic processing component to the signaling. Here again, we will use the simplest form of an envelope signaler, price breakouts. The bands are formed by the highest high and the lowest low in a specified window. The upside and downside transition windows can be of different lengths.

In a breakout, one enters long when the highest high (HH) of the preceding specified count of bars is surpassed during or at the close of the current bar, and exits long when the lowest low (LL) of its preceding count of bars is broken in a price decline. When one trades bands in this manner, one signals on the potential trending of the prices. There can be a significant difference between the upper and lower bands at any given point, depending on volatility, especially the average true range volatility that would fit very closely with this type of signaling.

Whipsaws usually do not occur because of the width of the price band, and one does expect to be out of the market for a good period of time owing to the barrier to entry, and sometimes to endure long in-market indeterminate periods owing to the barrier to exit.

    Find the instance of the Tradescape Platform from step 5. It will be the only one with nine panels.

    Click on the Toggle Between Default (0.7-1.2) and Wide (0.5-1.5) Lag-Fraction Y Axis button to automatically expand the lag fraction bounds.

tutorial2MD.png

The signal asymmetries vary from 0.25 (fast to enter, slow to exit) to 4.0 (slow to enter, fast to exit) across the panels. There is some indication that a 1.25-1.5 asymmetry offers greater lag tolerance at the sweet spot. For our breakout system study, we will adjust accordingly.

We will begin by evaluating 12 different breakout pairs as candidate trading signals. From our experience, we know that the 18 EM Length zone will typically be covered by breakouts in the 25-40 HH and LL lengths. We furnish a simple TSBreakout function to signal breakouts from the highest high and lowest low.

    From the TradeStation Development Environment, select the TSSigEval_T6 tab (if it is not open, use File | Open, choose Indicator from the dropdown and select TSSigEval_T6). Immediately use File | Save As and rename TSSigEval_T6 to TSSigEval_T7.

Change the line

   String SignalTitle("TSSigEval_T6"), // signal title to be added to the Tradescape plot

      to:

   String SignalTitle("TSSigEval_T7"), // signal title to be added to the Tradescape plot

    Delete all of the lines between these two markers:

   { ---------------------------------------------------------------------------------------------------------------
      Begin user-defined signal region of code, add up to 15 Signals
      --------------------------------------------------------------------------------------------------------------- }

 

   { ---------------------------------------------------------------------------------------------------------------
      End user-defined signal region of code
      --------------------------------------------------------------------------------------------------------------- }

    Insert the following between these two markers:

   Signal[0] = 12.0; // signal count

   Signal[1] = TSBreakout(PriceHi,PriceLo,20,20);

   Signal[2] = TSBreakout(PriceHi,PriceLo,25,20);

   Signal[3] = TSBreakout(PriceHi,PriceLo,30,20);

   Signal[4] = TSBreakout(PriceHi,PriceLo,35,20);

   Signal[5] = TSBreakout(PriceHi,PriceLo,25,25);

   Signal[6] = TSBreakout(PriceHi,PriceLo,30,25);

   Signal[7] = TSBreakout(PriceHi,PriceLo,35,25);

   Signal[8] = TSBreakout(PriceHi,PriceLo,40,25);

   Signal[9] = TSBreakout(PriceHi,PriceLo,30,30);

   Signal[10] = TSBreakout(PriceHi,PriceLo,35,30);

   Signal[11] = TSBreakout(PriceHi,PriceLo,40,30);

   Signal[12] = TSBreakout(PriceHi,PriceLo,45,30);

    Verify the technique and keep the development environment window open--we will revisit this process for the other types of signals.

    Insert the modified TSSigEval_T7 analysis technique with the following settings and click OK.

tutorial2S1.png

We will once more reserve the most recent year of data.

The default value for TSSigEval's Maximum number of bars the study will reference in the General tab (MaxBarsBack) of 125 will generally suffice for all breakouts.

tutorial2S2.png

We selected a mix of simple HH,LL breakouts that our experience suggested would cover the target time horizon. Signal 1 is the standard turtle (20,20) setting. Even though breakouts are assumed to process more of the chaotic movements, we don't see the same benefit we saw from the direct signaling.

While hardly a full confirmation, we do see improved RRT near the EM Length=18 sweet spot. We added many breakout pairs that utilized the asymmetry we found in the signaling, but the benefits still appear limited.

    Place the mouse cursor on the point for trading system 12:

tutorial2S3.png

There is nothing exceptional about the system. The RRt is good, 4.68, but the trend is 14.7%, the lag is high 207 bars, and the coverage error at the turns is poor, 21%, but largely expected from a traditional breakout.

    Click on system 12.

    Once again, zoom-in the equity curve for the signal and underlying:

tutorial2S4.png

This upper plot contains the equity curve for system 12 and for an EM signal representing exactly this same estimated EM length and lag fraction on the tradescape surface. The yellow equity curve is for the EM signal. The cyan equity curve is for signal 12. Breakouts can miss a good degree of the price action since their function is mainly to identify trends and jump on board. The signal 12 breakouts produce just a 46% in-market.

    Choose the Format Analysis Techniques... option in the TradeStation right click menu in the chart, select the TSSigEval_T7 technique, click on Status to turn it back On, and click on Format. On the Inputs tab, change the Reserved value to 0. Set the WalkFwd value at 11327: and then click OK.

tutorial2S5.png

The blind walkforward does somewhat confirm the EM length 18. The lower EM lengths do have a weaker reward-pain. The system we selected, signal 12, performed respectably for RRt. We have the same 1.31 underlying RRt.

    Click on system 12.

    Once again, zoom-in the equity curve for the signal and underlying:

tutorial2S6.png

The win rate was 40% on 110 trades. In-market is just 43%. There is a marked reduction in the pain, the average retracement dropping from 7.3% to 1.9%. The RRt increased from 0.19 to 2.65. The fitted trend improves from 1.4% to 5.3%, much less than we saw with the direct signaling. One need not look too hard for an explanation as to why breakouts, despite their lower lag, performed less effectively. The microstructure is suggestive of the optimal breakout being nowhere constant.

Step 9: Evaluate Real World Moving Average Crossover Signals Against the YG 30min Tradescape

An intraday tutorial would be incomplete without including an example of a "sympathetic" or "correlational" signaler. Here one computes something that should correlate with price trends in a very "fuzzy" but consistent way. A great many intraday systems use such signaling. As in the first tutorial, we will use the simplest form of such a signaler, the moving average crossover. We will again employ it in the typical scenario of a long-term central channel and a short term sentiment component. It this context, an MA crossover is a sentiment segmentation technique. There is positive market sentiment when above the long term line and negative sentiment below. It can be an effective intraday trading paradigm, and one of the reasons the professional version of the platform offers two-stage sentiment-augmented signaling we call Sentimentscapes on an intraday basis.

Especially when working with MA crossovers, you must insure the TradeStation MaxBarsBack setting (the Maximum number of bars the study will reference in the General tab) is high enough to accommodate the signaling algorithms that will be called. TSSigEval is set to a user-defined value of 125. You will need to increase this if more bars than this are used in any of the MAs. In this tutorial no adjustment is needed.

    From the TradeStation Development Environment, select the TSSigEval_T7 tab (if it is not open, use File | Open, choose Indicator from the dropdown and select TSSigEval_T7). Immediately use File | Save As and rename TSSigEval_T7 to TSSigEval_T8.

Change the line

   String SignalTitle("TSSigEval_T7"), // signal title to be added to the Tradescape plot

      to:

   String SignalTitle("TSSigEval_T8"), // signal title to be added to the Tradescape plot

    Delete all of the lines between these two markers:

   { ---------------------------------------------------------------------------------------------------------------
      Begin user-defined signal region of code, add up to 15 Signals
      --------------------------------------------------------------------------------------------------------------- }

 

   { ---------------------------------------------------------------------------------------------------------------
      End user-defined signal region of code
      --------------------------------------------------------------------------------------------------------------- }

    Insert the following between these two markers:

   Signal[0] = 9.0; // signal count

   Signal[1] = TSMACross(Price,0,75,6);

   Signal[2] = TSMACross(Price,0,75,7);

   Signal[3] = TSMACross(Price,0,80,7);

   Signal[4] = TSMACross(Price,0,65,8);

   Signal[5] = TSMACross(Price,0,75,8);

   Signal[6] = TSMACross(Price,1,80,8);

   Signal[7] = TSMACross(Price,0,65,9);

   Signal[8] = TSMACross(Price,0,75,9);

   Signal[9] = TSMACross(Price,1,80,9);

    Verify the technique.

    Insert the modified TSSigEval_T8 analysis technique with the following settings and then click OK:

tutorial2T1.png

We continue to reserve the most recent year of data.

There is a close correlation between the sweet spots in a comprehensive MA crossover optimization and the lengths needed to achieve the desired EM length of the signaler. Because of the indirection, you may find it necessary to perform that optimization in order to find the lengths needed to realize the target time horizon in the tradescape.

We did not do that here. We used the values from the first tutorial which targeted an EM length of 22 and linearly scaled both MA values for an EM length of 18. There was no optimization on YG of any kind.

Moving average crossovers are all about information content. In general, there is no advantage in using the various FIR-type weighted moving averages; in fact the WMA usually produces poor crossovers. Adaptive MAs are usually a bad idea for the same reason. In this analysis, as in the first tutorial, we included mostly SMA crossovers. We add two EMA crossovers for an IIR reference.

tutorial2T2.png

Signals 6 and 9 are the EMA crossovers. Despite the lower lag, the EMA results are not surprising. It is expected given the manner in which information content is integrated in an IIR filter. The errors at the turns for signals 6 and 9 are higher than all of the SMA crossovers.

SMA crossovers 4 and 7 offer lower lag and a good RRt performance. For this time period, they did well in mapping the YG market sentiment. The lower lag from signals 4 and 7 derive from the fact these use the shortest length for the central channel component, 65, as compared to 75 or 80 for the others.

    Place the cursor on signal 7:

tutorial2T3.png

The coverage errors of 20.1% may seem high, but this is very good for a crossover and sympathetic signaling. The positive and negative sentiment states signaled from the crossover correspond as well to the price movements as the selected breakout did. The trend is very good, 18%, the RRt good at 5.67, and the lag at 19.6 bars is similar to the other systems. The higher scatter of the lags (8) is expected with this type of signaler.

    Click the system 7 point and once more zoom-in the equity curve for the signal and underlying:

tutorial2T4.png

The upper plot contains the equity curve for system 7. The fitted trend of 18% compares favorably to the breakout system. The win rate is low 38%, and the time in market is 56%. The RRt improves from 2.1 to 5.7.

    Choose the Format Analysis Techniques... option in the TradeStation right click menu in the chart, select the TSSigEval_T8 technique, click on Status to turn it back On, and click on Format. On the Inputs tab, change the Reserved value to 0. Set the WalkFwd value at 11327: and then click OK.

tutorial2T5.png

Systems 4 and 7 look best within the blind walkforward. The EMAs again tested with lower lag, but poorer performance.

    Click the system 7 point and once more zoom-in the equity curve for the signal and underlying:

tutorial2T6.png

The blind walkforward of the MA crossover system has a robust trend of 8.2%, a 35% win rate, 52% in market, and an increase in the RRt from 0.19 to 3.05. Like the breakout system, the selected MA crossover did not fare as well as the direct signaling systems.

    To close all Tradescape windows currently open in a single step, right click the icon on the taskbar and choose Close All Windows.

Signaler Choices and a Knowledge Base

Most intraday trading systems are more sophisticated than those tested here, and many enter into trades only when a specific and often complex set of conditions occur. The basic signaling algorithms used in this tutorial were included primarily for their simplicity and the fact most traders are familiar with them.

There is the well-known argument that is it wise to use the simplest system possible that achieves the intended result. By entity selection, bar density selection, and targeting the optimal time horizon, it is sometimes possible to employ a basic signaling algorithm. For certain entities, there may be no bar density or time horizon where such signalers generate any benefit. To trade order with simpler signals, the trends must have a certain persistence, and their formation and decay can't be so wild and chaotic that they break the algorithm.

Once one is familiar with what a given signaling system or strategy delivers in terms of time horizon and lag fraction, and how much penalty one typically pays for inaccuracy, one look at an entity's tradescape will usually tell you whether or not it is likely that it can be successfully traded with that system.