Is it possible to backtest standard deviation channels?

bobbybones

New member
I want to backtest linear regression standard deviations, though the linear regression value is constantly changing. Is it even possible to backtest?
 
@bobbybones It would help if you were to define your interpretation of "backtesting"... What is it that you would be monitoring for with said backtest...??? Give us more details and perhaps we can come up with answers or suggestions... You brief request has left nothing but questions... Remember, we can't remotely read what it is that is going on in your mind - at least not that we'd admit to... :unsure::eek:
 
@bobbybones It would help if you were to define your interpretation of "backtesting"... What is it that you would be monitoring for with said backtest...??? Give us more details and perhaps we can come up with answers or suggestions... You brief request has left nothing but questions... Remember, we can't remotely read what it is that is going on in your mind - at least not that we'd admit to... :unsure::eek:
Ok sorry for the lack of clarity, I mean like make a strategy in tos.
 
@bobbybones As long as you make it so that it has an end point and not constantly updating with price then yes but pretty hard to backtest linear regression. You can use the linear regression tool and create alert with drawings and then start collecting some data on it is probably best.
 
Again, based on what details...??? What do you consider a "strategy"...??? We need details... Your request is like me asking you the question, "How long is a piece of string?"...
Like you know the built in strategies in tos? Like it “places” a buy order and a sell order based on certain criteria. I want it to buy when it hits the 1.5 deviation and the 2 deviation and sell at the mean.
 
Like you know the built in strategies in tos? Like it “places” a buy order and a sell order based on certain criteria. I want it to buy when it hits the 1.5 deviation and the 2 deviation and sell at the mean.

So, which Study are you referring to... This is like pulling teeth...!!! Can you write more than two sentences to describe things in detail...??? I honestly don't like having to pry information out of you... It's you who wants the help and you're wasting MY time, and anyone else's who is following this topic...!!! Figure it out yourself if you can't explain yourself... It's you vision, not ours...
 
I want to backtest linear regression standard deviations, though the linear regression value is constantly changing. Is it even possible to backtest?
yes but you must define a static timeframe/bars back you want the study to scan for and it would have to be manual live scan unless you are fine with 3-7 of delayed data as thats how tos works on watchlists.
 
Like you know the built in strategies in tos? Like it “places” a buy order and a sell order based on certain criteria. I want it to buy when it hits the 1.5 deviation and the 2 deviation and sell at the mean.
The problem with deviation channels and mean is that it sorta does what people refer to as repaint(i dont like that term). Think about it this way lets say you run a lap between 5-10 mins the average is 7.5, if you run the last lap in ten minutes than you probably think that the next lap should be faster or revert to the center. But when there is more data or if you keep running at 10 mins the mean will not be the same anymore, even more so if you run more than 10 min, so then the channels keep changing, and the deviations keep changing, you could look at more data(bigger time frames) because the more data you the less the probability that the mean or average will change, but its very difficult to see what the channels have done unless you use the on-demand feature, there is a guy that uses primarily deviation channels, its the boiler room on thinkorswim, but as far as backtesting its, I dont know how you would do it, you can backtest something that keeps changing, having said that I do think that regression channels work if you use them multitude frame, because the deviations are truer on higher time frames, and they don't "deviate" as much. Look i to what standard deviations are i. Statistics and you'll understnad.
 
The problem with deviation channels and mean is that it sorta does what people refer to as repaint(i dont like that term). Think about it this way lets say you run a lap between 5-10 mins the average is 7.5, if you run the last lap in ten minutes than you probably think that the next lap should be faster or revert to the center. But when there is more data or if you keep running at 10 mins the mean will not be the same anymore, even more so if you run more than 10 min, so then the channels keep changing, and the deviations keep changing, you could look at more data(bigger time frames) because the more data you the less the probability that the mean or average will change, but its very difficult to see what the channels have done unless you use the on-demand feature, there is a guy that uses primarily deviation channels, its the boiler room on thinkorswim, but as far as backtesting its, I dont know how you would do it, you can backtest something that keeps changing, having said that I do think that regression channels work if you use them multitude frame, because the deviations are truer on higher time frames, and they don't "deviate" as much. Look i to what standard deviations are i. Statistics and you'll understnad.
Yeah I know boiler room trading personally and have been using his system to trade and it works pretty well. I’m just trying to optimize it, which is why I need more data, such as trades I might have made. Back testing it manually will be a huge pain in the ***, but I guess I’ll have to do it. Thanks for your help.
 
I gave it a quick try.

This will add the buy/sell based on crossing above or below the high/low line. As germanburrito stated, I believe its not very accurate due to the repaint issue. You would need to test with on demand feature for better results. Issue with on demand is I do not think you can use scanner.

FYI, my thinkScript knowledge is very minimal. I am just getting started with this trading stuff =).

Code:
input price = close;
input deviations = 2.0;



