Support Board
Date/Time: Tue, 15 Apr 2025 14:21:34 +0000
[Programming Help] - My custom studies do not update correctly in real time
View Count: 89
[2025-03-28 23:29:04] |
User904259 - Posts: 2 |
My custom studies look messy and noisy when the chart updates in real time as new candles are added to the chart (studies in chart region 2 & chart region 3). However, when I open the Studies\Chart Studies dialog box and just Click ‘Apply’, the study gets re-evaluated . . . The study then looks noticeably different. It is far less messy, less chaotic and less noisy. The values of the study have been changed by the re-evaluation of the 'Apply" button. []Why do these studies not update correctly in real time? I am using manual looping with ‘sc.UpdateStartIndex’. I have included the block of code for study “Step(Close-StepPrice) RNK”. I have created other custom studies that have the same problem. How do I fix my custom studies to update correctly in real time? What am I doing wrong? SCSFExport scsf_StepCloseMinusStepPrice(SCStudyInterfaceRef sc)
{ float PRICE = 0; float POINT = 0.0f; float STEPSIZEA = 0.0f; float sMinA = 0.0f; float sMaxA = 0.0f; float& sMin1A = sc.GetPersistentFloatFast(0);// *** EACH 'int' AND 'float' PERSISTENT VARIABLE *** float& sMax1A = sc.GetPersistentFloatFast(1);// *** NEEDS ITS OWN INDEX NUMBER. *** int& TRENDA = sc.GetPersistentIntFast(0); // *** THESE ARE -NOT- INITIAL VALUES. *** float POINTB = 0.5f; float STEPSIZEB = 0.0f; float sMinB = 0.0f; float sMaxB = 0.0f; float& sMin1B = sc.GetPersistentFloatFast(2);// *** EACH 'int' AND 'float' PERSISTENT VARIABLE *** float& sMax1B = sc.GetPersistentFloatFast(3);// *** NEEDS ITS OWN INDEX NUMBER. *** int& TRENDB = sc.GetPersistentIntFast(1); // *** THESE ARE -NOT- INITIAL VALUES. *** SCSubgraphRef Subgraph_StepClsMnsStpPrc = sc.Subgraph[0]; SCSubgraphRef Subgraph_ZeroLine = sc.Subgraph[1]; SCFloatArray SteppedPrice; SCFloatArray CloseMinusStepPrice; SCInputRef Input_StepSizeA = sc.Input[0]; SCInputRef Input_StepSizeB = sc.Input[1]; // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "Step(Close-StepPrice) RNK"; sc.AutoLoop = 0; //Automatic looping off sc.UpdateAlways = 1; sc.GraphRegion = 1; Subgraph_StepClsMnsStpPrc.Name = "Step(Close-StepPrice) RNK"; Subgraph_StepClsMnsStpPrc.DrawStyle = DRAWSTYLE_LINE; Subgraph_StepClsMnsStpPrc.PrimaryColor = RGB(0, 255, 100); Subgraph_StepClsMnsStpPrc.DrawZeros = true; Subgraph_ZeroLine.Name = "Zero Line"; Subgraph_ZeroLine.DrawStyle = DRAWSTYLE_LINE; Subgraph_ZeroLine.LineWidth = 1; Subgraph_ZeroLine.PrimaryColor = RGB(255, 255, 255); Subgraph_ZeroLine.DrawZeros = true; Input_StepSizeA.Name = "StepSizeA"; Input_StepSizeA.SetFloat(100.0f); Input_StepSizeB.Name = "StepSizeB"; Input_StepSizeB.SetFloat(10.0f); return; } // Section 2 - Do data processing here //SCString Message; //Message.Clear(); //Message.Format("## Message HERE"); EXAMPLE Message.AppendFormat("Price %f, ", Price); //sc.AddMessageToLog(Message, 0); // a non-popped up message that goes to 'Sierra Chart/Window/Message Log' STEPSIZEA = Input_StepSizeA.GetFloat(); STEPSIZEB = Input_StepSizeB.GetFloat(); POINT = sc.TickSize; for (int Index = sc.UpdateStartIndex; Index < sc.ArraySize; Index++) { PRICE = (sc.BaseData[SC_RENKO_OPEN][Index] + sc.BaseData[SC_RENKO_CLOSE][Index]) / 2; sMaxA = PRICE + 2 * STEPSIZEA * POINT; sMinA = PRICE - 2 * STEPSIZEA * POINT; if (PRICE > sMax1A) TRENDA = 1; if (PRICE < sMin1A) TRENDA = -1; if (TRENDA > 0 && sMinA < sMin1A) sMinA = sMin1A; if (TRENDA < 0 && sMaxA > sMax1A) sMaxA = sMax1A; if (TRENDA > 0) SteppedPrice[Index] = sMinA + STEPSIZEA * POINT; if (TRENDA < 0) SteppedPrice[Index] = sMaxA - STEPSIZEA * POINT; sMin1A = sMinA; sMax1A = sMaxA; CloseMinusStepPrice[Index] = (sc.BaseData[SC_RENKO_CLOSE][Index] - SteppedPrice[Index]); // ----------------------------------------------------------------------------------------- sMaxB = CloseMinusStepPrice[Index] + 2 * STEPSIZEB * POINTB; sMinB = CloseMinusStepPrice[Index] - 2 * STEPSIZEB * POINTB; if (CloseMinusStepPrice[Index] > sMax1B) TRENDB = 1; if (CloseMinusStepPrice[Index] < sMin1B) TRENDB = -1; if (TRENDB > 0 && sMinB < sMin1B) sMinB = sMin1B; if (TRENDB < 0 && sMaxB > sMax1B) sMaxB = sMax1B; if (TRENDB > 0) Subgraph_StepClsMnsStpPrc[Index] = sMinB + STEPSIZEB * POINTB; if (TRENDB < 0) Subgraph_StepClsMnsStpPrc[Index] = sMaxB - STEPSIZEB * POINTB; sMin1B = sMinB; sMax1B = sMaxB; Subgraph_ZeroLine[Index] = 0.0f; } } |
[2025-03-29 21:36:33] |
ForgivingComputers.com - Posts: 1040 |
Since you are looking at Renko Open and Close values, I suggest waiting for the bar to close before updating the subgraphs. if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
return; |
[2025-04-03 23:22:34] |
User904259 - Posts: 2 |
Thank you . . . this is a good suggestion. I added this to my code and the study still changes when the 'Apply' is clicked. You are correct, this is happening because of the way the 'Close' is handled using the Renko charts. I created a version that only uses the 'Open' to see if it updated messy in real-time and then changed when 'Apply' is clicked. The 'Open' version does not change any when the 'Apply' is clicked in the 'Chart Studies' form. The 'Open' version remains the same. I also tested the 'Close' version a bit with range charts. The real-time updating of the 'Close' study is also changed when a bit when the 'Apply' is clicked for the Range charts but it is not as big of a change. |
To post a message in this thread, you need to log in with your Sierra Chart account: