Support Board
Date/Time: Tue, 26 Nov 2024 23:37:58 +0000
Post From: Color of Subgraph getting reset incorrectly inconsistently.
[2023-10-17 20:54:54] |
rajeshh - Posts: 8 |
Hello - I have the study below to illustrate the problem I am having. Would appreciate anyone trying it out and seeing why its doing so? /*
The following study is to illustrate the problem I am having - Basically I am showing an UP arrow below a bar n-1 when the next bar n goes above it, and a DOWN arrow above a bar when the next bar goes below its low. If the bar n also takes out the other side of the bar n-1, I want the arrows to be colored yellow. This is not working consistently for all the bars. Looking at my code, once yellow color has been set on the bar, I dont understand how its getting reset. */ SCSFExport scsf_TestLastDataColor(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_Down = sc.Subgraph[0]; SCSubgraphRef Subgraph_Up = sc.Subgraph[1]; if (sc.SetDefaults) { sc.GraphName = "Test Last DataColor"; sc.AutoLoop = true; sc.GraphRegion = 0; sc.ValueFormat= VALUEFORMAT_INHERITED; Subgraph_Down.Name = "Down"; Subgraph_Down.DrawStyle = DRAWSTYLE_ARROW_DOWN; Subgraph_Down.DrawZeros = false; Subgraph_Down.LineWidth = 1; Subgraph_Up.Name = "Up"; Subgraph_Up.DrawStyle = DRAWSTYLE_ARROW_UP; Subgraph_Up.DrawZeros = false; Subgraph_Up.LineWidth = 1; return; } int n = sc.Index; bool UpTriggered, DownTriggered; UpTriggered = sc.High[n] > sc.High[n-1]; //Bar n has gone above prior bar n-1 DownTriggered = sc.Low[n] < sc.Low[n-1]; //Bar n has gone below prior bar n-1 if (UpTriggered ) { //Only set it if it hasnt been set already if ( Subgraph_Up[n-1] ==0 ) { Subgraph_Up[n-1] = sc.Low[n-1] - sc.TickSize; Subgraph_Up.DataColor[n-1] = RGB(0,200,255); } } else Subgraph_Up[n-1] = 0; if (DownTriggered ) { //Only set it if it hasnt been set already if ( Subgraph_Down[n-1] ==0) { Subgraph_Down[n-1] = sc.High[n-1] + sc.TickSize; Subgraph_Down.DataColor[n-1] = COLOR_RED; } } else Subgraph_Down[n-1] = 0; //Bar n has gone above the prior bar and then below the prior bar //In this case, color the arrow Yellow. if (UpTriggered && sc.BaseData[SC_LAST][n] < sc.Low[n-1]) { Subgraph_Up.DataColor[n-1] = COLOR_YELLOW; } //Bar n has gone below the prior bar and then above the prior bar //In this case, color the arrow Yellow. if (DownTriggered && sc.BaseData[SC_LAST][n] > sc.High[n-1] ) { Subgraph_Down.DataColor[n-1] = COLOR_YELLOW; } } |