#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;}

## Return Since a Specific Condition Occurred

by QuantShare, 4012 days ago

If you want to calculate the return of a time series (example: stock's price) since a specific event or condition occurred then you can download this function and use it as follows:

Example 1: Stock return since the beginning of the year

cond = year() != ref(year(), 1);
a = returnsince(close, cond);
plot(a, "", colorGreen);

Example 2: Stock return since the stock become overbought or oversold (RSI > 70 or RSI < 30)

r = rsi(14);
cond = r > 70 or r < 30;
a = returnsince(close, cond);
plot(a, "", colorGreen);

Example 3: Moving average changes in percentage since Monday

cond = week() != ref(week(), 1);
a = returnsince(sma(30), cond);
plot(a, "", colorGreen);

Example 4: Relative performance of a stock against the S&P 500 since the beginning of the year

cond = year() != ref(year(), 1);
a = returnsince(close, cond);
b = returnsince(GetSeries("^GSPC", close), cond);
c = a - b;
plot(c, "", colorGreen);

What is this?

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

 Related objects Empty
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 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 4 Links to Download Free Historical Stock Prices Data by Date Quantitative Analysis: Price Channels How to Download Trading Data for Certain Securities Only 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