Gentleman-Goat

Linear Regression - Auto Adjust To Ideal Pearson's R (Min & Max)

8256 lượt xem
505
This is meant as a partner to my linear regression strategy script. This one however is just the indicator only so you can overlay the technique over other strategies.

To use this script you need to understand what Pearson's R is; which is how correlated a set of data is to a line within a given deviation (+ or -).

If the Pearson's R is negative (-) then the trend is going upwards. If the value is positive (+) then the trend is going downwards.

There is a lot of debate as to what the ideal negative and positive values are for the Pearson's R, so you can change these in the settings. What the script will do is attempt to automatically find (and draw the trend lines ) based on a given minimum period and a maximum period (both set in the settings) that match the ideal Pearson's R settings selected.

Ideally the data is MOST correlated the closest it is to -1 or 1. This means the pattern is very reliable.

This script was designed and works very well with the bar replay mode. You may need a more professional version of TradingView to use this correctly. This mode allows you to see the script in action as it mutates and changes according to the new data being introduced.

I've pre-set the Pearson's R (+) and (-) ranges to what I think is ideal.

Phát hành các Ghi chú: This new version cleans up the code a bit and adds a better infobox thanks to richard santos and some modifications I did to his original code base. The colors of the info box are designed to better match the new oscillator partner script I uploaded as well.
Phát hành các Ghi chú: The box adjustment was not working so well so removed it for now.
Phát hành các Ghi chú: I changed the default values to 0.85 for both positive and negative to match the oscillator indicator. These can be changed in the settings. I also added alerts for the upper and upper max + lower and lower max trend lines. You can enable these alerts by going to alerts and adding a new alert then selecting my indicator and selecting from the alert options. Enjoy!
Phát hành các Ghi chú: Added new alerts for detecting bullish,bearing or sideways trends that you can set and alerts for both the long term and short term when these occurs so users can use webhooks to trigger trades based on these conditions. Some traders like to trade differently during different cycles, so this will allow you to do this programmatically now :). Thanks to TradeBoneDog for this suggestion :).

You can disable what shows in the infobox as well in the settings if you only care about seeing certain results so it doesn't get so cluttered in there ;).
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
-=Gentleman Goat=-

Bình luận

I recently added alerts to this script for the upper and max upper, lower and max lower trend lines. You can enable them by selecting the alerts tab option on the right menu bar then pressing the 'create alert' button or the + button above and then selecting my indicator from the 'condition' dropdown and then selecting the condition below it. If you need any help just let me know.
+1 Phản hồi
mfa_supertrader Gentleman-Goat
@Gentleman-Goat, This indicator helps me a lot now! Many thanks for the additional features!
+1 Phản hồi
Gentleman-Goat mfa_supertrader
@mfa_supertrader, antime, let me know if you have any other ideas!
Phản hồi
Gentleman-Goat mfa_supertrader
@mfa_supertrader, I added more alerts that may be useful, let me know.
Phản hồi
Hi, please advise, how to use this script, do i use it as a trend following or a counter trend, as the box description says in the the chart (should i follow what it said or counter it). Thank you.
Phản hồi
Thanks for sharing you script with the community, you're doing a great job! It will be great if you can add arrow to show buy and sell direction with this script. Thanks.
Phản hồi
I'm not able to see the linear regression lines on the chart . Cannot add a screen shot here in the comment. Only the infobox is coming .
Phản hồi
Thank you for helping the community with such a wonderful script. During Tradingview replay mode back-test I found it complement well with different strategies.

Before trying it in Real-time need your help to clarify the followings. (below mentioned setting changes are done through setting gear of Indicator and NOT directly inside code. If it needs to be changed in script, please advise)

On Intraday Chart (as you mentioned default settings work well with 4H chart and not work with lower time frame)
To apply it on 5minutes chart, I am trying to change the setting to> Min period 8, Max period 24 and Step by as 8 (multiple of min period 8 and hope this is what you meant)
But when Info Box display comes, at start shows Long Trend(LT) as 24 and Short Trend(ST) as 8 but after sometime ST keep changing to 12 & 16 and back to 8 instead of fixed Min & Max period set. Tried multiple settings and think that the numbers I entered is incompatible. So need your help to clarify.

1. As per your observations using this indicator what is the best intraday 5min chart Min Period, Step By and Max Period? (I tried 8 & 24 as Step by need to be multiples of them and it is closer to Fib 8 & 21 indicating short term trend). If possible, provide 2 or 3 setting options to experiment.
2. What is impact (better or worse) of increasing or decreasing the Step by other than PC processing power consumption?

On Daily chart (if understood correctly, the default setting of Min period 48 & Max period 360 is recommended for 4 hour chart. So, want to reconfirm whether you recommend other settings for daily or weekly chart too.
3. As per your observations using this indicator what is the best settings for Min Period, Step By and Max Period on Daily chart? If possible, provide 2 or 3 setting options to experiment.

On Weekly chart
4. As per your observations using this indicator what is the best settings for Min Period, Step By and Max Period on weekly chart?

General question
5. If understood correctly, you meant to enter "LONG" when Pearson R value is -0.85 for high probable solid reliable continuing trend and go "SHORT" when Pearson R value is 0.71 for high probable solid reliable trend. Please confirm this understanding is correct.
6. If above understanding is correct, whether changing default of -0.85 & 0.85 to -0.85 & 0.71 in settings of Oscillator and Strategy script is fine? Also whether it have any impact to other settings and need to be changed in settings or script.

Sorry to bother you with above questions as I am finding this indicator have high potential to filter out good probability trades when used correctly with any strategy. So clarifying above points will help me to try out this indicator.

Awaiting your reply.
Once again thank you for the efforts and sharing it to the community.
Phản hồi
@IdeasSJ, This will take me some time to respond, but wanted to let you know I got your questions. You can private chat me anytime as well. This will probably require some discussion. In short you will have to play with the settings to find out what is best for other time frames. I'm working on a version of this indicator for use in back trader in which different values can be tested for optimization purposes and then put back in here after. When I finish that I'll put a link to that here somehow if possible. I'll probably have to make some youtube videos on how to use it. The values for pearson's R are also subjective, but in general I've found the higher the number of the pearson's R either in negative or positive the more 'sure' the trend is, but also the more likely the trend will reverse soon. In a kind of weird irony, the more sure a trend becomes the more 'sure' it's trend will be 'undone' since more people are aware of it. As for the impact of the step parameter it's simply cpu usage time. If you set this to low the script on tradingview will timeout since it thinks it crashed. So you will have to play with this until you get the maximum values out of it that don't crash tradingview. The reason the the short trend keeps changing is because it attempts to find the pearson's R value that matches what you are looking for. So for example, if you set the pearson's r for uptrends to -0.85 then it will keep going bars back until it finds a combination that creates a linear regression that matches that 'trend sureness' so to speak. It will constantly be bouncing back and forth potentially especially in the early stages. In this indicator you'll notice I have another indicator which is an oscillator. You will want to use this. You will notice that whenever the short trend and the long trend meet when the settings are set correctly a trend reversal is coming. It correctly predicted bitcoins collapse on the covid date and it's subsequent recovery for example.
Phản hồi