Support Board
Date/Time: Tue, 21 Oct 2025 14:10:03 +0000
[User Discussion] - polynomial regression channel
View Count: 134
[2025-10-03 15:26:22] |
User411320 - Posts: 348 |
Hello, by selecting "No" for Use Redraw (In:5), will this stop the indicator from repainting ? |
![]() |
[2025-10-03 16:25:42] |
John - SC Support - Posts: 42471 |
Since that is not one of our studies, we do not know. We supply the User Contributed Studies without any support for them. We also do not appear to have the source code for this, so you can not look to see what it does. For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2025-10-03 16:42:33] |
User411320 - Posts: 348 |
Hello John, Isn't the following the source code? /*==========================================================================*/
// // PRC - Polynomial Regression Channel // // 20110329 - written by aslan // 20100330 - added redraw option // SCSFExport scsf_PolynomialRegressionChannel(SCStudyInterfaceRef sc) { SCInputRef Input_PolyDegree = sc.Input[0]; SCInputRef Input_Period = sc.Input[1]; SCInputRef Input_StdDev1 = sc.Input[2]; SCInputRef Input_StdDev2 = sc.Input[3]; SCInputRef Input_Redraw = sc.Input[4]; SCSubgraphRef Subgraph_Fx = sc.Subgraph[0]; SCSubgraphRef Subgraph_Upper2 = sc.Subgraph[1]; SCSubgraphRef Subgraph_Upper1 = sc.Subgraph[2]; SCSubgraphRef Subgraph_Lower1 = sc.Subgraph[3]; SCSubgraphRef Subgraph_Lower2 = sc.Subgraph[4]; if (sc.SetDefaults) { sc.GraphName = "Polynomial Regression Channel"; sc.StudyDescription = "Polynomial Regression Channel"; Input_PolyDegree.Name = "Polynomial Degree (1-4)"; Input_PolyDegree.SetInt(3); Input_PolyDegree.SetIntLimits(1, 4); Input_Period.Name = "PRC Period"; Input_Period.SetInt(150); Input_Period.SetIntLimits(1, 10000); Input_StdDev1.Name = "Standard Deviation Level 1"; Input_StdDev1.SetFloat(1.618f); Input_StdDev1.SetFloatLimits(0, 1000); Input_StdDev2.Name = "Standard Deviation Level 2"; Input_StdDev2.SetFloat(2.0); Input_StdDev2.SetFloatLimits(0, 1000); Input_Redraw.Name = "Use Redraw"; Input_Redraw.SetYesNo(1); Subgraph_Fx.Name = "Mid"; Subgraph_Fx.DrawZeros = false; Subgraph_Fx.DrawStyle = DRAWSTYLE_LINE; Subgraph_Fx.LineWidth = 1; Subgraph_Fx.LineStyle = LINESTYLE_DOT; Subgraph_Fx.PrimaryColor = COLOR_GRAY; Subgraph_Upper2.Name = "Upper 2"; Subgraph_Upper2.DrawZeros = false; Subgraph_Upper2.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_TOP; Subgraph_Upper2.PrimaryColor = COLOR_RED; Subgraph_Upper1.Name = "Upper 1"; Subgraph_Upper1.DrawZeros = false; Subgraph_Upper1.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_BOTTOM; Subgraph_Upper1.PrimaryColor = COLOR_RED; Subgraph_Lower1.Name = "Lower 1"; Subgraph_Lower1.DrawZeros = false; Subgraph_Lower1.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_TOP; Subgraph_Lower1.PrimaryColor = COLOR_BLUE; Subgraph_Lower2.Name = "Lower 2"; Subgraph_Lower2.DrawZeros = false; Subgraph_Lower2.DrawStyle = DRAWSTYLE_TRANSPARENT_FILL_BOTTOM; Subgraph_Lower2.PrimaryColor = COLOR_BLUE; sc.AutoLoop = true; sc.DrawZeros = false; sc.GraphRegion = 0; sc.GlobalDisplayStudySubgraphsNameAndValue = 0; sc.DisplayStudyName = 0; sc.DisplayStudyInputValues = 0; return; } struct s_PRCData { double ai[10][10]; double b[10]; double x[10]; double sx[20]; }; int& lastIndex = sc.GetPersistentInt(1); int& nn = sc.GetPersistentInt(2); s_PRCData *p_PRCMemory = (s_PRCData *) sc.GetPersistentPointer(1); if (sc.LastCallToFunction) { // This study is being removed from the chart or the chart is being closed - cleanup if (p_PRCMemory != 0) { sc.FreeMemory(p_PRCMemory); p_PRCMemory = 0; sc.SetPersistentPointer(1, p_PRCMemory); } return; } if (sc.Index == 0) { lastIndex = -1; sc.ValueFormat = sc.BaseGraphValueFormat; if (p_PRCMemory != 0) sc.FreeMemory(p_PRCMemory); p_PRCMemory = (s_PRCData*)sc.AllocateMemory(sizeof(s_PRCData)); sc.SetPersistentPointer(1,p_PRCMemory); if (p_PRCMemory == 0) return; // set up static vars s_PRCData& PRCData = *p_PRCMemory; nn = Input_PolyDegree.GetInt() + 1; //----------------------sx------------ PRCData.sx[1] = Input_Period.GetInt() + 1; for(int i=1;i<=nn*2-2;i++) { double sum = 0.0; for(int n=0;n<=Input_Period.GetInt();n++) { sum+=pow(static_cast<double>(n),i); } PRCData.sx[i+1]=sum; } } // make sure we have enough bars to start if (sc.Index < Input_Period.GetInt()) return; // erase old data on new bar if (sc.Index != lastIndex) { lastIndex = sc.Index; if (Input_Redraw.GetYesNo()) { Subgraph_Fx[sc.Index-Input_Period.GetInt()-1] = 0; Subgraph_Upper2[sc.Index-Input_Period.GetInt()-1] = 0; Subgraph_Upper1[sc.Index-Input_Period.GetInt()-1] = 0; Subgraph_Lower1[sc.Index-Input_Period.GetInt()-1] = 0; Subgraph_Lower2[sc.Index-Input_Period.GetInt()-1] = 0; } } // now lets do the real work if (p_PRCMemory == 0) return; s_PRCData& PRCData = *p_PRCMemory; //----------------------syx----------- for(int i=1;i<=nn;i++) { double sum=0.0; for(int n=0;n<=Input_Period.GetInt();n++) { if(i==1) sum+=sc.Close[sc.Index-n]; else sum+=sc.Close[sc.Index-n]*pow(static_cast<double>(n),i-1); } PRCData.b[i]=sum; } //===============Matrix=============== for(int j=1;j<=nn;j++) { for(int i=1; i<=nn; i++) { int k=i+j-1; PRCData.ai[i][j]=PRCData.sx[k]; // reset ai matrix } } //===============Gauss================ for(int k=1; k<=nn-1; k++) { int l=0; double m=0.0; for(int i=k; i<=nn; i++) { if(abs(PRCData.ai[i][k])>m) { m=abs(PRCData.ai[i][k]); l=i; } } if(l==0) return; if (l!=k) { double tt = 0.0; for(int j=1; j<=nn; j++) { tt=PRCData.ai[k][j]; PRCData.ai[k][j]=PRCData.ai[l][j]; PRCData.ai[l][j]=tt; } tt=PRCData.b[k]; PRCData.b[k]=PRCData.b[l]; PRCData.b[l]=tt; } for(int i=k+1;i<=nn;i++) { double qq=PRCData.ai[i][k]/PRCData.ai[k][k]; for(int j=1;j<=nn;j++) { if(j==k) PRCData.ai[i][j]=0; else PRCData.ai[i][j]=PRCData.ai[i][j]-qq*PRCData.ai[k][j]; } PRCData.b[i]=PRCData.b[i]-qq*PRCData.b[k]; } } PRCData.x[nn]=PRCData.b[nn]/PRCData.ai[nn][nn]; for(int i=nn-1;i>=1;i--) { double tt=0.0; for(int j=1;j<=nn-i;j++) { tt=tt+PRCData.ai[i][i+j]*PRCData.x[i+j]; PRCData.x[i]=(1/PRCData.ai[i][i])*(PRCData.b[i]-tt); } } //==================================== for(int n=0;n<=Input_Period.GetInt();n++) { double sum=0.0; for(int k=1;k<=Input_PolyDegree.GetInt();k++) { sum+=PRCData.x[k+1]*pow(static_cast<double>(n),k); } if (n==0 || Input_Redraw.GetYesNo()) Subgraph_Fx[sc.Index-n] = static_cast<float>(PRCData.x[1]+sum); } //-------------------Std-------------- double sq=0.0, sq1=0.0, sq2=0.0; for(int n=0;n<=Input_Period.GetInt();n++) { sq+=pow(sc.Close[sc.Index-n]-Subgraph_Fx[sc.Index-n],2); } sq=sqrt(sq/(Input_Period.GetInt()+1)); sq1=sq*Input_StdDev1.GetFloat(); sq2=sq*Input_StdDev2.GetFloat(); for(int n=0;n<=Input_Period.GetInt();n++) { if (n==0 || Input_Redraw.GetYesNo()) { Subgraph_Upper1[sc.Index-n] = static_cast<float>(Subgraph_Fx[sc.Index-n]+sq1); Subgraph_Lower1[sc.Index-n] = static_cast<float>(Subgraph_Fx[sc.Index-n]-sq1); Subgraph_Upper2[sc.Index-n] = static_cast<float>(Subgraph_Fx[sc.Index-n]+sq2); Subgraph_Lower2[sc.Index-n] = static_cast<float>(Subgraph_Fx[sc.Index-n]-sq2); } } } I'm not a coder, so I can be wrong |
[2025-10-03 16:53:03] |
John - SC Support - Posts: 42471 |
Possibly - probably. Where did you find it? I did not see the "Polynomial Regression Analysis" listed in the list of contributed studies code at the following link (but I did not look into every file): User Contributed Advanced Custom Study System Source Code For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2025-10-03 16:59:42] |
User411320 - Posts: 348 |
Attached are images where I found it
|
![]() ![]() |
[2025-10-03 17:49:11] |
John - SC Support - Posts: 42471 |
Then that would be the study source code. Thank you.
For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
[2025-10-03 18:14:06] |
User411320 - Posts: 348 |
I'm not a coder, so as I understand as long as I have the redraw option as "No", it won't repaint.
|
[2025-10-03 18:47:30] |
John - SC Support - Posts: 42471 |
If you add the study and toggle "Use Redraw" to "Yes" and "No" you will see that you get different results. So it is not just a matter of not re-painting the study. We will not go into any further analysis of this. For the most reliable, advanced, and zero cost futures order routing, use the Teton service: Sierra Chart Teton Futures Order Routing |
To post a message in this thread, you need to log in with your Sierra Chart account: