Offset Regression Bands Indicator and Strategy for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
This strategy was based on the Regression Channel indicator for ThinkorSwim. According to the original page, the strategy is based on offset regression bands and works well with indices and diverse ETFs.

I tested it on several large cap stocks and the signals worked out well most of the time too.

Some examples include AMD, MCD, and SPY. There is a built-in watchlist in ThinkorSwim called Indices and All ETFs. You can quickly pull them up and test out the tickers on there.

nXjczmW.png


etRqVsc.png


f1Nsels.png


thinkScript Code for Long

Rich (BB code):
# stdrev buy
# Strategy added by BenTen
# Original https://github.com/dougives/stdrev/blob/master/stdrev.thinkscript

def OPEN_ACTUAL_TIME = 0930;
def CLOSE_ACTUAL_TIME = 1600;
def is_trading_hours = If((SecondsFromTime(OPEN_ACTUAL_TIME) >= 0 && SecondsTillTime(CLOSE_ACTUAL_TIME) > 0), 1, 0);

def stoploss = close < close[-10] * 0.95;

def rsi = RSI("average type" = "EXPONENTIAL");

input price = close;
input deviations = 1.1;
input short_gap = 0.3;
input full_range = no;
input length = 1024;
input spread = 0.0001;
input overshoot = 0.2;
input tradesize = 1;
input only_when_open = no;

def regression;
def std_deviation;
if (full_range) {
    regression = InertiaAll(price);
    std_deviation = StDevAll(price);
} else {
    regression = InertiaAll(price, length);
    std_deviation = StDevAll(price, length);
}

def upper = regression + deviations * std_deviation;
def breaker = regression + overshoot * std_deviation;
def middle = regression;
def lower = regression - deviations * std_deviation;

def upper_s = regression + (deviations + short_gap) * std_deviation;
def breaker_s = regression - overshoot * std_deviation;
def middle_s = regression;
def lower_s = regression - (deviations + short_gap) * std_deviation;

def buy = price crosses above lower - spread;
def sell2c = price crosses above breaker;

plot buy1 = buy;
buy1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy1.SetDefaultColor(GetColor(8));
buy1.SetLineWeight(2);

AddOrder(OrderType.BUY_TO_OPEN, condition = buy, price = open,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");

AddOrder(OrderType.SELL_TO_CLOSE, condition = sell2c, price = close,100, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");

thinkScript Code for Short

Rich (BB code):
# stdrev sell
# Strategy added by BenTen
# Original https://github.com/dougives/stdrev/blob/master/stdrev.thinkscript

def OPEN_ACTUAL_TIME = 0930;
def CLOSE_ACTUAL_TIME = 1600;
def is_trading_hours = If((SecondsFromTime(OPEN_ACTUAL_TIME) >= 0 && SecondsTillTime(CLOSE_ACTUAL_TIME) > 0), 1, 0);

def stoploss = close < close[-10] * 0.95;

def rsi = RSI("average type" = "EXPONENTIAL");

input price = close;
input deviations = 1.1;
input short_gap = 0.3;
input full_range = no;
input length = 1024;
input spread = 0.0001;
input overshoot = 0.2;
input tradesize = 1;
input only_when_open = no;

def regression;
def std_deviation;
if (full_range) {
    regression = InertiaAll(price);
    std_deviation = StDevAll(price);
} else {
    regression = InertiaAll(price, length);
    std_deviation = StDevAll(price, length);
}

def upper = regression + deviations * std_deviation;
def breaker = regression + overshoot * std_deviation;
def middle = regression;
def lower = regression - deviations * std_deviation;

def upper_s = regression + (deviations + short_gap) * std_deviation;
def breaker_s = regression - overshoot * std_deviation;
def middle_s = regression;
def lower_s = regression - (deviations + short_gap) * std_deviation;

def short = price crosses below upper_s + spread;
def buy2c = price crosses below breaker_s;

AddOrder(OrderType.SELL_TO_OPEN, condition = short, price = open,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Short");

AddOrder(OrderType.BUY_TO_CLOSE, condition = buy2c, price = close,100, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Cover");

Keep in mind that hindsight is always 20/20. I haven't been able to find a single misleading signal from this indicator so I'm suspecting that there is some sort of repainting going on. I'll continue to watch it. Let me know if you guys find something.
 

Attachments

  • nXjczmW.png
    nXjczmW.png
    359 KB · Views: 260
  • etRqVsc.png
    etRqVsc.png
    345.1 KB · Views: 218
  • f1Nsels.png
    f1Nsels.png
    299.2 KB · Views: 218
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Awesome buddy.

Not being a ThinkOrSwimmer is there any way to see the LRC plot on the chart while the strategy runs?

 
Last edited:
@lit Yes it is possible. I uncommented out in the code but you can always turn it back on &#128512;

 
Last edited:
@ag91 Thanks for bringing it up, yes, anything with "Regression" in it will repaint.
 
Looks like I'm a few months late to this party. I just found this study. Looks very promising, although I do have one question: No matter what time frame I'm using, the study only seems backtest a maximum of 3 days.

Any thoughts? I'm not a coding expert, but I didn't see anything stand out that said "only backtest 3 days", lol.

Cheers!
 
@uawgmsmco Look at my comment right above yours. This indicator will repaint. It looks good but difficult to actually use it to trade. Please be careful when using.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
296 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top