Support Board
Date/Time: Tue, 04 Feb 2025 16:36:13 +0000
Post From: Ninja Trader 7 code block converted over to Sierra code
[2018-09-12 08:23:38] |
JoseyWales - Posts: 67 |
Looks like that bug only happens with real time data. Delete the old function and try this one out: #include "sierrachart.h" SCSFExport scsf_ATRStopAndColorBackground(SCStudyInterfaceRef sc) { SCSubgraphRef BackgroundColor = sc.Subgraph[0]; SCSubgraphRef BullishLine = sc.Subgraph[1]; SCSubgraphRef BearishLine = sc.Subgraph[2]; SCSubgraphRef Trend = sc.Subgraph[3]; SCSubgraphRef BarColor = sc.Subgraph[4]; SCSubgraphRef ATR = sc.Subgraph[5]; SCInputRef TrendLength = sc.Input[0]; SCInputRef Factor = sc.Input[1]; SCInputRef ColorType = sc.Input[2]; if (sc.SetDefaults) { sc.AutoLoop = 1; sc.FreeDLL = 0; sc.GraphName = "ATR Stop And Color Background"; sc.GraphRegion = 0; // Graphs BullishLine.Name = "Bullish Line"; BullishLine.DrawStyle = DRAWSTYLE_LINE_SKIP_ZEROS; BullishLine.PrimaryColor = COLOR_DODGERBLUE; BullishLine.LineWidth = 3; BearishLine.Name = "Bearish Line"; BearishLine.DrawStyle = DRAWSTYLE_LINE_SKIP_ZEROS; BearishLine.PrimaryColor = COLOR_MAGENTA; BearishLine.LineWidth = 3; Trend.Name = "Trend"; Trend.DrawStyle = DRAWSTYLE_IGNORE; Trend.SecondaryColorUsed = true; Trend.PrimaryColor = COLOR_GREEN; Trend.SecondaryColor = COLOR_RED; BackgroundColor.Name = "Background Color"; BackgroundColor.SecondaryColorUsed = true; BackgroundColor.PrimaryColor = RGB(0, 64, 0); BackgroundColor.SecondaryColor = RGB(64, 0, 0); BarColor.Name = "Bar Color"; BarColor.DrawStyle = DRAWSTYLE_COLOR_BAR; BarColor.SecondaryColorUsed = true; BarColor.PrimaryColor = COLOR_DODGERBLUE; BarColor.SecondaryColor = COLOR_RED; // Inputs TrendLength.Name = "Trend Length"; TrendLength.SetInt(20); Factor.Name = "Factor"; Factor.SetDouble(1.5); ColorType.Name = "Color Background or Color Bars?"; ColorType.SetCustomInputStrings("No;Color Background;Color Bars"); ColorType.SetCustomInputIndex(0); return; } double& carryForward = sc.GetPersistentDouble(0); double& result = sc.GetPersistentDouble(1); int& swing = sc.GetPersistentInt(0); if (sc.Index < TrendLength.GetInt()) { swing = 1; if (ColorType.GetIndex() == 1) { BackgroundColor.DrawStyle = DRAWSTYLE_BACKGROUND; BarColor.DrawStyle = DRAWSTYLE_IGNORE; } else if (ColorType.GetIndex() == 2) { BackgroundColor.DrawStyle = DRAWSTYLE_IGNORE; BarColor.DrawStyle = DRAWSTYLE_COLOR_BAR; } return; } sc.ATR(sc.BaseDataIn, ATR, TrendLength.GetInt(), MOVAVGTYPE_SIMPLE); double num = Factor.GetDouble() * ATR[sc.Index]; if (swing == 1 && sc.Close[sc.Index] <= result) { swing = -1; result = DBL_MAX; } else if (swing == -1 && sc.Close[sc.Index] >= result) { swing = 1; result = DBL_MIN; } if (swing == 1) { if (sc.Low[sc.Index] - carryForward > result) result = sc.Low[sc.Index] - carryForward; BullishLine[sc.Index] = result; BearishLine[sc.Index] = 0; Trend[sc.Index] = swing; // Color Bullish Trend.DataColor[sc.Index] = Trend.PrimaryColor; if (ColorType.GetIndex() == 1) { BackgroundColor[sc.Index] = swing; BackgroundColor.DataColor[sc.Index] = BackgroundColor.PrimaryColor; } else if (ColorType.GetIndex() == 2) { BarColor[sc.Index] = swing; BarColor.DataColor[sc.Index] = BarColor.PrimaryColor; } } else if (swing == -1) { if (sc.High[sc.Index] + carryForward < result) result = sc.High[sc.Index] + carryForward; BullishLine[sc.Index] = 0; BearishLine[sc.Index] = result; Trend[sc.Index] = swing; // Color Bearish Trend.DataColor[sc.Index] = Trend.SecondaryColor; if (ColorType.GetIndex() == 1) { BackgroundColor[sc.Index] = swing; BackgroundColor.DataColor[sc.Index] = BackgroundColor.SecondaryColor; } else if (ColorType.GetIndex() == 2) { BarColor[sc.Index] = swing; BarColor.DataColor[sc.Index] = BarColor.SecondaryColor; } } carryForward = num; } |