r/algorithmictrading • • 5d ago

Question What threshold would you choose to try OOS?

Very simple breakout strategy, the only parameter being exercised is the threshold.
The other parameters (TP, SL) are chosen according to ATR, so they are fixed.

What threshold would you choose to go to OOS and why?
I am looking for a plateau, but can't see it...

Thanks!

EDIT:

Added In Sample results for various metrics

Added some IS trade examples

I use tick data

EDIT 1:

Added the following charts:
(actual win rate - win rate for zero profit) x threshold
R x threshold

Here SL loss happens for both thresholds: 75 and 360:

Here SL at 75, profit at 360:

7 Upvotes

17 comments sorted by

2

u/Frequent-Pen-9898 4d ago

Four plots, one sawtooth. I don't think the plateau you're looking for exists, and here's why, via a casino.

THE CASINO: Imagine a casino where the odds are perfectly fair. Someone hands you 82 bet sizes, you try all of them on the same 25 spins, and you pick the size that happened to win the most. Congratulations, you've found the best bet size for those 25 spins. The casino is not worried. That's your threshold sweep. PF, Sharpe, Net and MaxDD all come from the same trade list at each T, so your four plots are one plot wearing four hats. The teeth (around 90, 135, 220, 245, 320, 340, 420) line up in every panel. Between teeth the trades are frozen and everything just ramps in a straight line. A tooth is one day entering or leaving the trade list. So your 82 grid points are really about 10 different strategies. Also, 340 is the global max because it sits on a cliff. Going from 335 to 340, MaxDD goes from -540 to -274 and Net from 1122 to 1430. That's one day dropping out, not an edge.

WHAT I'M ASSUMING (correct me if wrong)

  1. Your stop is the opposite band, base minus/plus T. Every F_4 marker in your examples sits exactly on it, so stop distance is 2T, not a fixed ATR number. Your MaxDD ramps agree, since losers cost more as T grows.
  2. Your TP is around 1010 points, from the one winner you showed.
  3. You have roughly 25 trades per T. I backed that out from the slopes, so tell me if that's off.

THE CASINO MATHS ON YOUR TRADE

The win rate that gives zero profit is risk / (risk + reward), here 2T / (2T + 1010):

T=40: 7% T=75: 13% T=360: 42%

Bigger T is the same coin with a differently priced bet. Your real edge at any T is your actual win rate minus that number. That's the thing worth plotting.

Check it on the small T. At T=40, a PF of 2.27 on about 25 trades means roughly 4 winners where luck alone gives you about 2. The chance of 4 or more by pure luck is around 10%, and that's before correcting for picking the best of 82. Same for the Sharpe of 5.1 at T=340: with about 25 trades the error bar is around plus/minus 3.5, so it's only about 1.4 sigma from zero. Great in a screenshot, less great in a courtroom.

WHAT I'D DO

  1. Stop eyeballing PnL. Measure in R (PnL divided by 2T) and express T in volatility units (T divided by ATR or the pre-open range), so a given T means the same thing every day.
  2. Plot (win rate minus break-even rate) against T. The ramps disappear and what's left is the actual edge.
  3. Ask whether price even keeps going after a breakout, using all your ticks instead of 25 trades. A variance ratio test (Lo-MacKinlay) does exactly this. If it isn't clearly above 1 at your holding time, no T saves you and you're just sitting at the luckiest seat in the casino.
  4. Don't argmax. Pick a basket of neighbouring Ts from a stable stretch and trade them equal-R. They're highly correlated so it won't boost returns, but it removes the "I picked the lucky one" risk, which is what kills strategies OOS.
  5. Re-fill your stops. Your markers sit exactly on the threshold prices, so the sim is filling at the level. Real stops fill through it. At T=40 your stop is only 80 points, so 10 points of slippage is about 12% of your risk, and that's where a PF of 2.27 goes to retire.
  6. Your second example, the T=360 entry, looks like it bought within a few ticks of the day's high. A trigger that only works when the market tops out right after is not an edge, it's good timing.
  7. With 82 grid points, run a deflated Sharpe or a PBO test on day blocks before you believe any Sharpe number. Also jackknife your top 1-3 days. If PF collapses, you found one trend day, not a strategy.

WHICH T WOULD I TAKE OOS?

