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. اقرأ المزيد في شروط الاستخدام.