#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

by bug man, 3913 days ago

This function accepts a list of rules and an index as parameters and returns a rule for the specified index.
The Market trading rules function can be very useful when applied in an optimization or backtesting process. Imagine you have a trading system and you would like to test different exit strategies. You first need to compile a list of rules that will be used as exits.
Let us say, these are your exit rules:
rsi(14) < 30
roc(close, 2) < -10
sma(volume, 30) < sma(volume, 10)
close < ref(close, 1) && ref(close, 1) < ref(close, 2)

buy = sma(30) > sma(14) && roc(close, 20) < -10 && roc(close, 2) > 3;
sell = ??

Because you have four exit rules, you would like to test four strategies. You can of course create a trading system for each exit rule or you can use this market trading rules function and only one trading system to accomplish the same result. The usefulness of this function may not seem obvious with this example, however if you had more than 20 exit rules to test then this function will save you a lot of time.
Here is a trading system based on the market trading rules function:
Optimize("varindex", 0, 3, 1);
buy = sma(30) > sma(14) && roc(close, 20) < -10 && roc(close, 2) > 3;
sell = rules_select("rsi(14) < 30;roc(close, 2) < -10;sma(volume, 30) < sma(volume, 10);close < ref(close, 1) && ref(close, 1) < ref(close, 2)", varindex);

When you optimize this strategy, the variable 'varindex' will varies from 0 to 3 and this in turn will create 4 strategies.

You can also use this function to create more variations and combinations. Instead of using the function once, you can use it several times, each time with the same rules or different ones. This will create several combinations.
Example:
Optimize("varindex1", 0, 2, 1);
Optimize("varindex2", 0, 1, 1);
s1 = rules_select("rule1;rule2;rule3", varindex1)
s2 = rules_select("rule4;rule5", varindex2)
sell = s1 || s2;

The above example will create six strategies. You can calculate the number of combinations by multiplying the number of iterations in every function (3 * 2 = 6).
Here is the list of all the generated trading rules combinations:
sell = rule1 || rule4;
sell = rule1 || rule5;
sell = rule2 || rule4;
sell = rule2 || rule5;
sell = rule3 || rule4;
sell = rule3 || rule5;

The rules passed to the Market trading rules function must be separated by a semi-colon and must be entered as a string (between quotes).

What is this?

 Type: Trading Indicator Object ID: 326 Country: All Market: All Style: Technical Analysis

Related objects
Show All
McNicholl Sentiment (by mdmd, uploaded several months ago)
No notes
 14
Trend Deviation Indicator (by bug man, uploaded several months ago)
No notes
 17
Supertrend Indicator (by Juliettpapa, uploaded several months ago)
No notes
 62
Standard Deviation Ratio (by Caleb, uploaded several months ago)
No notes
 17
Traders Dynamic Index - TDI Indicator (by Caleb, uploaded several months ago)
No notes
 36
NORMDIST - Normal Probability Density Function (by QuantShare, uploaded several months ago)
No notes
 21
NORMINV - Inverse of the Normal Cumulative Distribution (by QuantShare, uploaded several months ago)
No notes
 26
Number of reviews
Average rate
Click to rate this item
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object

 Random Blog Posts Stock split & dividend Survivorship bias Transaction Costs How scripts communicate with each other How to simulate options strategies Organizing Trading Objects Creating a download item: Initial Jobless Claims How to search for a download item Show All

Number of reviews
Average rate
Click to rate this item
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object