This article deals with a tool to help you test various stops when building trading systems in TradeStation’s EasyLanguage. This topic is really a part 2 of the article, “Advanced Stops and Targets Strategy Tool“. In the original article the created tool called _Stops&TargetsAdvanced is a simple strategy based on an existing TradeStation strategy called _Stops&Targets. I took this program and modified it with several other exit techniques and made it available.
The original _Stops&TargetsAdvanced strategy tool could be applied to any strategy you’re working on to aid in testing various stops. With this tool you can quickly test several popular stops without writing any code. The stops were all based upon the same time frame you were currently trading. In TradeStation lingo, that’s your data1 feed. However, what if you wanted to base your stops on a different time frame? In this article I’ve created a modified strategy tool that will help you test various stops on a different time frame.
I created a new strategy tool called _Stops Higher Time Frame which takes data from a different data stream other than the instrument you’re trading. Most of the time, this second data stream will be data2. This will allow you to generate stop values from a different time frame from the one you are trading on. For example, if you’re trading the S&P eMini on a 5-minute chart you can now test various stops on a 30-minute time frame or any other time frame. However, the data stream number is actually controlled by an input value. Thus, it’s possible to take signals from data3, data4, or whatever you like. This provides you with the flexibility of controlling exactly what data stream your stop values will be generated from.
Below is an image of the _Stops Higher Time Frame strategy applied to a chart. You can see this strategy is running parallel with another strategy called RSI2 Simple which uses a two-period RSI to generate buy signals when price closes below the value five. All exit signals are generated by the _Stops Higher Time Frame strategy.
Because the new strategy tool generates stop values from a higher time frame, you will need to have Data2 defined within your trading chart. This is simply done by importing a new symbol into your existing chart and selecting the Data2 option.
Types of Stops
There are a total of eight different stops you can test. They are listed below. Of course, there is nothing stopping you from adding additional stops to this strategy tool. The code is freely available for you to download and modify at the bottom of this article.
- Bar Count Exit – Exit a position based on the number of bars since the position was opened.
- ATR Hard Stop – Exit a position based on the average true range of the market. This is a fixed stop loss. In other words, the stop does not advance as a position moves in your favor. However, the value of the stop loss is updated on each bar close to adjust for the current market ATR.
- ATR Trail – Trailing stop based on the average true range of the market.
- Square Root ATR Trail – This simply takes the square root of the ATR value. What this does is reduce the variablility of each reading. You can read more here.
- Noise Tolerant Stop – This technique is based upon the article, “A Noise Tolerant Money Management Stop“, and provides a linear regression-based stop which is also a non-optimized-based exit.
- Moving Average Exit – Exit a position based upon when price crosses beyond a simple moving average.
- RSI Exit – Exit a position based on an RSI value.
- Day Of Week Exit – Exit a position based upon the day of the week. By using this stop you can close all positions on a specific weekday, such as Friday.
Input Values Explained
Next I will explain the input values.
- ShareOrPosition – Should P&L be calculated based on per share or position bases.
- DataNum – This is where data stream takes signals from. In most instances the value will be 2 indicating data2.
- ExitToTest – This indicates which stop to test. At the time of this writing there are eight stops to test. Simply enter the digit (see above, Types of Stops) of the stop to activate.
- NumBars – The number of bars to exit a position since opening the trade.
- ATRLen – The number of bars to use in ATR calculation.
- ATRMult – This number is the ATR multiple. The value is multiplied by the ATR to generate a final value.
- NTStop_N – The look-back period for the noise tolerant stop.
- MALen – The look-back period to use for the moving average-based exit.
- RSILen – The look-back period to use for the RSI-based exit.
- iDayOfWeek – The day of week to exit. 1 for Monday and 5 for Friday.
Exiting Based on A Different Instrument
I originally created this strategy tool to be used on a higher time frame. However, there is nothing stopping you from using a different instrument to trigger your exits. Since signals to exit are being generated on a different data stream that the instrument you’re trading, that means you really could use anything. For example, instead of exiting your Apple shares on a daily chart, you exit when the QQQ fall below a moving average. So, using this tool opens up the possibilities beyond different time frames.
Closing
I would suggest reviewing the first article in this series, “Advanced Stops and Targets Strategy Tool“. On that page you will find video instructions on the original stops and targets tool which will go a long way in helping you here. Overall, this is a very simple strategy tool which can be rather helpful. The _Stops Higher Time Frame strategy tool is really a framework from which you can add your own stops.
Jeff,
Your site is a treasure of good will and great information. Thank you for your work!
This code will not import or verify if copied and pasted into TS. You did not define the variable MP (e.g. Vars: MP(0);) or include a statement like MP = MarketPosition. Also NTStop_Data2 is similarly not defined as a variable. If I do define it
Vars: NTStop_Data2(0,Data2);
I still get an error message saying a close parenthesis is expected after “NTStop_Data2” in the statement below:
Begin
SetDollarTrailing( NTStop_Data2( NTStop_N, Interset ) * Bigpointvalue );
End
I am using TS 9.1 Update 29. Not sure if program might work on another version.
Alan, NTStop_Data2 is not a variable. It’s a function. If you’re using TradeStation you’ll want to import the ELD which contains all the required components. Hope this helps!
Jeff,
I was able to import the Higher Time Frame Stops Strategy Tool,so please disregard my previous comments. Importing worked when I shut down TradeStation completely. I think I had previously tried to import when the program was open, and in that state I could not import the strategy. Thanks for the tool.
Glad you got it working Alan.
Could you please provide the text for the function, NTStop_Data2
so that I can copy and paste it. Is the output of the function a numeric value as opposed to a Boolean (True/False) value? As I said above, I was unable to successfully import the ELD file, so I have to copy/paste the text, but the text you have given so far does not seem to include the text for the function.