OPEN-SOURCE SCRIPT
تم تحديثه Segment Regression

As an example of the descriptive power of Pine Script, this very short example traces a 'segment regression', a result not entirely obvious with so few lines of code, repositioning them when the previous inference moves away from the graph beyond the pre-set limit.
A trick used is to restart the new inference segment
- from the maximum reached in the previous trend, when positive (slope>0)
- from the minimum reached in the previous trend, when negative (slope<0)
The result can in my opinion be easily used to build strategies.
A trick used is to restart the new inference segment
- from the maximum reached in the previous trend, when positive (slope>0)
- from the minimum reached in the previous trend, when negative (slope<0)
The result can in my opinion be easily used to build strategies.
ملاحظات الأخبار
Version 2: added a line to determine a channel, not considering a fixed number of bars to avoid the obvious impact of the last lines before the breakout
ملاحظات الأخبار
This is an update that also includes more detail on the logic underlying the indicator.The study presented here extends the classic 'linear regression' to that of 'segmental linear regression'.
The linreg() tool is therefore assumed to be known, which is initially applied without any variation, with the starting point equal to the first bar of the graph and with a minimum number of bars equal to those expected.
At each subsequent frame, then:
1) the percentage distance between the real value and the one inferred with the current regression segment is evaluated
2) if this calculated percentage distance is lower than the desired one or if it has the same sign as the slope of the current regression segment, nothing is done
3) if this percentage distance is higher than the desired one in the opposite direction to the slope of the regression segment, the starting point of the new regression segment is updated with
3.1) the point where the previous graph touched the minimum, if the slope of the previous inference segment was negative
3.2) the point where the previous graph touched the maximum, if the slope of the previous inference segment was positive
Please note that in the moments in which the graph is lateral, the slope of the regression segment can change sign even without activating point 3) above.
Ultimately, you get an indicator that is able to follow the graph in a much more adequate way than an ordinary linear regression.
It is my opinion that with this indicator as a starting point, good strategies can be implemented.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
للوصول السريع إلى الرسم البياني، أضف هذا النص البرمجي إلى مفضلاتك - تعرف على المزيد هنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
للوصول السريع إلى الرسم البياني، أضف هذا النص البرمجي إلى مفضلاتك - تعرف على المزيد هنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.