price pattern detector (ppd) - featured products · pdf fileprice pattern detector ......

23
Price Pattern Detector (PPD) User Manual Version 1.1 Price Pattern Detector (later called PPD) is a Trading App developed by Gandalf Project Research team to identify price patterns, assess their robustness and create trading strategies. It uses the Genetic Optimization engine of TradeStation, with a user-friendly interface, to select entry and exit conditions, filters, money management. How does it work? PPD is made of a Trading App (interface), a strategy and several functions. The trading App has the purpose of collecting all the parameters and settings that are fed to the strategy and the TradeStation optimization engine. Thanks to the Trading App the user can also show the results of the processing. PPD will generate the easylanguage code of the trading systems. These trading systems will use the PPD functions. In order to understand how PPD works the following scheme represents a strategy template used by the software and the optimization engine: To better understand the structure of a “pattern” and the meaning of genes the following is an example of a pattern (2 patterns in OR) where the first pattern is made of 1 element and the second of 2. (closetoavgpriceratio(0)[1] < closetomedpriceratio(2)[6])or (closetoavgpriceratio(0) <= opentoopenratio(0)[4] and ORBP(10)[2] < opentomedpriceratio(5)[9]) Each gene can have a number as parameter (x) but also be referenced to a certain number of bars back [x]. Further details of the strategy structure can be learnt from the strategy example included in this guide (annex1). The full list of the entry and exit modes is indicated in annex2 of this manual. Entry Mode (29 different types) Long or Short PATTERN ENTRY Up to 3 patterns in OR made of up to 5 genes in AND Patterns can use up to 500 genes Pattern can include references to data2 and data3 Optional volatility and/or trend filter can be applied or optimized Exit Mode (9 different types) based on time in the market – Time exit can be also Stop&Reverse Exit Pattern Long or Short (can include time exit if loss/if win/always)

Upload: dinhthu

Post on 07-Feb-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Price Pattern Detector (PPD) User Manual

Version 1.1 Price Pattern Detector (later called PPD) is a Trading App developed by Gandalf Project Research team to identify price patterns, assess their robustness and create trading strategies. It uses the Genetic Optimization engine of TradeStation, with a user-friendly interface, to select entry and exit conditions, filters, money management. How does it work? PPD is made of a Trading App (interface), a strategy and several functions. The trading App has the purpose of collecting all the parameters and settings that are fed to the strategy and the TradeStation optimization engine. Thanks to the Trading App the user can also show the results of the processing. PPD will generate the easylanguage code of the trading systems. These trading systems will use the PPD functions. In order to understand how PPD works the following scheme represents a strategy template used by the software and the optimization engine:

To better understand the structure of a “pattern” and the meaning of genes the following is an example of a pattern (2

patterns in OR) where the first pattern is made of 1 element and the second of 2.

(closetoavgpriceratio(0)[1] < closetomedpriceratio(2)[6])or

(closetoavgpriceratio(0) <= opentoopenratio(0)[4] and ORBP(10)[2] < opentomedpriceratio(5)[9])

Each gene can have a number as parameter (x) but also be referenced to a certain number of bars back [x]. Further details of the strategy structure can be learnt from the strategy example included in this guide (annex1). The full list of the entry and exit modes is indicated in annex2 of this manual.

Entry Mode (29 different types) Long or Short PATTERN ENTRY

Up to 3 patterns in OR made of up to 5 genes in AND

Patterns can use up to 500 genes

Pattern can include references to data2 and data3

Optional volatility and/or trend filter can be applied or optimized

Exit Mode (9 different types) based on time in the market – Time exit can be also

Stop&Reverse

Exit Pattern Long or Short (can include time exit if loss/if win/always)

Page 2: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

System validation and use of the optimization engine As mentioned before, PPD will use the TradeStation optimization engine to find and simulate a combination of patterns and condition and create a list of trading systems. In order to have a proper selection of trading systems and consider a validation criteria PPD will not work on the entire historical data set available but will let the user select a number or years (and %) of In-Sample, Out-of-Sample and Real Money. During the pattern search PPD will use only the IS and OoS part of the historical data set and the user can select the % of OoS at the beginning or the end of the period. The last part of data (real money) is shown only at the end of the pattern search and it is never utilized by the optimization engine.

Is Sample Out of Sample Real money

Data used by PPD and TradeStation optimization engine to find a list of trading systems. OoS % on the total of IS+OoS can be set. OoS can be at the

beginning, at the end or both of this period.

These data are used and shown only at the end of the processing when the trading system is selected and the equity is shown on the screen.

How to use PPD

Once the Trading App is downloaded on the system a new icon will appear in the list of installed applications. The first time PPD is loaded it generates 2 files in the computer folder C:\Program Files (x86)\TradeStation Archives The generated files are: PPFSettings.config PPFTemplate.template The first file is a file where several settings are saved and the second is the strategy template used to generate the final trading system. Both are text files that can be edited with any text editor, like notepad. Normally there is no need to modify any of these two files.

Page 3: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

It might be useful to modify a setting in the config file related to the folder that PPD will use to store its files during and after the processing. The standard folder is the same where the 2 files are generated but this folder can be changed to a customized one. The annex 3 explains how to change this folder and the meaning of the various config file parameters. The main window of PPD stays always open and shows the processing log or any error that might happen since the app is loaded. The button Clear Log is used to clear the log field. The button Load previous pattern search is used to load any previous pattern search. Once a pattern search reaches the end or is interrupted by the user PPD will save the result of the processing to several files so that they are saved and can always be reloaded in a second moment. For more details on the files meaning and content refer to annex 4. The first button, Start Pattern Search, is the most important one as it is the starting point for any new pattern search. Once the button is pressed the following form will appear:

Page 4: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

This form is organized in several tabs, the first one we see here is Main Settings and it collects the settings related to the symbols used to perform the search, the genetic engine settings and some trend and volatility entry filters. PPD can use one symbol or a list of symbols for data1, data2 or data3. The use of different data means that each pattern (entry or exit) can use genes referred not only to the main symbol but also to a different symbol specified in data2 or data3. The trading system will than entry or exit on the symbol1 when a pattern occurs under certain conditions on data2 or data3 also. An example of a pattern based on different symbols/data is: (closetoavgpriceratio(0)[1] of data2 < closetomedpriceratio(2)[6] of data2) or

(closetoavgpriceratio(0) of data3 <= opentoopenratio(0)[4] of data3 and ORBP(10)[2] < opentomedpriceratio(5)[9])

Using a list instead of a single system will instruct the engine to rotate the symbols of the list and create all the possible combinations. The final list of trading systems will be based only on one symbol of the list(s). Bar type will determine which bar size PPD will use (Daily of xx mins). Type let the user chose the symbol type (Stock, Future, Forex), this setting will influence mainly the money management parameters. The filed Years of history is used to specify the number of years on which PPD will perform the trading system/pattern search. With reference to the previous paragraph, this filed represent the number of years of both IS and OoS and will so NOT include the real money. The number of years of real money are set with the following filed, Years of real money. The two following fields are used to specify the % (on the IS+OoS period) of OoS. The % can be at the beginning, at the end of on both sides of this period. The following group of settings are related to the genetic optimization engine of TradeStation. These settings are the same used in TradeStation so for a detailed explanation we suggest to refer to the help page: http://help.tradestation.com/09_00/tradestationhelp/optimize/advanced_optimization_options.htm The last group of settings, Trend and Volatility filters can be used to set certain long/short trend /volatility entry filters. The user can leave these 4 checkboxes disabled, set a specific filter or let the engine look for the best one. We will see later during this document that, once a list of trading system is generated, the user will be able to apply or search for additional filters/entry/exit criteria based on a specific trading system. The trend/volatility filters can be applied or optimized as a second step, as further optimization of a specific trading system. For a list of these filters please refer to annex 2.

