Login Page - Create Account

Support Board


Date/Time: Sun, 28 Apr 2024 19:18:51 +0000



Post From: Ninja Trader 7 code block converted over to Sierra code

[2018-09-12 04:37:21]
JoseyWales - Posts: 67
Here's a slightly modified version that doesn't use transparency (saves on performance anyway), you can change that back if you want to but it has to be done from the code. You can change the color from the subgraphs tab, but not the draw style. Choose between Color bars and Color background on the inputs tab. Note that I changed the function name and study name to "ATR Stop And Color Background". I also had to move the BackgroundColor subgraph to 0 so it gets drawn first. Attached is an ES 5 Tick Regular Renko chart with it applied. Try opening a new chartbook and tab and applying the study to rule out local chart graphics.


#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.DrawStudyUnderneathMainPriceGraph = 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;
    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;

    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;
}

Date Time Of Last Edit: 2018-09-12 04:40:42
imageES Renko 5T.png / V - Attached On 2018-09-12 04:32:18 UTC - Size: 275.8 KB - 457 views