Measuring the Summer Calm With TradeStation’s Custom Functionality

1203

Stocks have enjoyed a calm drift higher since the beginning of May. But just how smooth has the ride been? Today we’ll answer that question using TradeStation’s award-winning platform.

One approach is to measure the amount of time since the S&P 500 last had a significant decline. After all, bearish periods tend to have sharper declines because sellers have more control over the price action.

Let’s begin by asking, “how long has it been since the S&P 500 fell at least 3 percent drop in a single day?” And, “how does it compare with earlier history?

S&P 500, daily chart, with “Bars since X% move” custom indicator.

The answer to the first question is that the S&P 500 last had a 3 percent pullback on August 26, 2022, or 453 sessions ago. (Those are trading days, not calendar days.) It’s the longest streak since August 20, 2015, when the index went 949 sessions without a 3 percent pullback. Before that, the longest streak without a 3 percent decline ended on February 26, 2007, after 988 sessions.

From these points data, we might believe that yes, the S&P 500 has gone a relatively “long time” without a “big pullback.” But how did we get this information?

Custom Indicator

The chart above includes a custom indicator called “Bars since X% move,” available for download here. It’s written in TradeStation’s EasyLanguage, which lets customers program a wide range of indicators and strategies (including systems to automate trading).

Customize indicator dialog box showing input tab. The Style and Color tabs are also marked.

Traders can import Bars since X% move by double clicking on the “BARS SINCE X MOVE.ELD” file contained in the zip file. It can then be added to charts by clicking Studies → Add Studies… It will use the time interval of the chart. That means it seeks daily moves on daily charts, weekly moves on weekly charts, etc.

By default it looks for positive moves of 5 percent. Users can change this criterion with the Customize Indicator dialog and clicking on the Inputs tab. The threshold input should be changed to “-3” for the analysis performed above. Note: The Color tab can adjust the indicator’s color and the Style tab controls attributes like line thickness.

Using EasyLanguage

Traders can also click the “Edit EasyLanguage” button at the bottom of the same dialog to see the code we’ll now explain.

The first important line is the inputs, which tells TradeStation which values to accept from the user. “(5)” is the default value:

Inputs: 
threshold(5); // Percentage change threshold as a number, integer or decimal.

It next declares a series of variables. The first stores percentage changes for each bar. The second variable bookmarks when a change of the desired size occurs. The third is used to calculate the period of time between the targeted moves. “(0)” at the end of each variable sets default values of zero:

Vars: 
pct_cng(0), // Variable to store percentage change of the current bar
start_counter(0), // Variable to store the bar number when the desired change occurs
output_val(0); // Variable to store the output value (number of bars since the specified change)

The third step is to calculate the percentage change of each bar. Note that close[0] is the closing price of the current bar, while close[1] is the closing price one bar prior.

pct_cng = ((close[0] / close[1]) - 1) * 100;

Coding the Logic

The next section performs the main logic. If the customer is looking for a positive percent move, it looks for a percent move greater than the threshold. For negative thresholds, it seeks moves that are less than the inputted value. When a move of the desired magnitude is detected, it remembers the bar number. (Bars are numbers from older to newer.):

// Handle positive threshold values
If threshold > 0 and pct_cng > threshold Then
begin
start_counter = CurrentBar;
end;

// Handle negative threshold values
If threshold < 0 and pct_cng < threshold Then
begin
start_counter = CurrentBar;
end;

Returning Data to User

So far, the code looks at each bar to find moves of a certain percent. When such a move is detected, it saves the bar number to the variable start_counter.

The next step is find the distance from that past event to the present time. This next line performs the calculation by finding the simple difference between the saved bar number and the current bar number:

output_val = CurrentBar - start_counter;

Finally, the value is displayed to the user with “Plot.” EasyLanguage can output several values with plot, which is why this code shows “Plot1.” It could also have Plot2, Plot3, etc, if needed:

Plot1(output_val, "Bars since X move");

In conclusion, this indicator uses EasyLanguage to answer a question about the market. It’s one of the many examples of how TradeStation can provide customers with valuable insights. See our educational events for more information and training.


Please add the awards disclosure: Visit www.TradeStation.com/Awards to learn more.  

Advertisement
Trade in milliseconds

Explore the most actively traded options

Trade 600+ futures products on an advanced platform

Previous articleTechnology and the Nasdaq Surged Back to Life in June
Next articleKey Points About Selling Credit Spreads
David Russell is Global Head of Market Strategy at TradeStation. Drawing on nearly two decades of experience as a financial journalist and analyst, his background includes equities, emerging markets, fixed-income and derivatives. He previously worked at Bloomberg News, CNBC and E*TRADE Financial. Russell systematically reviews countless global financial headlines and indicators in search of broad tradable trends that present opportunities repeatedly over time. Customers can expect him to keep them apprised of sector leadership, relative strength and the big stories – especially those overlooked by other commentators. He’s also a big fan of generating leverage with options to limit capital at risk.