Page 5: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Entry Pattern tab

The second tab, Entry Pattern, allows the user to specify every setting related to the entry pattern structure. Number of elements per pattern indicates the maximum number of elements per pattern so, if we specify 5 for example, the pattern can be made of 1,2,3,4 or 5 elements. For both Long and Short entry patterns the user can set or search the best entry mode and entry gap. (full list of entry modes is specified in annex 2). As we mentioned before a fine tuning of a strategy can be performed in a second run so the user might decide to leave entry mode 1 as setting for the first search. The check boxes Optimize related to pattern1, 2 or 3 will instruct PPD to search for 1,2 or 3 patterns (in OR) for Long, Short or both. As standard the form is checked to search for 1 pattern long only. Max bars back field is the max number of bars back that will be used in the gene. So if 5 is specified, the engine will look for a value between 0 to 5. With reference to the pattern used as example before (closetoavgpriceratio(0)[1] < closetomedpriceratio(2)[6]) bars back is represented by the 1 and the 6. The check boxes Use data 2 and use data 3 will be enabled only if a symbol2 and/or symbol3 are set in the main tab. These fields will instruct the engine to look for entry patterns that might refer to data2 and/or data3. In max X elements means that on a pattern made of Y elements a maximum of X elements might refer to data2/3.

Page 6: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

The following three checkboxes use < and <= operators, use = < <= operators and use = < <= > >= operators will determine the number of operators in each pattern to be used. Normally the first or second options are the best ones. Than the following checkboxes will instruct PPD engine on the groups of genes to consider for that pattern. The last option of this tab, If both pattern occurs give priority to, will instruct PPD to consider a long or short entry first if on the same bar both patterns (long/short) occur. This field has a third option that let PPD to search for the best choice using the optimization engine. Exit Long and Exit Short tabs

These tabs can be used to enable the search of an exit based on pattern. PPD has different exit types:

• time exit

• pattern exit

• pattern stop and reverse exit/entry The pattern exits can include a time exit after a certain number of bars anyway. An exit pattern can coexist with a time exit. The settings of the exit patterns tabs are the same of the entry pattern tabs, so we invite the user to read that section of the guide.

Page 7: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

There are only two fields that are different in the exit pattern tabs compared to entry tabs:

• Pattern intervenes when will indicate PPD to activate the exit pattern only when the trade is Winning, Losing or Always.

• Exit anyway after x bars will indicate PPD that even if no exit pattern conditions occur an exit will be sent after a certain number of bars anyway.

Time Exit tab

This tab collects every setting related to the exits based on time (number of bas in the trade). Exit mode number can be set to a specific exit mode (refer to annex 2 for more details), it can be searched/optimized or checking, Disable time exit long the exit based on time will be ignored. In this case a pattern exit must be activated. Disabling a time exit can be useful when stop and reverse exit is enabled. The most important setting related to the time exit is Exit after X bars which can be set manually or searched/optimized from a minimum of x to a maximum of x bars. Stop loss amount and Target amount can be set manually or searched/optimized by PPD. Normally these parameters are used if exit mode different than 1 is used. Several exits use a target or a stop loss so if you enable the optimization of the exit mode it is recommended to care about these values or optimize them in a coherent way. The same settings can be set for the time exit SHORT.

Page 8: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Stop & MM tab In this last tab there are several settings related to exit stop loss, money management and stop and reverse options.

Chandelier stop exit settings allows the user to enable the use of a chandelier stop exit where the lookback period can be set to a specific number of bars or optimized/searched by PPD within a specific range from/to number of bars. The increment can be specified as well. The standard deviation can be set to a specific number or optimized in the same way as the number of bars. The following group of settings is related to Position sizing that can be fixed (one contract or 100.000 EUR/USD) or percent volatility. A specific stop loss amount for both long and short can be also set here. The last checkbox allows the user to enable/disable the stop & reverse exits type. As mentioned in the form, this mode will use an entry pattern and exit (reverse) with a long or short pattern. The time exit will not act as reverse but will remain a normal exit (if enabled). Search window lower buttons

The search window has four buttons in the lower part: Start Pattern Search will launch the pattern search processing and hide the search window, See results will go back to the results windows if a previous search was completed, Load Strategy allows the user to load a previously created trading system. This feature is useful if the user wants to optimize or add specific filters to a strategy previously selected. As we will see later the search process will generate one file with the entire list of the best X trading systems found but also a file for each of these generated trading systems. (refer to Annex 4 for further details) These files can be opened here and further optimized.

Page 9: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Start Patter Search Once the user has set the relevant search settings the button Start Pattern Search will activate the TradeStation optimization engine with all the set parameters. During these steps the main windows log field will always be updated, so the user can move the widows on the screen in a way to always keep attention to what is shown in there.

Once the search start the progress form (Optimization evolution form) is shown on the screen.

Page 10: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

The chart shown on this form is not an equity line but it shows the progress of the fitness function improvement. In this example the fitness function chosen was the “net profit” so the vertical axis shows the value of the last best net profit found, on the horizontal axis the number of test made by the engine is displayed. Several other info is shown on this form to help the user understand the progress of the optimization: Elapsed time, Remaining time, Generation count, Individual count, Total runs, Average runs per minute, current fitness function and the best value found. The field Generation name is automatically generated by PPD but it can be changed to any text while the generation is in progress. This name will later represent the file name (and generation name) and the file root name for each trading system generated. A different name set by the user can help to remember the kind of search performed. (Ex “SPY with VIX entry and exit patter no time exit”). As explained before in this guide during this part of the processing only the IS and OoS data are considered by the system. The processing can be interrupted manually by the user at any time or it will stop at the expected time indicated by Remaining time. The processing can last much less in case there is no evolution in the fitness function after X runs. This setting is one of the optimization engine settings in the first tab of the search form we have seen before. Once the processing is finished or interrupted, PPD will need to reprocess each system found to generate the complete equity curve and in this case the last X years of real money will also be considered. This processing can happen individually when the trading system is selected (in the result windows which we will see in a few lines later) or the entire trading systems found list can be pre-processed in background. The pre-processing will take a long time and slow down the computer but will later speed up the equity curve display. This option can be enabled or disabled by the checkbox Write all equity file in advance. Normally it makes sense to leave it enabled if the user intends to perform the entire search till the end and not interrupt it manually and do this task during the night or when the computer is not used. Once the search is finished or interrupted the button See results will be enabled and the user can proceed to click on it in order to see the best X trading systems found.

Page 11: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Optimization Results form

This last form allows the user to see the results of the processing in a graphical way. The table located in the middle of the form shows the X best systems found by PPD per the fitness function selected and the other settings decided by the user. Clicking on each line will update the equity curve in the upper part of the form. If the equity curves were previously generated this step will be instant otherwise there will be a delay of few seconds for each new system selected as PPD will have to generate the equity file in real time. The curve displayed here is now made by the IS+OoS+Real money part, which is the green one. A good progress and coherence of the green part compared to the blue parts might show a certain stability in the patter performance and less risk of over fitting. It is clear that, the previously mentioned concept doesn’t represent in any way a certainty for the future but it is a pure application of the trading system generated on the full history of data. The lower left part of the form allows the user to filter the list of system applying several filters to the training systems metrics. Apply filters button will filter the list and if the checkbox Remove duplicates is enabled the operation will also remove the systems that seem having the same results (despite certain parameters or patterns are different). Remove filters will restore the full list of systems. The buttons Hide some columns and Show all columns will increase or reduce the number of columns in the table leaving the most important ones. The list of system can be sorted clicking on the column title. Clicking twice will invert the order sorting order.

