OPEN-SOURCE SCRIPT
LinReg Scale-In Strategy

This strategy is based on an basic LinReg concept. Instead of using traditional price levels or moving averages, it uses the Linear Regression Correlation Coefficient (Pearson's r) to measure the actual strength of a trend and dynamically build up a position.
How it works:
The indicator calculates how closely the price follows a linear trend, returning a value between -1 and +1.
Scale-In (Entries): The strategy enters a Long position step-by-step as the uptrend gains momentum. It adds to the position when the coefficient crosses above the 0.25, 0.50, and 0.75 thresholds (pyramiding up to 3 times).
Scale-Out (Exit): Following the "let profits run but cut losses quick" mentality, the strategy closes the entire position as soon as the trend starts dying out and the coefficient crosses back down below 0.25.
Setup Tip: It is recommended using this approach on commodities using the Daily timeframe. The strategy is set to fixed contracts by default to allow smooth backtesting on futures like NQ or ES without running into margin limits.
Disclaimer:
This script is published for educational and testing purposes only. It does not constitute financial advice. Trading futures and other financial instruments involves significant risk of loss. Past performance is not indicative of future results. Always do your own research and backtesting before risking real capital.
How it works:
The indicator calculates how closely the price follows a linear trend, returning a value between -1 and +1.
Scale-In (Entries): The strategy enters a Long position step-by-step as the uptrend gains momentum. It adds to the position when the coefficient crosses above the 0.25, 0.50, and 0.75 thresholds (pyramiding up to 3 times).
Scale-Out (Exit): Following the "let profits run but cut losses quick" mentality, the strategy closes the entire position as soon as the trend starts dying out and the coefficient crosses back down below 0.25.
Setup Tip: It is recommended using this approach on commodities using the Daily timeframe. The strategy is set to fixed contracts by default to allow smooth backtesting on futures like NQ or ES without running into margin limits.
Disclaimer:
This script is published for educational and testing purposes only. It does not constitute financial advice. Trading futures and other financial instruments involves significant risk of loss. Past performance is not indicative of future results. Always do your own research and backtesting before risking real capital.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.