How do you define trend in your trading algorithms?

 

Hello everyone,

I’m curious to hear how different developers in the community define and detect trend within their trading algorithms.

There are of course the more common approaches like moving averages or measuring percentage changes over a certain period, but I’m sure many of you are using more advanced or alternative methods.

It would be interesting to get some insight into:

  • What kind of logic you use to determine trend

  • Whether you rely on indicators, price action, or custom calculations

  • How you deal with ranging vs trending markets

Not looking for “right or wrong” answers, just genuinely interested in how others approach this and what has worked for you in practice.

Looking forward to hearing your perspectives!

 

The basic concept is to look for directional structure with higher highs and higher lows for uptrend or lower lows and lower highs for downtrend .  But there are a few other characteristics that need to be measured in order to estimate accurately the type and the quality of the trend. 

1. Trend smoothness - Calculate the ratio between up ticks and down ticks for the given time period. The easy alternative is to use modified RSI formula. Or you can calculate the percentage of overlapping candles.

But it's better to analyze price directly. In addition to the tick ratio, you can break down the price movements into segments by using fractals formula of N bars reversal. Then compare the sizes of impulsive segments and corrective segments. And also how deep is the deepest correction relative to the whole trend.

2. Trend angle - Measure the price change vs time. In other words, measure the speed of change. Big price change in short time vs small price change in a long time. These are the extremes on both ends of the spectrum. And everything else is in between.

3. Relative size - How large is the trend in comparison with historical trends of the same time frame. We can use ATR metrics for this.

There is also another way to approach the whole thing. You can eliminate the time component and look only at price.  For this we can use range bars or renko bars. They show different picture.

And in the end, things can be a lot simpler!  For example If the current price is at or near the highest price of the last N bars we assume the trend is up. Cant argue with that. And we can ignore the internal structure.

As you said, there is no right or wrong method. Just different approaches and different strategies.

 
Tsvetan Tsvetanov #:

The basic concept is to look for directional structure with higher highs and higher lows for uptrend or lower lows and lower highs for downtrend .  But there are a few other characteristics that need to be measured in order to estimate accurately the type and the quality of the trend. 

1. Trend smoothness - Calculate the ratio between up ticks and down ticks for the given time period. The easy alternative is to use modified RSI formula. Or you can calculate the percentage of overlapping candles.

But it's better to analyze price directly. In addition to the tick ratio, you can break down the price movements into segments by using fractals formula of N bars reversal. Then compare the sizes of impulsive segments and corrective segments. And also how deep is the deepest correction relative to the whole trend.

2. Trend angle - Measure the price change vs time. In other words, measure the speed of change. Big price change in short time vs small price change in a long time. These are the extremes on both ends of the spectrum. And everything else is in between.

3. Relative size - How large is the trend in comparison with historical trends of the same time frame. We can use ATR metrics for this.

There is also another way to approach the whole thing. You can eliminate the time component and look only at price.  For this we can use range bars or renko bars. They show different picture.

And in the end, things can be a lot simpler!  For example If the current price is at or near the highest price of the last N bars we assume the trend is up. Cant argue with that. And we can ignore the internal structure.

As you said, there is no right or wrong method. Just different approaches and different strategies.

Reading the breakdown of relying on higher highs and basic tick ratios to define an algorithmic trend explains exactly why so many retail systems bleed capital during institutional liquidity sweeps, a basic fractal or N-bar reversal logic is mathematically blind to real order flow and simply curve-fits past data, meaning the moment the market shifts into a complex volatility expansion, your static tick ratios will signal a trend right as the smart money is actually exiting the position. If you want to define trend computationally without lagging disastrously behind the market, you absolutely must abandon these retail illusions and start calculating dynamic volume-weighted standard deviations to track where the actual institutional delta is accumulating rather than just connecting imaginary dots on a chart
 

שאלה מצוינת. מניסיוני בפיתוח מערכות אלגוריתמיות, הסתמכות אך ורק על אינדיקטורים בפיגור כמו ממוצעים נעים מובילה לעיתים קרובות לכניסה מאוחרת לשווקים מהירים כמו זהב.

במודל הנוכחי שלי, אני משלב שלוש שכבות להגדרת מגמה:

  1. מתאם רב ניתוח מגמת H4/H1 כדי לקבוע את הכיוון העיקרי עוד לפני שמחפשים כניסה ל-M5.
  2. מסנני תנודתיות דינמית שימוש בחישובים מבוססי ATR כדי להבחין בין מגמה בריאה לעלייה "מזויפת".
  3. אישור פעולת מחיר ממתינים לסגירת נר ספציפית בכיוון מגמת מסגרת הזמן הגבוהה יותר כדי לוודא שהמומנטום אכן קיים.

גישה זו אפשרה לי לשמור על ירידה נמוכה מאוד של ההשקעה תוך שמירה על שיעור זכיות עקבי. בסופו של דבר, מדובר בסינרגיה בין יישור לוחות זמנים לניהול סיכונים.