def regression = InertiaAll(price);
def stdDeviation = stdevAll(price);

plot UpperLine = regression + deviations * stdDeviation;
plot LowerLine = regression - deviations * stdDeviation;

def crossAbove = price crosses above upperLine;
def crossBelow = price crosses below lowerLine;
def buy = crossBelow;
def sell = crossAbove;

AddOrder(OrderType.BUY_AUTO, buy, tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "StdDevStratBUY");
AddOrder(OrderType.SELL_AUTO, sell, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "StdDevStratSell");
 
So, which Study are you referring to... This is like pulling teeth...!!! Can you write more than two sentences to describe things in detail...??? I honestly don't like having to pry information out of you... It's you who wants the help and you're wasting MY time, and anyone else's who is following this topic...!!! Figure it out yourself if you can't explain yourself... It's you vision, not ours...
I’m sorry for not being as clear as you wanted. I’m talking about linear regression standard deviations.
So, which Study are you referring to... This is like pulling teeth...!!! Can you write more than two sentences to describe things in detail...??? I honestly don't like having to pry information out of you... It's you who wants the help and you're wasting MY time, and anyone else's who is following this topic...!!! Figure it out yourself if you can't explain yourself... It's you vision, not ours...
Sorry for not being as clear as you’d like. I’m taking about the linear regression trend and standard deviations from the linear regression trend. I want to buy when it hits the lower deviations and sell when it hits the mean. I don’t know what other details to include, as it’s a simple strategy.
 
@bobbybones So we've gone from Standard Deviations to Linear Regressions... I don't like having my chain rattled... I'm out...!!!

Good luck...!!!

CbuqXpv.png


2MxTxZN.png
 
@rad14733 's point being is that i assume he is implying that you are being very vague and i would have to agree, standard deviations of the linear regression is what you are saying, however if you can see from the studies that are screenshotted there are many linear regression studies and you arent really defining which one nor are you defining more in detail what you are trying to accomplish IN DETAIL.

To put it in perspective its like saying "i want to know when the arrow goes up". Anyone trying to help is going to say which arrow, and up from what, along with more questions as to what you are trying to do.
 
@bobbybones what makes this difficult to script a back test for is the repainting someone mentioned already. If you have the study on a 1Y 1D chart, for instance, the slope recalculates every day and the past values will change. So any signals prior to the current bar are garbage. The simple code posted here will not work except for the current day and you'd have to forward test each day manually or use OnDemand to back test each day manually.

The only way I can think of to maybe get around this problem, and I haven't fully thought it through, would be to create a modified version of the StandardDevChannel study that adds an offset to the Inertia() call equal to how many bars back you are so you're getting the correct values, as things were when that bar was formed. Something like...

Code:
def barsBack = # some magic
def regression = Inertia(close(period = AggregationPeriod.DAY)[barsBack], length);

For barsBack maybe something like HighestAll(BarNumber()) - BarNumber(). I've never tried something like that.
 
It is standard deviations of the linear regression. Anyway i can't force you to stay, sorry for wasting your time. Take it easy.
Hey man, I'm with you. Nothing you said above was "vague" to me. This is exactly what I've been playing around with for a couple of days. And as I started looking at just a 2.0 Std Dev Channel on a 20 Day/1Hr chart, it suddenly dawned on me why I get my arse handed to me nearly every time I try and jump on a "hot stock" and ride it...namely, I'M BUYING AT THE TOP of the move! Now I know why a stock starts to drop like a rock, sometimes literally less than 5 minutes after I buy! This was an epiphany for me and I've been doing this a long time...

I don't write in ThinkScript, so I'll leave the programming responses to others. But at this point, I do have a crude, manual workaround for repainting. My "rules" (still subject to change) are, I want to:

1) BUY when price drops outside the channel bottom (ideally with a Hammer reversal candle, but not necessary)
2a) SELL when price touches the top channel line OR
2b) When price has crossed over the mean line on the way back up, but begins to sell back down before reaching the top channel line, then I want to SELL IF it hits the mean line on the way back down before touching the top channel line, more or less securing a "half-profit" on the move.

The manual workaround for repainting is to simply take a screenshot of the chart when I enter a trade. This gives me the original price targets for selling in 2a and 2b. In fact, you could even enter a GTC Sell Order at the original top channel line price once filled on the Buy Order. So far, I'm trying to stick to charts with flat to slightly increasing slopes, shying away from decreasing slopes that could materially lower my original price targets as new data are added each hour.

I'm actually going to run through some "simulations" with OnDemand, taking a screenshot when 1) above generates a Buy Signal on a given chart. Then advance it to see how often my 2a) and 2b) sells would have occurred, and of course, how often price would've continued to fall after buying at 1). It's manual backtesting, but I think I'll have a pretty good idea of where this strategy stands after doing this with 10 or so symbols!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
304 Online
Create Post

Similar threads

Similar threads

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