#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 QuantShare, 1427 days ago

This function allows you to enter several criteria (segments) and an index. It then calculates the result of the segment referenced by the index.

Let us say that for example, you want to create two segments:
Overbought Stocks
Oversold Stocks

The formula for each segment is:
rsi(14) > 70
rsi(14) < 30

Here is how to use this function:
a = segment("rsi(14) > 70;rsi(14) < 30", -1);
b = segment("rsi(14) > 70;rsi(14) < 30", 0);
c = segment("rsi(14) > 70;rsi(14) < 30", 1);

The variable "a" will get the number of segments, which is "2" in this case. This is a special case: by specifying a negative index, the "segment" function returns the number of segments.
The variable "b" will calculate the first segment and return the result of the following function: rsi(14) > 70
The variable "c" will calculate the second segment and return the result of the following function: rsi(14) < 30

How could it be useful?

This trading indicator can be really useful if you want to optimize for example a trading system by testing several rules/segments.

Optimize("a", 0, 1, 1);
rule1 = segment("rsi(14) > 70;rsi(14) < 30", a);

buy = close > close[1] and rule1;

By optimizing the above trading system, QuantShare will backtest two trading systems:
1/ Price is higher than yesterday's price and stock is overbought
2/ Price is higher than yesterday's price and stock is oversold

You can of course add as many segments as you want. And you can also combine segments by creating several calls to the "segment" function.

Another example:

Optimize("a", 0, 1, 1);
Optimize("b", 0, 2, 1);
rule1 = segment("rsi(14) > 70;rsi(14) < 30", a);
rule2 = segment("close > 2;close > 10;close > 20", b);

buy = close > close[1] and rule1 and rule2;

// The above trading system will create 6 combinations

What is this?

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

Related objects
Show All
Sector Rotation Model - SRM (by bug man, uploaded several months ago)
No notes
 39
S&P 500 vs. Stock Volatility Ratio (by The trader, uploaded several months ago)
No notes
 19
Supertrend Indicator (by Juliettpapa, uploaded several months ago)
No notes
 42
Index of dispersion - Variance-to-Mean Ratio - VMR (by The trader, uploaded several months ago)
No notes
 14
Strategy Optimization on Random in-sample and out-of-sample Periods (by QuantShare, uploaded several months ago)
No notes
 21
Avgerage Correlation (by Vangelis M., uploaded several months ago)
No notes
 15
Upside-Downside and Custom Standard Deviation (by QuantShare, uploaded several months ago)
No notes
 19
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 Backtesting Your Trading Systems: Symbol Segmentation Update Chart Layout based on Active Time Frame Presentation of QuantShare's new Real Time Version Charting, Backtesting and Trading using Fundamental Data Different Ticker Symbols for Each Data Source How to Automatically Import Local Data Into QuantShare How to Switch On/Off Trading Rules in Your Stock Trading System Backtesting a Strategy Based on Bond and Stock Index ETFs 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