An equity curve is normally displayed here but due to TradeStation App Store regulation it

can’t be shown in any document published on the store. We invite the user to test this feature

on the app directly.

Some performance metrics are normally displayed here but due to TradeStation App Store regulation it can’t

be shown in any document published on the store. We invite the user to test this feature on the app directly.

Page 12: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

The button EL Code and Details will show a form with the EasyLanguage code of the selected trading system. This code can be copied and pasted (right mouse click) in a new Tradestation strategy, compiled and applied to the symbol(s) used in the search. If one or more lists of symbols were used the header part of the code will show which symbols have to be used on that trading system as data1, 2 or 3.

This form has a second tab which shows the parameters found by the optimization engine and used to generate the final strategy code.

Page 13: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Annex 1 Example of a strategy generated by PPD

{************************************************************************************************************************}

{********* Begin *********}

{************************************************************************************************************************}

{

vars:

int type_of_instrument (1),

bool entry_long_pattern (true),

bool entry_short_pattern (false),

int enter_mode_pattern_long (1),

int enter_gap_pattern_long (0),

int enter_mode_pattern_short (1),

int enter_gap_pattern_short (0),

int enter_trendfilter_long (0),

int enter_trendfilter_short (0),

int enter_volafilter_long (0),

int enter_volafilter_short (0),

int enter_priority (0),

int exit_pattern_long_enabled (1),

int exit_pattern_long_type (3),

int exit_bars_number_pattern_long (200),

int exit_pattern_short_enabled (0),

int exit_pattern_short_type (3),

int exit_bars_number_pattern_short (200),

int exit_SR (0),

int exit_mode_long (1),

int exit_mode_short (1),

int exit_bars_number_long (9),

int exit_bars_number_short (3),

double stop_loss_amount_long (1000),

double target_amount_long (1000),

double stop_loss_amount_short (1000),

double target_amount_short (1000),

int chandelier_stop_enabled (0),

int chandelier_stop_period (20),

double chandelier_stop_stdev (1.0),

int position_sizing_mode (1),

double catastriphic_SL_amount (0),

{************************************************************************************************************************}

{********* Vars and arrays *********}

{************************************************************************************************************************}

bool L_entry_pattern_ok (false), // Identify if entry is allowed based on pattern

bool S_entry_pattern_ok (false), // Identify if entry is allowed based on pattern

bool L_exit_pattern_ok (false), // Identify if exit long is allowed based on pattern

bool S_exit_pattern_ok (false), // Identify if exit short is allowed based on pattern

bool trend_filter_long_ok (true), // true if trend filter is ok long

bool trend_filter_short_ok (true), // true if trend filter is ok short

bool vola_filter_long_ok (true), // true if volatility filter is ok long

bool vola_filter_short_ok (true), // true if volatility filter is ok short

double capital (100000), // Amount of capital to trade each operation

double quantity (0), // Number of contracts or number of shares to buy or to sell

int numContracts (1), // Number of contracts if future

double next_trade_risk (3000), // risk per trade in percent volatility

int position_sizing_perc_k (2); // position sizing K on ATR

{************************************************************************************************************************}

{********* Trend and volatility filters *********}

{************************************************************************************************************************}

if enter_trendfilter_long > 0 then

begin

Page 14: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

if enter_trendfilter_long = 1 then trend_filter_long_ok = C > average(c,20);

if enter_trendfilter_long = 2 then trend_filter_long_ok = C > average(c,200);

if enter_trendfilter_long = 3 then trend_filter_long_ok = C < average(c,20);

if enter_trendfilter_long = 4 then trend_filter_long_ok = C < average(c,200);

if enter_trendfilter_long = 5 then trend_filter_long_ok = (C > bollingerband(C,200,+0) or C < bollingerband(C,200,-2)) and C

<average(C, 5);

if enter_trendfilter_long = 6 then trend_filter_long_ok = (C > bollingerband(C,200,+1) or C < bollingerband(C,200,-2.5)) and

C <average(C, 5);

end;

if enter_trendfilter_short > 0 then

begin

if enter_trendfilter_short = 1 then trend_filter_short_ok = C > average(c,20);

if enter_trendfilter_short = 2 then trend_filter_short_ok = C > average(c,200);

if enter_trendfilter_short = 3 then trend_filter_short_ok = C < average(c,20);

if enter_trendfilter_short = 4 then trend_filter_short_ok = C < average(c,200);

if enter_trendfilter_short = 5 then trend_filter_short_ok = (C < bollingerband(C,200,-0) or C > bollingerband(C,200,+2))

and C > average(C, 5);

if enter_trendfilter_short = 6 then trend_filter_short_ok = (C < bollingerband(C,200,-1) or C > bollingerband(C,200,+2.5))

and C > average(C, 5);

end;

if enter_volafilter_long > 0 then

begin

if enter_volafilter_long = 1 then vola_filter_long_ok = avgtruerange(2) > avgtruerange(5)[1];

if enter_volafilter_long = 2 then vola_filter_long_ok = avgtruerange(2) > avgtruerange(20);

if enter_volafilter_long = 3 then vola_filter_long_ok = avgtruerange(2) > avgtruerange(200);

if enter_volafilter_long = 4 then vola_filter_long_ok = avgtruerange(2) < avgtruerange(5)[1];

if enter_volafilter_long = 5 then vola_filter_long_ok = avgtruerange(2) < avgtruerange(20);

if enter_volafilter_long = 6 then vola_filter_long_ok = avgtruerange(2) < avgtruerange(200);

end;

if enter_volafilter_short > 0 then

begin

if enter_volafilter_short = 1 then vola_filter_short_ok = avgtruerange(2) > avgtruerange(5)[1];

if enter_volafilter_short = 2 then vola_filter_short_ok = avgtruerange(2) > avgtruerange(20);

if enter_volafilter_short = 3 then vola_filter_short_ok = avgtruerange(2) > avgtruerange(200);

if enter_volafilter_short = 4 then vola_filter_short_ok = avgtruerange(2) < avgtruerange(5)[1];

if enter_volafilter_short = 5 then vola_filter_short_ok = avgtruerange(2) < avgtruerange(20);

if enter_volafilter_short = 6 then vola_filter_short_ok = avgtruerange(2) < avgtruerange(200);

end;

{************************************************************************************************************************}

{********* Money management simple *********}

{************************************************************************************************************************}

If type_of_instrument = 1 then quantity=capital/close;

If type_of_instrument = 2 then quantity=numContracts;

If type_of_instrument = 3 then quantity=capital;

{************************************************************************************************************************}

{********* Advanced position sizing - percent volatility *********}

{************************************************************************************************************************}

if (position_sizing_mode = 2) then

begin

If instr(symbolname,"JPY")>0 then next_trade_risk=next_trade_risk/100;

quantity = MaxList(0, IntPortion(( next_trade_risk/bigpointvalue) / (avgtruerange(2)*position_sizing_perc_k)));

end;

{************************************************************************************************************************}

{********* Pattern Farm Entry *********}

{************************************************************************************************************************}

If entry_long_pattern = true then

begin

L_entry_pattern_ok =

((closetoavgpriceratio(0)[1] < closetomedpriceratio(2)[6])) or

((closetoavgpriceratio(0) <= opentoopenratio(0)[4]) and (bodytorangeratio(2)[8] < opentoavgpriceratio(2)[4])) or

((ORBP(10)[2] < opentomedpriceratio(5)[9]));

end;

If entry_short_pattern = true then

begin

S_entry_pattern_ok = false;

end;

{************************************************************************************************************************}

{********* Entry priority choice *********}

{************************************************************************************************************************}

Page 15: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

if entry_long_pattern and entry_short_pattern and L_entry_pattern_ok and S_entry_pattern_ok and enter_priority = 0 then

S_entry_pattern_ok = false;

if entry_long_pattern and entry_short_pattern and L_entry_pattern_ok and S_entry_pattern_ok and enter_priority = 1 then

L_entry_pattern_ok = false;

{************************************************************************************************************************}

{********* Enter module *********}

{************************************************************************************************************************}

// Entry for LONG

If entry_long_pattern then

begin

If Marketposition = 0 and L_entry_pattern_ok and trend_filter_long_ok and vola_filter_long_ok then

begin

if enter_mode_pattern_long=1 then buy("eL_O") quantity shares next bar at open;

if enter_mode_pattern_long=2 then buy("eL_L") quantity shares next bar at low limit;

If enter_mode_pattern_long=3 then buy("eL_L_2") quantity shares next bar at lowest(Low,2) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=4 then buy("eL_L_3") quantity shares next bar at lowest(Low,3) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=5 then buy("eL_L_4") quantity shares next bar at lowest(Low,4) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=6 then buy("eL_L_5") quantity shares next bar at lowest(Low,5) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=7 then buy("eL_L_6") quantity shares next bar at AvgPrice + enter_gap_pattern_long limit;

If enter_mode_pattern_long=8 then buy("eL_L_7") quantity shares next bar at Average(AvgPrice,2) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=9 then buy("eL_L_8") quantity shares next bar at Average(AvgPrice,3) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=10 then buy("eL_L_9") quantity shares next bar at Average(AvgPrice,4) +

enter_gap_pattern_long limit;

If enter_mode_pattern_long=11 then buy("eL_L_10") quantity shares next bar at Average(AvgPrice,5) +

enter_gap_pattern_long limit;

If enter_mode_pattern_long=12 then buy("eL_L_11") quantity shares next bar at Average(L,2) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=13 then buy("eL_L_12") quantity shares next bar at Average(L,3) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=14 then buy("eL_L_13") quantity shares next bar at Average(L,4) + enter_gap_pattern_long

limit;

If enter_mode_pattern_long=15 then buy("eL_L_14") quantity shares next bar at Average(L,5) + enter_gap_pattern_long

limit;

if enter_mode_pattern_long=16 then buy("eL_S") quantity shares next bar at high stop;

If enter_mode_pattern_long=17 then buy("eL_S_2") quantity shares next bar at highest(high,2) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=18 then buy("eL_S_3") quantity shares next bar at highest(high,3) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=19 then buy("eL_S_4") quantity shares next bar at highest(high,4) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=20 then buy("eL_S_5") quantity shares next bar at highest(high,5) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=21 then buy("eL_S_6") quantity shares next bar at AvgPrice + enter_gap_pattern_long stop;

If enter_mode_pattern_long=22 then buy("eL_S_7") quantity shares next bar at Average(AvgPrice,2) +

enter_gap_pattern_long stop;

If enter_mode_pattern_long=23 then buy("eL_S_8") quantity shares next bar at Average(AvgPrice,3) +

enter_gap_pattern_long stop;

If enter_mode_pattern_long=24 then buy("eL_S_9") quantity shares next bar at Average(AvgPrice,4) +

enter_gap_pattern_long stop;

If enter_mode_pattern_long=25 then buy("eL_S_10") quantity shares next bar at Average(AvgPrice,5) +

enter_gap_pattern_long stop;

If enter_mode_pattern_long=26 then buy("eL_S_11") quantity shares next bar at Average(H,2) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=27 then buy("eL_S_12") quantity shares next bar at Average(H,3) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=28 then buy("eL_S_13") quantity shares next bar at Average(H,4) + enter_gap_pattern_long

stop;

If enter_mode_pattern_long=29 then buy("eL_S_14") quantity shares next bar at Average(H,5) + enter_gap_pattern_long

stop;

end;

end;

// Entry for SHORT

If entry_short_pattern then

begin

If Marketposition = 0 and S_entry_pattern_ok and trend_filter_short_ok and vola_filter_short_ok then

begin

if enter_mode_pattern_short=1 then sellshort("eS_O") quantity shares next bar at open;

if enter_mode_pattern_short=2 then sellshort("eS_L") quantity shares next bar at high + enter_gap_pattern_short limit;

If enter_mode_pattern_short=3 then sellshort("eS_L_2") quantity shares next bar at highest(high,2) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=4 then sellshort("eS_L_3") quantity shares next bar at highest(high,3) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=5 then sellshort("eS_L_4") quantity shares next bar at highest(high,4) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=6 then sellshort("eS_L_5") quantity shares next bar at highest(high,5) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=7 then sellshort("eS_L_6") quantity shares next bar at AvgPrice + enter_gap_pattern_short

limit;

Page 16: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

If enter_mode_pattern_short=8 then sellshort("eS_L_7") quantity shares next bar at Average(AvgPrice,2) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=9 then sellshort("eS_L_8") quantity shares next bar at Average(AvgPrice,3) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=10 then sellshort("eS_L_9") quantity shares next bar at Average(AvgPrice,4) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=11 then sellshort("eS_L_10") quantity shares next bar at Average(AvgPrice,5) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=12 then sellshort("eS_L_11") quantity shares next bar at Average(high,2) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=13 then sellshort("eS_L_12") quantity shares next bar at Average(high,3) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=14 then sellshort("eS_L_13") quantity shares next bar at Average(high,4) +

enter_gap_pattern_short limit;

If enter_mode_pattern_short=15 then sellshort("eS_L_14") quantity shares next bar at Average(high,5) +

enter_gap_pattern_short limit;

if enter_mode_pattern_short=16 then sellshort("eS_S") quantity shares next bar at low + enter_gap_pattern_short stop;

If enter_mode_pattern_short=17 then sellshort("eS_S_2") quantity shares next bar at lowest(Low,2) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=18 then sellshort("eS_S_3") quantity shares next bar at lowest(Low,3) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=19 then sellshort("eS_S_4") quantity shares next bar at lowest(Low,4) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=20 then sellshort("eS_S_5") quantity shares next bar at lowest(Low,5) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=21 then sellshort("eS_S_6") quantity shares next bar at AvgPrice + enter_gap_pattern_short

stop;

If enter_mode_pattern_short=22 then sellshort("eS_S_7") quantity shares next bar at Average(AvgPrice,2) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=23 then sellshort("eS_S_8") quantity shares next bar at Average(AvgPrice,3) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=24 then sellshort("eS_S_9") quantity shares next bar at Average(AvgPrice,4) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=25 then sellshort("eS_S_10") quantity shares next bar at Average(AvgPrice,5) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=26 then sellshort("eS_S_11") quantity shares next bar at Average(Low,2) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=27 then sellshort("eS_S_12") quantity shares next bar at Average(Low,3) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=28 then sellshort("eS_S_13") quantity shares next bar at Average(Low,4) +

enter_gap_pattern_short stop;

If enter_mode_pattern_short=29 then sellshort("eS_S_14") quantity shares next bar at Average(Low,5) +

enter_gap_pattern_short stop;

end;

end;

{************************************************************************************************************************}

{********* Pattern Farm EXIT *********}

{************************************************************************************************************************}

If exit_pattern_long_enabled = 1 then

begin

L_exit_pattern_ok = ((O[8] <= H[7]) and (C[2] <= AvgPrice[5]));

end;

If exit_pattern_short_enabled = 1 then

begin

S_exit_pattern_ok = false;

end;

{************************************************************************************************************************}

{********* EXIT module *********}

{************************************************************************************************************************}

//Modulo Pattern Exit Long

if exit_pattern_long_enabled=1 and exit_SR = 0 and (barssinceentry(0)>=(exit_bars_number_pattern_long-1) or L_exit_pattern_ok)

then

begin

If exit_pattern_long_type=1 and Marketposition=1 and (Close-Entryprice)>0 then sell("P_P_exit_L") next bar at open;

//IF_PROFIT

If exit_pattern_long_type=2 and Marketposition=1 and (Close-Entryprice)<0 then sell("P_L_exit_L") next bar at open;

//IF_LOSS

If exit_pattern_long_type=3 and Marketposition=1 then sell("P_exit_L") next bar at open; //ALWAYS

end;

//Modulo Pattern Exit Short

if exit_pattern_short_enabled=1 and exit_SR = 0 and (barssinceentry(0)>=(exit_bars_number_pattern_short-1) or S_exit_pattern_ok)

then

begin

If exit_pattern_short_type=1 and Marketposition=-1 and (Entryprice-Close)>0 then buytocover("P_P_exit_S") next bar at open;

//IF_PROFIT

If exit_pattern_short_type=2 and Marketposition=-1 and (Entryprice-Close)<0 then buytocover("P_L_exit_S") next bar at open;

//IF_LOSS

If exit_pattern_short_type=3 and Marketposition=-1 then buytocover("P_exit_S") next bar at open; //ALWAYS

end;

//Modulo Pattern Exit Stop and reverse

if exit_pattern_long_enabled=1 and exit_SR = 1 and (barssinceentry(0)>=(exit_bars_number_pattern_long-1) or L_exit_pattern_ok)

then

Page 17: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

begin

If exit_pattern_long_type=1 and Marketposition=1 and (Close-Entryprice)>0 then sellshort("P_P_exitSR_L") next bar at open;

//IF_PROFIT

If exit_pattern_long_type=2 and Marketposition=1 and (Close-Entryprice)<0 then sellshort("P_L_exitSR_L") next bar at open;

//IF_LOSS

If exit_pattern_long_type=3 and Marketposition=1 then sellshort("P_exitSR_L") next bar at open; //ALWAYS

end;

if exit_pattern_short_enabled=1 and exit_SR = 1 and (barssinceentry(0)>=(exit_bars_number_pattern_short-1) or S_exit_pattern_ok)

then

begin

If exit_pattern_short_type=1 and Marketposition=-1 and (Entryprice-Close)>0 then buy("P_P_exitSR_S") next bar at open;

//IF_PROFIT

If exit_pattern_short_type=2 and Marketposition=-1 and (Entryprice-Close)<0 then buy("P_L_exitSR_S") next bar at open;

//IF_LOSS

If exit_pattern_short_type=3 and Marketposition=-1 then buy("P_exitSR_S") next bar at open; //ALWAYS

end;

// Modulo Time Exit "on next open"

if (exit_mode_long = 1) and (marketposition = 1) and (exit_bars_number_long > 0) and (barssinceentry(0)>=(exit_bars_number_long-

1)) then sell("T_exit_L_1") next bar at open;

if (exit_mode_short = 1) and (marketposition = -1) and (exit_bars_number_short > 0) and

(barssinceentry(0)>=(exit_bars_number_short-1)) then buytocover("T_exit_S_1") next bar at open;

// Modulo Time Exit "on next open" + Stop Loss

if (exit_mode_long = 2) then

Begin

If (marketposition = 1) and (exit_bars_number_long > 0) and (barssinceentry(0)>=(exit_bars_number_long-1)) then

sell("T_exit_L_2") next bar at open;

if (marketposition = 1) and ((entryprice-close)*quantity > stop_loss_amount_long) then sell("Stoploss_L_2") next bar at

open;

end;

if (exit_mode_short = 2) then

Begin

If (marketposition = -1) and (exit_bars_number_short > 0) and (barssinceentry(0)>=(exit_bars_number_short-1)) then

buytocover("T_exit_S_2") next bar at open;

if (marketposition = -1) and ((close-entryprice)*quantity > stop_loss_amount_short) then buytocover("Stoploss_S_2") next bar

at open;

end;

// Modulo Time Exit "on next open" + Target

if (exit_mode_long = 3) then

Begin

If (marketposition = 1) and (exit_bars_number_long > 0) and (barssinceentry(0)>=(exit_bars_number_long-1)) then

sell("T_exit_L_3") next bar at open;

if (marketposition = 1) and ((close-entryprice)*quantity > target_amount_long) then sell("Target_L_3") next bar at open;

end;

if (exit_mode_short = 3) then

Begin

If (marketposition = -1) and (exit_bars_number_short > 0) and (barssinceentry(0)>=(exit_bars_number_short-1)) then

buytocover("T_exit_S_3") next bar at open;

if (marketposition = -1) and ((entryprice-close)*quantity > target_amount_short) then buytocover("Target_S_3") next bar at

open;

end;

// Modulo Time Exit "on next open" + Stop Loss + Target

if (exit_mode_long = 4) then

Begin

If (marketposition = 1) and (exit_bars_number_long > 0) and (barssinceentry(0)>=(exit_bars_number_long-1)) then

sell("T_exit_L_4") next bar at open;

if (marketposition = 1) and ((entryprice-close)*quantity > stop_loss_amount_long) then sell("Stoploss_L_4") next bar at

open;

if (marketposition = 1) and ((close-entryprice)*quantity > target_amount_long) then sell("Target_L_4") next bar at open;

end;

if (exit_mode_short = 4) then

Begin

If (marketposition = -1) and (exit_bars_number_short > 0) and (barssinceentry(0)>=(exit_bars_number_short-1)) then

buytocover("T_exit_S_4") next bar at open;

if (marketposition = -1) and ((close-entryprice)*quantity > stop_loss_amount_short) then buytocover("Stoploss_S_4") next bar

at open;

if (marketposition = -1) and ((entryprice-close)*quantity > target_amount_short) then buytocover("Target_S_4") next bar at

open;

end;

//Bailout

if (exit_mode_long = 5) and (marketposition = 1) and (positionprofit > 0) then sell("Bailout_L_1") next bar at open;

if (exit_mode_short = 5) and (marketposition = -1) and (positionprofit > 0) then buytocover("Bailout_S_1") next bar at open;

//Bailout 2

if (exit_mode_long = 6) and (marketposition = 1) and (positionprofit > 0) then sell("Bailout_L_2") this bar at close;

if (exit_mode_short = 6) and (marketposition = -1) and (positionprofit > 0) then buytocover("Bailout_S_2") this bar at close;

//Bailout 2 + Stop Loss

if (exit_mode_long = 7) then

Begin

If (marketposition = 1) and (positionprofit > 0) then sell("Bailout_L_3") this bar at close;

if (marketposition = 1) and ((entryprice-close)*quantity > stop_loss_amount_long) then sell("B_Stoploss_L_3") next bar at

open;

end;

if (exit_mode_short = 7) then

Page 18: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Begin

If (marketposition = -1) and (positionprofit > 0) then buytocover("Bailout_S_3") this bar at close;

if (marketposition = -1) and ((close-entryprice)*quantity > stop_loss_amount_short) then buytocover("B_Stoploss_S_3") next

bar at open;

end;

//Bailout 2 + Target

if (exit_mode_long = 8) then

Begin

If (marketposition = 1) and (positionprofit > stop_loss_amount_long) then sell("Bailout_L_4") this bar at close;

if (marketposition = 1) and ((close-entryprice)*quantity > target_amount_long) then sell("B_Target_L_4") next bar at open;

end;

if (exit_mode_short = 8) then

Begin

If (marketposition = -1) and (positionprofit > stop_loss_amount_short) then buytocover("Bailout_S_4") this bar at close;

if (marketposition =-1) and ((entryprice-close)*quantity > target_amount_short) then buytocover("B_Target_S_4") next bar at

open;

end;

{************************************************************************************************************************}

{********* Chandelier Stop *********}

{************************************************************************************************************************}

vars:

double chandelier_stop_low (0),

double chandelier_stop_high (0),

double chandelier_stop_SL_long (0),

double chandelier_stop_SL_short (0);

If chandelier_stop_enabled=1 then

begin

chandelier_stop_low = Close - chandelier_stop_stdev*StandardDev(Close,chandelier_stop_period,2);

chandelier_stop_high = Close + chandelier_stop_stdev*StandardDev(Close,chandelier_stop_period,2);

if marketposition<>1 then begin

chandelier_stop_SL_long=chandelier_stop_low;

end;

if marketposition<>-1 then begin

chandelier_stop_SL_short=chandelier_stop_high;

end;

if marketposition=1 then begin

if chandelier_stop_low<chandelier_stop_SL_long then chandelier_stop_SL_long=chandelier_stop_SL_long[1] else

chandelier_stop_SL_long=chandelier_stop_low;

end;

if marketposition=-1 then begin

if chandelier_stop_high>chandelier_stop_SL_short then chandelier_stop_SL_short=chandelier_stop_SL_short[1] else

chandelier_stop_SL_short=chandelier_stop_high;

end;

if marketposition=1 and c < chandelier_stop_SL_long then begin

sell ("Ch_exit_L") next bar at open;

end;

if marketposition=-1 and c > chandelier_stop_SL_short then begin

buytocover ("Ch_exit_S") next bar at open;

end;

end;

{************************************************************************************************************************}

{********* Stop Loss catastrofico % *********}

{************************************************************************************************************************}

If catastriphic_SL_amount > 0 then

begin

SetStopposition;

SetStopLoss(catastriphic_SL_amount * bigpointvalue);

end;

{************************************************************************************************************************}

{********* End Code *********}

{************************************************************************************************************************}

Page 19: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Annex 2 Entry, Exit mode, trend and volatility filters The following list shows the 29 different entry mode LONG: enter_mode_pattern_long=1 - buy("eL_O") next bar at open

enter_mode_pattern_long=2 - buy("eL_L") next bar at low limit

enter_mode_pattern_long=3 - buy("eL_L_2") next bar at lowest(Low,2) + enter_gap_pattern_long limit

enter_mode_pattern_long=4 - buy("eL_L_3") next bar at lowest(Low,3) + enter_gap_pattern_long limit

enter_mode_pattern_long=5 - buy("eL_L_4") next bar at lowest(Low,4) + enter_gap_pattern_long limit

enter_mode_pattern_long=6 - buy("eL_L_5") next bar at lowest(Low,5) + enter_gap_pattern_long limit

enter_mode_pattern_long=7 - buy("eL_L_6") next bar at AvgPrice + enter_gap_pattern_long limit

enter_mode_pattern_long=8 - buy("eL_L_7") next bar at Average(AvgPrice,2) + enter_gap_pattern_long limit

enter_mode_pattern_long=9 - buy("eL_L_8") next bar at Average(AvgPrice,3) + enter_gap_pattern_long limit

enter_mode_pattern_long=10 - buy("eL_L_9") next bar at Average(AvgPrice,4) + enter_gap_pattern_long limit

enter_mode_pattern_long=11 - buy("eL_L_10") next bar at Average(AvgPrice,5) + enter_gap_pattern_long limit

enter_mode_pattern_long=12 - buy("eL_L_11") next bar at Average(L,2) + enter_gap_pattern_long limit

enter_mode_pattern_long=13 - buy("eL_L_12") next bar at Average(L,3) + enter_gap_pattern_long limit

enter_mode_pattern_long=14 - buy("eL_L_13") next bar at Average(L,4) + enter_gap_pattern_long limit

enter_mode_pattern_long=15 - buy("eL_L_14") next bar at Average(L,5) + enter_gap_pattern_long limit

enter_mode_pattern_long=16 - buy("eL_S") next bar at high stop

enter_mode_pattern_long=17 - buy("eL_S_2") next bar at highest(high,2) + enter_gap_pattern_long stop

enter_mode_pattern_long=18 - buy("eL_S_3") next bar at highest(high,3) + enter_gap_pattern_long stop

enter_mode_pattern_long=19 - buy("eL_S_4") next bar at highest(high,4) + enter_gap_pattern_long stop

enter_mode_pattern_long=20 - buy("eL_S_5") next bar at highest(high,5) + enter_gap_pattern_long stop

enter_mode_pattern_long=21 - buy("eL_S_6") next bar at AvgPrice + enter_gap_pattern_long stop

enter_mode_pattern_long=22 - buy("eL_S_7") next bar at Average(AvgPrice,2) + enter_gap_pattern_long stop

enter_mode_pattern_long=23 - buy("eL_S_8") next bar at Average(AvgPrice,3) + enter_gap_pattern_long stop

enter_mode_pattern_long=24 - buy("eL_S_9") next bar at Average(AvgPrice,4) + enter_gap_pattern_long stop

enter_mode_pattern_long=25 - buy("eL_S_10") next bar at Average(AvgPrice,5) + enter_gap_pattern_long stop

enter_mode_pattern_long=26 - buy("eL_S_11") next bar at Average(H,2) + enter_gap_pattern_long stop

enter_mode_pattern_long=27 - buy("eL_S_12") next bar at Average(H,3) + enter_gap_pattern_long stop

enter_mode_pattern_long=28 - buy("eL_S_13") next bar at Average(H,4) + enter_gap_pattern_long stop

enter_mode_pattern_long=29 - buy("eL_S_14") next bar at Average(H,5) + enter_gap_pattern_long stop

The following list shows the 29 different entry mode SHORT: enter_mode_pattern_short=1 - sellshort("eS_O") next bar at open

enter_mode_pattern_short=2 - sellshort("eS_L") next bar at high + enter_gap_pattern_short limit

enter_mode_pattern_short=3 - sellshort("eS_L_2") next bar at highest(high,2) + enter_gap_pattern_short limit

enter_mode_pattern_short=4 - sellshort("eS_L_3") next bar at highest(high,3) + enter_gap_pattern_short limit

enter_mode_pattern_short=5 - sellshort("eS_L_4") next bar at highest(high,4) + enter_gap_pattern_short limit

enter_mode_pattern_short=6 - sellshort("eS_L_5") next bar at highest(high,5) + enter_gap_pattern_short limit

enter_mode_pattern_short=7 - sellshort("eS_L_6") next bar at AvgPrice + enter_gap_pattern_short limit

enter_mode_pattern_short=8 - sellshort("eS_L_7") next bar at Average(AvgPrice,2) + enter_gap_pattern_short limit

enter_mode_pattern_short=9 - sellshort("eS_L_8") next bar at Average(AvgPrice,3) + enter_gap_pattern_short limit

enter_mode_pattern_short=10 - sellshort("eS_L_9") next bar at Average(AvgPrice,4) + enter_gap_pattern_short limit

enter_mode_pattern_short=11 - sellshort("eS_L_10") next bar at Average(AvgPrice,5) + enter_gap_pattern_short limit

enter_mode_pattern_short=12 - sellshort("eS_L_11") next bar at Average(high,2) + enter_gap_pattern_short limit

enter_mode_pattern_short=13 - sellshort("eS_L_12") next bar at Average(high,3) + enter_gap_pattern_short limit

enter_mode_pattern_short=14 - sellshort("eS_L_13") next bar at Average(high,4) + enter_gap_pattern_short limit

enter_mode_pattern_short=15 - sellshort("eS_L_14") next bar at Average(high,5) + enter_gap_pattern_short limit

enter_mode_pattern_short=16 - sellshort("eS_S") next bar at low + enter_gap_pattern_short stop

enter_mode_pattern_short=17 - sellshort("eS_S_2") next bar at lowest(Low,2) + enter_gap_pattern_short stop

enter_mode_pattern_short=18 - sellshort("eS_S_3") next bar at lowest(Low,3) + enter_gap_pattern_short stop

enter_mode_pattern_short=19 - sellshort("eS_S_4") next bar at lowest(Low,4) + enter_gap_pattern_short stop

enter_mode_pattern_short=20 - sellshort("eS_S_5") next bar at lowest(Low,5) + enter_gap_pattern_short stop

enter_mode_pattern_short=21 - sellshort("eS_S_6") next bar at AvgPrice + enter_gap_pattern_short stop

enter_mode_pattern_short=22 - sellshort("eS_S_7") next bar at Average(AvgPrice,2) + enter_gap_pattern_short stop

enter_mode_pattern_short=23 - sellshort("eS_S_8") next bar at Average(AvgPrice,3) + enter_gap_pattern_short stop

enter_mode_pattern_short=24 - sellshort("eS_S_9") next bar at Average(AvgPrice,4) + enter_gap_pattern_short stop

enter_mode_pattern_short=25 - sellshort("eS_S_10") next bar at Average(AvgPrice,5) + enter_gap_pattern_short stop

enter_mode_pattern_short=26 - sellshort("eS_S_11") next bar at Average(Low,2) + enter_gap_pattern_short stop

enter_mode_pattern_short=27 - sellshort("eS_S_12") next bar at Average(Low,3) + enter_gap_pattern_short stop

enter_mode_pattern_short=28 - sellshort("eS_S_13") next bar at Average(Low,4) + enter_gap_pattern_short stop

enter_mode_pattern_short=29 - sellshort("eS_S_14") next bar at Average(Low,5) + enter_gap_pattern_short stop

The following list shows the long and short trend filters:

enter_trendfilter_long = 1 - C > average(c,20)

enter_trendfilter_long = 2 - C > average(c,200)

enter_trendfilter_long = 3 - C < average(c,20)

enter_trendfilter_long = 4 - C < average(c,200)

enter_trendfilter_long = 5 - (C > bollingerband(C,200,+0) or C < bollingerband(C,200,-2)) and C <average(C, 5)

enter_trendfilter_long = 6 - (C > bollingerband(C,200,+1) or C < bollingerband(C,200,-2.5)) and C <average(C, 5)

enter_trendfilter_short = 1 - C > average(c,20)

enter_trendfilter_short = 2 - C > average(c,200)

enter_trendfilter_short = 3 - C < average(c,20)

enter_trendfilter_short = 4 - C < average(c,200)

enter_trendfilter_short = 5 - (C < bollingerband(C,200,-0) or C > bollingerband(C,200,+2)) and C > average(C, 5)

enter_trendfilter_short = 6 - (C < bollingerband(C,200,-1) or C > bollingerband(C,200,+2.5)) and C > average(C, 5)

Page 20: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

The following list shows the long and short volatility filters:

enter_volafilter_long = 1 - avgtruerange(2) > avgtruerange(5)[1]

enter_volafilter_long = 2 - avgtruerange(2) > avgtruerange(20)

enter_volafilter_long = 3 - avgtruerange(2) > avgtruerange(200)

enter_volafilter_long = 4 - avgtruerange(2) < avgtruerange(5)[1]

enter_volafilter_long = 5 - avgtruerange(2) < avgtruerange(20)

enter_volafilter_long = 6 - avgtruerange(2) < avgtruerange(200)

enter_volafilter_short = 1 - avgtruerange(2) > avgtruerange(5)[1]

enter_volafilter_short = 2 - avgtruerange(2) > avgtruerange(20)

enter_volafilter_short = 3 - avgtruerange(2) > avgtruerange(200)

enter_volafilter_short = 4 - avgtruerange(2) < avgtruerange(5)[1]

enter_volafilter_short = 5 - avgtruerange(2) < avgtruerange(20)

enter_volafilter_short = 6 - avgtruerange(2) < avgtruerange(200)

The following list shows the long and short exit modes:

exit_mode_long = 1 - sell("T_exit_L_1") next bar at open

exit_mode_short = 1 - buytocover("T_exit_S_1") next bar at open

exit_mode_long = 2 - barssinceentry(0)>=exit_bars_number_long-1 - sell("T_exit_L_2") next bar at open

(entryprice-close)*quantity > stop_loss_amount_long - sell("Stoploss_L_2") next bar at open

exit_mode_short = 2 - barssinceentry(0)>=exit_bars_number_short-1 - buytocover("T_exit_S_2") next bar at open

(close-entryprice)*quantity > stop_loss_amount_short - buytocover("Stoploss_S_2") next bar at open

exit_mode_long = 3 - barssinceentry(0)>=exit_bars_number_long-1 - sell("T_exit_L_3") next bar at open

(close-entryprice)*quantity > target_amount_long - sell("Target_L_3") next bar at open

exit_mode_short = 3 - barssinceentry(0)>=exit_bars_number_short-1 - buytocover("T_exit_S_3") next bar at open

(entryprice-close)*quantity > target_amount_short - buytocover("Target_S_3") next bar at open

exit_mode_long = 4 - barssinceentry(0)>=exit_bars_number_long-1 - sell("T_exit_L_4") next bar at open

(entryprice-close)*quantity > stop_loss_amount_long - sell("Stoploss_L_4") next bar at open

(close-entryprice)*quantity > target_amount_long - sell("Target_L_4") next bar at open

exit_mode_short = 4) barssinceentry(0)>=exit_bars_number_short-1 - buytocover("T_exit_S_4") next bar at open

