//original native sierra chart "extend bar gap until future intersection" study with option to show open gaps only. #include "sierrachart.h" SCDLLName("Extend Bar Gap v2") static void NativeExtendBarGapUntilFutureIntersection(SCStudyInterfaceRef sc) { SCSubgraphRef Subgraph_LinePropertiesSubgraph = sc.Subgraph[0]; SCInputRef Input_DisplayValueLabel = sc.Input[0]; SCInputRef Input_NameLabel = sc.Input[1]; SCInputRef Input_CompareToOpentoCloseRangeOnly = sc.Input[2]; if (sc.SetDefaults) { // Set the configuration and defaults. sc.GraphName = "Extend Bar Gap Until Future Intersection"; Subgraph_LinePropertiesSubgraph.Name = "Line Properties"; Subgraph_LinePropertiesSubgraph.DrawStyle = DRAWSTYLE_SUBGRAPH_NAME_AND_VALUE_LABELS_ONLY; Subgraph_LinePropertiesSubgraph.LineWidth = 1; Subgraph_LinePropertiesSubgraph.PrimaryColor = COLOR_RED; Subgraph_LinePropertiesSubgraph.DrawZeros = false; Input_DisplayValueLabel.Name = "Display Value Label"; Input_DisplayValueLabel.SetYesNo(true); Input_NameLabel.Name = "Name Label"; Input_NameLabel.SetString(""); Input_CompareToOpentoCloseRangeOnly.Name = "Compare to Open to Close Range Only"; Input_CompareToOpentoCloseRangeOnly.SetYesNo(false); sc.ValueFormat = VALUEFORMAT_INHERITED; sc.GraphRegion = 0; sc.AutoLoop = 1; return; } if (sc.Index == 0) return; t_ChartArrayDataType ExtendPrice = 0.0; if (!Input_CompareToOpentoCloseRangeOnly.GetYesNo()) { //Check for up gap if (sc.FormattedEvaluate(sc.High[sc.Index - 1], sc.BaseGraphValueFormat, LESS_OPERATOR, sc.Low[sc.Index], sc.BaseGraphValueFormat)) { ExtendPrice = sc.High[sc.Index - 1]; } //Check for down gap else if (sc.FormattedEvaluate(sc.Low[sc.Index - 1], sc.BaseGraphValueFormat, GREATER_OPERATOR, sc.High[sc.Index], sc.BaseGraphValueFormat)) { ExtendPrice = sc.Low[sc.Index - 1]; } else { return; } } else { t_ChartArrayDataType PriorMaxValue = max(sc.Open[sc.Index - 1], sc.Close[sc.Index - 1]); t_ChartArrayDataType PriorMinValue = min(sc.Open[sc.Index - 1], sc.Close[sc.Index - 1]); t_ChartArrayDataType MaxValue = max(sc.Open[sc.Index], sc.Close[sc.Index]); t_ChartArrayDataType MinValue = min(sc.Open[sc.Index], sc.Close[sc.Index]); //Check for up gap if (sc.FormattedEvaluate(PriorMaxValue, sc.BaseGraphValueFormat, LESS_OPERATOR, MinValue, sc.BaseGraphValueFormat)) { ExtendPrice = PriorMaxValue; } //Check for down gap else if (sc.FormattedEvaluate(PriorMinValue, sc.BaseGraphValueFormat, GREATER_OPERATOR, MaxValue, sc.BaseGraphValueFormat)) { ExtendPrice = PriorMinValue; } else { return; } } SCString NameLabelString = Input_NameLabel.GetString(); bool DisplayNameLabel = false; if (!NameLabelString.IsEmpty()) DisplayNameLabel = true; sc.AddLineUntilFutureIntersection ( sc.Index - 1 , 0 // LineIDForBar. Use 0 since there is only one line per bar. , ExtendPrice , Subgraph_LinePropertiesSubgraph.PrimaryColor , Subgraph_LinePropertiesSubgraph.LineWidth , Subgraph_LinePropertiesSubgraph.LineStyle , Input_DisplayValueLabel.GetYesNo() , DisplayNameLabel , NameLabelString ); } //hide intersected lines SCSFExport scsf_ExtendBarGapV2(SCStudyInterfaceRef sc) { if (sc.LastCallToFunction) return; NativeExtendBarGapUntilFutureIntersection(sc); SCInputRef ShowOpenGapsOnly = sc.Input[3]; if (sc.SetDefaults) { sc.GraphName = "Extend Bar Gap v2"; ShowOpenGapsOnly.Name = "Show Open Gaps Only"; ShowOpenGapsOnly.SetYesNo(false); return; } sc.UpdateAlways = ShowOpenGapsOnly.GetYesNo(); if (!ShowOpenGapsOnly.GetYesNo() || sc.Index != sc.ArraySize - 1) return; for (int i = sc.GetNumLinesUntilFutureIntersection( sc.ChartNumber, sc.StudyGraphInstanceID) - 1; i >= 0; --i) { int lineID = 0; int startIndex = 0; int endIndex = 0; t_ChartArrayDataType price = 0; if (sc.GetStudyLineUntilFutureIntersectionByIndex( sc.ChartNumber, sc.StudyGraphInstanceID, i, lineID, startIndex, price, endIndex) && endIndex > 0) { sc.DeleteLineUntilFutureIntersection(startIndex, lineID); } } }