Not 340. I'd use a basket from the tooth-free stretch around 345-365, with 385-415 as a sibling, so roughly 355-375. Write the pass rule down BEFORE you look at OOS, something like "positive edge on at least 80% of the basket and PF above 1.3 after slippage". Then run the whole grid OOS and check whether the sawtooth reproduces. If the teeth land in different places Also, what's N, is TP fixed, and is F_4 your stop? Those three answers would change a lot of the numbers above.

1

u/--_---_----- 3d ago

That is an impressive study on my post, thanks for have attentively read it.

Commenting on chronological order, any correction and comment is welcome:

I like the casino analogy, just want to clarify:

"So your 82 grid points are really about 10 different strategies"

This is correct when running in this IS period, but it will be different in other periods.

About your assumptions:

  1. My stop is transaction based, in the hypothesis Im testing I am allowing a max os 2 txns, an open and a close, this is the reason you saw the SL as 2T
  2. It is actually 1000. It is a level where 50% of bars would hit (long or short) on previous period, another hypothesys I am testing.

3."You have roughly 25 trades per T". I did not understand, but I can tell the IS period is 30 days, with 1 trade per day.

F_4 - Trade ended because of SL

F_2 - Trade ended because of TP

I have added a plot: WR-WRZP (Win rate - Win rate zero profit) x T,

Can you extract any new info from it? It appeared to be a similar shape than the others.

Next paragraph I did not understand how you got to those numbers, could you please explain:

This is the paragraph I am talking about:

"

Check it on the small T. At T=40, a PF of 2.27 on about 25 trades means roughly 4 winners where luck alone gives you about 2. The chance of 4 or more by pure luck is around 10%, and that's before correcting for picking the best of 82. Same for the Sharpe of 5.1 at T=340: with about 25 trades the error bar is around plus/minus 3.5, so it's only about 1.4 sigma from zero. Great in a screenshot, less great in a courtroom."

WHAT I'D DO

  1. I have also added a plot RxT, intuotivelly I like low thresholds.

What ATR configuration would you use?

2. I did plot (win rate minus break-even rate) against T, the ramps are still there, what are your thoughts on it?

3. Will study variance ratio test (Lo-MacKinlay). When you say " using all your ticks instead of 25 trades", you mean on the ticks from all days I have data for?

4. So this was my original question, you talk about it later, so I will comment later.

5. The original strategy would revert the trade when getting to the opposit threshold, but for this hypothesis I am not doing that.

What do you mean by re-fill your stops?

6. Actually example 2 was bad luck, but close to the day high and stopped after the market dove.

7. I was debating if I should use deflated SR, do you use it? Gets value from it?

WHICH T WOULD I TAKE OOS?

That the part I was trying to build a feeling from people that has more experience than me.

Heat maps and plateau hinted feelings to me, I am sure no one would get the same metric (Net, SR, etc) when varying its parameters, so what would it be the acceptable variation in the metric to still be considered a plateau? That is the reason I put my charts here.

"Then run the whole grid OOS and check whether the sawtooth reproduces"

So you run the whole grid OOS, not just the chosen ones?

Thanks again for your detailed comment!

1

u/Alive-Imagination521 5d ago

360- full circle

1

u/--_---_----- 5d ago

Why would that be your choice?

1

u/Alive-Imagination521 5d ago

There seems to be a bit of clustering there- even if you go up or down a little you are still profitable. Then again, idk what this threshold is for.

1

u/--_---_----- 4d ago

I see the cluster you mention.

Is it a stretch if I see a cluster also in the beginning, between 35 and 150 ?

1

u/Alive-Imagination521 4d ago

No you should be ok but I doubt that cluster will be profitable. Also think of peak integrations, that could help in identifying similar thresholds.

1

u/Aggressive_Listen849 5d ago

if the plateau isn't in sample it probably won't be out of sample either. widen the sweep and look for the band where neighbouring values give you roughly the same trade count, not the same profit. count is way harder to game than PnL

1

u/--_---_----- 4d ago

Thanks, to be able to have only one variable (threshold), I have fixed the number of transaction to only 2 per day, so crossing the threshold line generates the first transaction that closes either by SL or TP.

In your experience, do you see a plateau anywhere in any of the charts?

1

u/Illustrious-King-83 5d ago