(close-entryprice)*quantity > stop_loss_amount_short - buytocover("Stoploss_S_4") next bar at open

(entryprice-close)*quantity > target_amount_short - buytocover("Target_S_4") next bar at open

exit_mode_long = 5 - positionprofit > 0 - sell("Bailout_L_1") next bar at open

exit_mode_short = 5 - positionprofit > 0 - buytocover("Bailout_S_1") next bar at open

exit_mode_long = 6 - positionprofit > 0 - sell("Bailout_L_2") this bar at close

exit_mode_short = 6 - positionprofit > 0 - buytocover("Bailout_S_2") this bar at close

exit_mode_long = 7 - positionprofit > 0 - sell("Bailout_L_3") this bar at close

(entryprice-close)*quantity > stop_loss_amount_long - sell("B_Stoploss_L_3") next bar at open

exit_mode_short = 7 - positionprofit > 0 - buytocover("Bailout_S_3") this bar at close

(close-entryprice)*quantity > stop_loss_amount_short - buytocover("B_Stoploss_S_3") next bar at open

exit_mode_long = 8 - positionprofit > stop_loss_amount_long - sell("Bailout_L_4") this bar at close

(close-entryprice)*quantity > target_amount_long - sell("B_Target_L_4") next bar at open

exit_mode_short = 8 - positionprofit > stop_loss_amount_short - buytocover("Bailout_S_4") this bar at close

(entryprice-close)*quantity > target_amount_short - buytocover("B_Target_S_4") next bar at open

Page 21: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Annex 3 Config file Once PPD is loaded a configuration file with standard content is created in the following folder: C:\Program Files (x86)\TradeStation Archives\ The config file, which is a plain text file, is called: PPFSettings.config The standard content of this file is:

ver=110 generationdir=C:\Program Files (x86)\TradeStation Archives\ strategyname=TA_Price_Pattern_Detector__Gandalf_Project__PPDv8SearchEngine functionandstrategyprefix=TA_Price_Pattern_Detector__Gandalf_Project__

ver is an internal setting that indicates PPD the version with which the config file was originally generated. This field should not be changed for any reason. generationdir is the folder where PPD will store the files during and after the pattern search process. Normally this field is changed to a different and more convenient folder. The folder must be manually created first. Example: generationdir=C:\PPDspool\ Very important: the string must include the final “\”. strategyname and functionsandstrategyprefix indicates PPD the name of the strategy and the prefix name of the functions to use during the processing. These fields normally do not require any adjustment and shouldn’t be changed by the user. Only in case the source code of the functions or of the strategy are locally imported and compiled on the PC these fields should be changed removing the prefix that the store adds to the loaded apps. Example: strategyname=PPDv8SearchEngine functionandstrategyprefix= Very important note: the folder C:\Program Files (x86)\TradeStation Archives\ is normally a read-only folder so if the user tries to open any file with notepad and save it, a system error will probably arise. The easiest way is to open the file, modify it, save it temporarily to the desktop or any other normal folder, and than copy it back to C:\Program Files (x86)\TradeStation Archives\ overwriting the original file.

Page 22: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

Annex 4 Files generated by PPD and its content Once a pattern search/optimization is finished or interrupted by the user PPD will create several files based on the generation name. The generation name is generated by PPD but can be changed by the user during the optimization. In the following examples, we will consider as generation name: “GEN_1_SPY”. PPD will than generate a file called: GEN_1_SPY.rptall which contains the list of the X best trading systems found and their metrics. The first column contains the test number.

PPD will also write, for each test, files named GEN_1_SPY_gen_XXXX.tst, where XXXX is the test number. These files contain all the parameters to build the trading system. Example:

If the write equity files in advance is enabled, or later when a single trading system is selected in the result windows, an additional file is created for each test. The file is named GEN_1_SPY_gen_XXXX.eq, where XXXX is the test number. This file contains the equity curve information of the entire period: IS+OoS+RM. Example:

Page 23: Price Pattern Detector (PPD) - Featured Products · PDF filePrice Pattern Detector ... Optional volatility and/or trend filter ... Once the Trading App is downloaded on the system

TRADING RISK DISCLOSURE

PAST TRADING RESULTS ARE NOT INDICATIVE OF FUTURE RESULTS. PAST PRICE PATTERNS MAY NOT REPEAT IN PRECISELY THE SAME WAY AND SUBSEQUENTLY TRADING SYSTEMS MAY NOT ACHIEVE PROFITS/LOSSES SIMILAR TO PAST ACTUAL OR HYPOTHETICAL RESULTS. THERE ARE JUST TOO MANY VARIABLES IN THE MARKETS TO ACCURATELY FORECAST FUTURE RESULTS FOR ANY SYSTEM OR TRADER. HYPOTHETICAL PERFORMANCE RESULTS HAVE MANY INHERENT LIMITATIONS, SOME OF WHICH ARE DESCRIBED BELOW. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THOSE SHOWN. IN FACT, THERE ARE FREQUENTLY SHARP DIFFERENCES BETWEEN HYPOTHETICAL PERFORMANCE RESULTS AND THE ACTUAL RESULTS SUBSEQUENTLY ACHIEVED BY ANY PARTICULAR TRADING PROGRAM. ONE OF THE LIMITATIONS OF HYPOTHETICAL PERFORMANCE RESULTS IS THAT THEY ARE GENERALLY PREPARED WITH THE BENEFIT OF HINDSIGHT. IN ADDITION, HYPOTHETICAL TRADING DOES NOT INVOLVE FINANCIAL RISK, AND NO HYPOTHETICAL TRADING RECORD CAN COMPLETELY ACCOUNT FOR THE IMPACT OF FINANCIAL RISK IN ACTUAL TRADING CONDITIONS. IN ADDITION THE ABILITY TO WITH STAND LOSSES OR TO ADHERE TOA PARTICULAR TRADING PROGRAM IN SPITE OF TRADING LOSSES ARE MATERIAL POINTS WHICH CAN ALSO ADVERSELY AFFECT ACTUAL TRADING RESULTS. THERE ARE MANY OTHER FACTORS RELATED TO THE FINANCIAL MARKETS IN GENERAL OR TO THE IMPLEMENTATION OF ANY SPECIFIC TRADING PROGRAM WHICH CANNOT BE FULLY ACCOUNTED FOR IN THE PREPARATION OF HYPOTHETICAL PERFORMANCE RESULTS, ALL OF WHICH CAN ADVERSELY AFFECT ACTUAL TRADING RESULTS. THE RISK OF LOSS IN TRADING FUTURES, OPTIONS, COMMODITIES, AND STOCKS CAN BE SUBSTANTIAL. YOU SHOULD THEREFORE CAREFULLY CONSIDER WHETHER SUCH TRADING IS SUITABLE FOR YOU IN LIGHT OF YOUR FINANCIAL CONDITION. IN CONSIDERING WHETHER TO TRADE OR TO AUTHORIZE SOMEONE ELSE TO TRADE FOR YOU, YOU SHOULD BE AWARE OF THE FOLLOWING: IF YOU PURCHASE OR SELL A FUTURE, OPTION, YOU MAY SUSTAIN A TOTAL LOSS OF THE INITIAL MARGIN FUNDS AND ANY ADDITIONAL FUNDS THAT YOU DEPOSIT WITH YOUR BROKER TO ESTABLISH OR MAINTAIN YOUR POSITION. IF THE MARKET MOVES AGAINST YOUR POSITION, YOU MAYBE CALLED UPON YOUR BROKER TO DEPOSIT A SUBSTANTIAL AMOUNT OF ADDITIONAL MARGIN FUNDS, ON SHORT NOTICE. IF YOU DO NOT PROVIDE THE REQUIRED FUNDS WITHIN THE PRESCRIBED TIME, YOUR POSITION MAY BE LIQUIDATED AT A LOSS, AND YOU WILL BE LIABLE FOR ANY RESULTING DEFICIT IN YOU ACCOUNT. THE PLACEMENT OF CONTINGENT ORDERS BY YOU OR YOUR TRADING ADVISOR, SUCH AS A "STOP LOSS" OR "STOP LIMIT" ORDER, WILL NOT NECESSARILY LIMIT YOUR LOSSES TO THE INTENDED AMOUNTS, SINCE MARKET CONDITIONS MAY MAKE IT IMPOSSIBLE TO EXECUTE SUCH ORDERS. THE HIGH DEGREE OF LEVERAGE THAT IS OFTEN OBTAINABLE IN FUTURES AND OPTIONS MARKETS CAN WORK AGAINST YOU, AS WELL AS FOR YOU. THE USE OF LEVERAGE CAN LEAD TO LARGE LOSSES AS WELL AS GAINS. THIS BRIEF STATEMENT CANNOT DISCLOSE ALL THE RISK AND OTHER SIGNIFICANT ASPECTS OF THE FINANCIAL MARKETS.