Support Board
Date/Time: Fri, 18 Apr 2025 04:25:13 +0000
Post From: My custom studies do not update correctly in real time
[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; } } |