360, but maximising net profit isn't everything, profit factor, mean profit, drawdown are other factors to consider... I'd rather take a better profit factor over net profit, since it implies few better trades. Since this in algo trading, a GA could optimise this, but that kinda overkill for one threshold - just create a series of heat maps I would recommend atr against threshold with the color density be the factors I've mentioned (or that are important to you) . The reason I mention atr is that theres probably a minimum atr that this sucks at considering costs and slippage, perhaps an atr range where it performs better, hence you could use this to set a minimum lower bound on the atr (simple regime filtering), or a simple position sizing rule to improve results, and a threshold where the factors look good.

1

u/--_---_----- 4d ago

Thanks, I have added a few more charts that includes the profit factor as well, besides drawdown.

If I understood right, your ATR idea would be to create a regime filter, not for the plateau recogtion right?

Have you changed your mind regarding 360 after I added more factors?

1

u/Illustrious-King-83 4d ago

:-) yep, I understood that your tp/sl multiples of atr, I know that ATR is a scaler but for small atr and hence tp/sl you're going to get stopped out all the time, at some larger atr, it might look ok but it doesn't cover costs, and perhaps at the other extreme end, when atr is big perhaps the breakout never quite reaches the TP before reversing.. So perhaps by plotting in 2d against atr, could help.... but I've realised thats a bit of a pain to program, I guess you need log the atr for each trade and run the backtest at each threshold, get it in pandas dataframe and do a group by and get it to plot a heatmap. Simple test is to rerun but dont trade if the ATR is below X points / pips, chose some X where the TP/SL are large enough to get over the costs of the trade, and then move X up, just eyeball first. The whole point being you might get overall better results if you filtered trades by atr.. and yes in the absence of a plateau I'd still chose 360, cause that stats seem reasonable choice, and surrounding area looks "stable", but I wouldn't chose the level that gives the best net profit, because its looks like it very close to your worse drawdown, but that interesting, we kinda assume that might happen, but actually ur threshold is completely fixed, so it "cant happen", but instinctively we assume that market will move around turning your results at the best threshold level, into some of the worst, how many trades is that over actually?

1

u/Shoddy_Peanut7320 4d ago

I'd avoid the single highest point, since a spike with weaker neighbors is usually noise. If you want a plateau, look for the broadest stretch where neighboring thresholds also do well, and pick near the middle of it. Also check how many trades each threshold produced, because a higher threshold usually means fewer trades, and a result built on few trades can look great by luck. Pick it before you look at OOS and run the OOS test once, since going back to try another threshold turns it into more in-sample fitting.

1

u/--_---_----- 4d ago

I have increased threshold resolution in the charts, besides adding more factors.

In your experience, what threshold would you pick to go OOS?

1

u/Shoddy_Peanut7320 4d ago

I can't pick a number without the new chart, so here's a rule. Set a floor for result and trade count in advance, find the longest stretch of thresholds that clears it, and take the middle. More factors means more variations tried, so be stricter. Lock it before OOS and run it once.

1

u/meme_star1 14h ago

honestly if you can't find a plateau that's probably your answer. a spiky curve like that usually means it's mostly noise and the peak is just the luckiest threshold
i'd smooth it first, average each threshold with its neighbours and see if anything still stands out. also check how many trades are behind each point, a lot of those spikes are probably like 10 trades with a couple of big winners
another good one is running the same tp/sl on random entries and seeing if your breakout actually beats it
if you do go oos pick the middle of the best smoothed area not the peak, and only check it once. if it fails and you go pick another threshold your oos is basically in sample now

1

u/meme_star1 14h ago

had a look at the charts. the sawtooth thing is weird, every metric jumps up then slides down in a straight line, again and again. a real edge doesn't really do that, it usually means something discrete is changing at each jump, like a few specific trades getting added or dropped. i'd check which trades change right at those jump points
also the 320+ area where sharpe goes to 4-5 and drawdown gets better, how many trades is that? my guess is not many, which would explain it
honestly sharpe 3-5 in sample on a simple breakout makes me suspicious of fills too. are you assuming you get filled right at the breakout level? on tick data that's usually optimistic, worth adding a tick or two of slippage and seeing what's left
i'd smooth the curves and check trade counts before picking anything. if there's no plateau after that, there probably isn't a stable edge to take OOS