Tutorial 16 | TradeStation strategy based on candlestick patterns & stochastic crossovers

Tutorial 16 – Create a strategy that creates buy/sell signals based on Candlestick patterns and stochastic crossovers

The original tutorial 16 ran into some issues with the updated optimizer engine because it does not allow drawing objects to be present during a normal optimization. The new version of the program (available for download below) tests whether the program is optimizing, if not the drawing objects are drawn. The new version also has additional comments and the data types are set for variables and inputs.

Welcome to tutorial 16 in this series of tutorials designed to demonstrate and explain TradeStation EasyLanguage programming concepts. The idea behind the series is that if you learn the TradeStation EasyLanguage yourself, you will have a skill that will enable you to program and try out trading ideas whenever you want.

Markplex Tutorial 16

As always, the purpose of this tutorial is to demonstrate the programming techniques rather than to create a tradable indicator. See the disclaimer at the end of this page. I am using TradeStation version 8.1 to create this tutorial.

You may wish to develop a strategy where you look for one signal – and then wait for a confirming signal. This confirming signal may happen on the same bar as the original signal. On the other hand, it may occur a few bars later – and this may be acceptable for your trading strategy. An example of this would be a strategy where we look for a candlestick signal and then wait for a stochastic crossover as a confirmation. Obviously there will be a stochastic crossover at some point in the future and so we need to limit the number of bars after the candlestick pattern has occurred for the crossover to trigger a trade.

This step-by-step tutorial will guide you through several techniques including: using EasyLanguage’s built in candlestick pattern functions, drawing a character(s) on the chart when a candlestick pattern has occurred, using EasyLanguage StopLoss and ProfitTarget functions, finding stochastic crossovers and looking for confirmation signals a user-defined number of bars after an initial ‘warning signal.’ I am using an initial candlestick signal followed by a confirming stochastic signal in this tutorial, however it could be modified to use a different pair of indicators. I have applied this strategy to a daily EURUSD chart. It could also be applied to intraday charts.

The following chart shows an entry signal resulting from this strategy.

Markplex Tutorial 16

You may follow the tutorial and copy and type the program to try it out. If you would prefer to cut down your typing, you may, for nominal fee of $39.95, download the program by click the ‘add to cart button.’ After payment, your software is available for immediate download.

Step 1

To start, create a new strategy (press CTR-N, select the EasyLanguage tab, click on strategy and delete all the initial contents of the strategy). The first task to to apply some EasyLanguage candlestick functions to show candlestick patterns. TradeStation provide many candlestick pattern functions. To see them all, try typing “candlestick” into the TradeStation user guide. We are going to use 3 patterns in this tutorial: bullish/bearish Harami, bullish/bearish engulfing and 3 White Solidiers/3 Black crows.

Enter the following (ignore the color blocks – I added these for clarification):

Markplex Tutorial 16

I separated the different functions’ variables so that they appear just above the function call. Remember that with functions the outputs look a little like inputs. For example, with the function: C_3WhSolds_3BlkCrows( Length, Percent, o3WhiteSoldiers, o3BlackCrows ) the outputs are actually o3WhiteSoldiers and o3BlackCrows. If either of these outputs is equal to 1 it means that the candlestick pattern has occured. If it has we draw a letter on the chart at the corresponding bar, for example:

if o3WhiteSoldiers = 1 then
begin
VALUE1 = TEXT_NEW(D,T,(L – L*ADJ),”3c”); {Three White Soldiers}
TEXT_SETCOLOR(VALUE1,Green);
TEXT_SETSTYLE(VALUE1,2,1);
end;

The following shows the result of applying this strategy to a chart. Notice that I placed the characters above the high of the bar by adding an adjustment input (H + H*ADJ) and below of the lows by subtracting an adjustment (L – L*ADJ).

Markplex Tutorial 16

Step 2

Once the candlestick pattern has occurred we need to start counting bars so that we can test that the confirming pattern has occurred within a certain number of bars. Make the following modifications to your existing program.

Markplex Tutorial 16

With these changes we increment 2 variables: AfterBullCandle and AfterBearCandle every bar. When a candlestick pattern is detected the appropriate counter is reset to zero.

Markplex Tutorial 16

The input value MaxAfterCandle is the number of bars after a candlestick signal that the stochastic crossover will still trigger a signal. I have printed the AfterBearCandle and AfterBullCandle counters on the chart. These will be removed in the final version, but are useful in making sure that the program is performing as expected. This is a very useful technique to use as you develop programs. Notice that I set the initial values of AfterBearCandle and AfterBullCandle to be equal to MaxAfterCandle + 1. This is to make sure that we don’t get a false trigger at the start of the chart – even though a candlestick pattern has not occurred.

Step 3

The next step is to add the stochastic function to the program – together with the necessary inputs and variables. Make the following modifications to your program:

Markplex Tutorial 16

This adds the stochastic function but does not do anything with it. In the next step, we will look for stochastic crossovers and also add a stop loss and profit target function.

Step 4

Markplex Tutorial 16

and add the following at the bottom of the strategy. Notice that the lines that ‘printed’ the bar numbers have been “commented out” by putting a “//” in front of the line. The next lines test for a stochastic crossover together with a count less than the MaxAfterCandle number of bars. To understand how the SetStopLoss and SetProfitTarget work, enter them into TradeStation and right click the words and click on “definition of …” .

Markplex Tutorial 16

After making these changes and verifying the program (press F3 while in the program entry windows). Apply to a chart (if you have not already done so), and view the results. Here is an example of what you might expect.

Markplex Tutorial 16

To aid your understanding of what is going on, you could add a stochastic indicator to the chart. CAUTION: make sure you use the same parameters that you are using in the strategy, or you will confuse yourself as to why certain trades happen at certain times.

Strategy property controls can be used to determine some aspects of how the strategy works and is backtested.

You may, for nominal fee of $39.95, download the program by click the ‘add to cart button.’ After payment, your software is available for immediate download.

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.

If you see any errors in this tutorial – or I have not made something clear, please let me know. You can e-mail me at: tutorials@markplex.com. Also, let me know if you have any ideas for new tutorials.

Disclaimer The information, materials, products and services on this Web site are made available subject to the following terms and conditions. Markplex Corporation reserves the right to change these terms and conditions at its sole discretion. This Web site and any downloads, videos, tutorials, programs and information contained herein is presented solely for educational, informational, and/or entertainment use and under no circumstances should be used for actual trading. We at Markplex Corporation are not Broker/Dealers, Financial Advisers or Registered Analysts. No offer or solicitation to buy or sell securities, securities derivatives, futures products or off-exchange foreign currency (forex) transactions of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given or in any manner endorsed by Markplex Corporation. You are fully responsible for any investment or trading decisions you make. Futures and options trading has a large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. This Web site is neither a solicitation nor an offer to buy and/or sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this Web site. Past performance, whether actual or indicated by historical tests of strategies, is no guarantee of future performance or success. No warranties of profitability are being made or given. There is a possibility that you may sustain a loss equal to or greater than your entire investment regardless of which asset class you trade (equities, options futures or forex); therefore, you should not invest or risk money that you cannot afford to lose. CFTC RULE 4.41 - Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. Screen shots on this site are examples and are not meant to imply that any of the programs or tutorials available on this Web site will generate profitable trades. EasyLanguage or PowerLanguage trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (and parts thereof) and associated techniques referred to, included in or attached to this tutorial or program description are examples only, and have been included solely for educational, informational, and entertainment use. Markplex Corporation does not recommend that you use any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (or any parts thereof) or techniques. The use of any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions and techniques does not guarantee that you will make profits, increase profits, or minimize losses. Markplex Corporation assumes no liability for any damages, direct or otherwise, resulting from the use of this information and/or program(s) described, and no warranty is made regarding its accuracy or completeness. Use of this Web site including the information, tutorials and/or programs included on it is at your own risk. You shall indemnify and hold Markplex Corporation harmless from any and all liability, loss, trading losses, costs, damage, or expense, including attorneys' fees you or third party may suffer (other than damage to your tangible property or injuries to employees occurring during the course of work) as a result of claims, demands, costs, or judgments arising out of third party and any other claims based on Markplex Corporation's performance, including, but not limited to losses resulting from the use of Markplex Corporation developed software, programs, web sites, tutorials, or the TradeStation charting and/or trading platform. Any testimonials on this Web site may not be representative of the experience of other clients and are not indicative of future results or success.
This Web site contains or may contain references and links to other companies and/or their Web sites, none of which is under the control of Markplex Corporation. Markplex Corporation makes no representations, warranties or endorsements whatsoever about any other Web sites to which you may have access through the Markplex Corporation Web site, or any products or services of those other companies, even if the products or services of those other companies or their Web sites are described or offered on the Markplex Corporation Web site or integrated with Markplex Corporation's products or services. TradeStation®, EasyLanguage® and PowerEditor® are registered trademarks of TradeStation Technologies, Inc. Other brand and product names which appear on this site are the trademarks or service marks of their respective owners, including: Microsoft® is a registered trademark in the United States Microsoft®Excel® is a registered trademark of Microsoft® Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.

By continuing to use and navigate our sites, services, applications, tools or messaging, you are agreeing to our Terms and Conditions and the use of cookies, web beacons and similar technologies as described in our Privacy Policy and Privacy Policy on the use of cookies.