Login Page - Create Account

Support Board


Date/Time: Fri, 29 Mar 2024 05:40:01 +0000



[Programming Help] - Ninja Trader 7 code block converted over to Sierra code

View Count: 4251

[2018-09-12 01:38:17]
JoseyWales - Posts: 67
You may never end up finding a perfect 1 to 1 match between SierraChart and NinjaTrader chart bars. A few reasons I can think of is different platforms may not use the same tick sizes. For example NT uses .00001 for non JPY Forex data, whereas SC uses .00005. Another reason is both SC and NT have their own interpretations of how to calculate Renko bars. If either NT or SC Renko bar logic differs from one another, then one may create a bar where the other does not. The last reason I can think of is NT uses "Break at end of day" and SC "New Bar on Season Start" settings and session times could be different. And the data providers may be different, therefore different raw tick data.

The biggest thing to learn/remember when programming SC ACSIL studies is variables and arrays that aren't a reference are destroyed at the end of the scope. And when AutoLoop = 1 this means it occurs at every update. Data assigned in a SCFloatArray will not be retained, whereas data in a SCFloatArrayRef will be. So the variables carryForward, result, and swing were being reset to 0 every iteration when they should have retained their value from the previous update. SC ACSIL is function like programming compared to NinjaScript's class based programming where a simple field stays in the scope of the class until the class is deleted, not on every update.

SierraChart has Persistent variables that solve this dilemma. If you don't need an entire SCFloatArrayRef and just need a variable to be carried over to the next update, use Persistent variables. It takes an int parameter as a key, so be sure to use different key values for persistent variables of the same type. And don't forget to make the type as a reference (double& name = sc.GetPersistentDouble(0), int& name = sc.GetPersistentInt(0)) so it is assignable. If you forget the reference operator, the code will compile fine but it will be confusing trying to debug until you realize you forgot to make it a reference type.

sc.GetPersistentInt()

This is the code as seen in my attached pictures. Changing the input named Factor changes the output much more than Trend Length. It has another input named "Color Background or Color Bars?" if the user wants to paint the background or bars. If you want to have the stop level as a single subgraph, you can create a new subgraph and assign to it the variable "result" in the bottom if/else blocks like Bullish/Bearish Lines do. The subgraph named Trend assigns -1 for bearish and 1 for bullish conditions. Because it is a subgraph, it can be referenced in an alert condition (ID1.SG3[0] > 0).

Study/Chart Alerts And Scanning

Apparently you can't have a subgraph painting the background and another subgraph painting the bar colors within the same indicator. That's why the user has to choose either or neither, but not both. It might be a SierraChart bug.

Let me know what you think and if there's any improvements I can make for you.


#include "sierrachart.h"

SCSFExport scsf_BG_ColorAndTrailingStop(SCStudyInterfaceRef sc)
{
  SCSubgraphRef BullishLine = sc.Subgraph[0];
  SCSubgraphRef BearishLine = sc.Subgraph[1];
  SCSubgraphRef Trend = sc.Subgraph[2];
  SCSubgraphRef BackgroundColor = 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 = "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;
    Trend.DrawZeros = false;

    BackgroundColor.Name = "Background Color";
    BackgroundColor.SecondaryColorUsed = true;
    BackgroundColor.PrimaryColor = COLOR_GREEN;
    BackgroundColor.SecondaryColor = COLOR_RED;
    BackgroundColor.DrawZeros = false;

    BarColor.Name = "Bar Color";
    BarColor.DrawStyle = DRAWSTYLE_COLOR_BAR;
    BarColor.PrimaryColor = COLOR_DODGERBLUE;
    BarColor.SecondaryColor = COLOR_RED;
    BarColor.SecondaryColorUsed = true;

    // 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_TRANSPARENT;
    else if (ColorType.GetIndex() == 2)
      BackgroundColor.DrawStyle = DRAWSTYLE_IGNORE;

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

imageSierraChart Color Background - Color Bar.png / V - Attached On 2018-09-12 01:22:06 UTC - Size: 404.92 KB - 453 views
imageSierraChart vs NinjaTrader 8 - Renko Comparison.png / V - Attached On 2018-09-12 01:23:21 UTC - Size: 550.33 KB - 488 views
Attachment Deleted.
[2018-09-12 02:47:51]
User701453 - Posts: 176
Wow, this is amazing.
You completed in a day, what I been trying to do for a week.
I spent more time trying to code this then i did trading or sleeping.

I will compile the code and let you know the results in a few minutes.
[2018-09-12 03:04:28]
User701453 - Posts: 176
JoseyWales,

Code remote compile with no errors, but when I added the study to the chart.
The renko candles disappeared, chart goes white and the price scale is blank.
selecting either option background or candle, the candles dont show up.

I have attached a screen shot, maybe I need to change a setting in the subgraphs?

I tested on SC version 1717 and 1802.
Date Time Of Last Edit: 2018-09-12 03:05:32
imagesc_josey.PNG / V - Attached On 2018-09-12 03:04:05 UTC - Size: 85.91 KB - 401 views
[2018-09-12 03:35:23]
JoseyWales - Posts: 67
I don't have access to NQU8 data so can you try on Forex data?
But first change the code block under the persistent variables:

  if (sc.Index < TrendLength.GetInt())
  {
    swing = 1;

    if (ColorType.GetIndex() == 1)
      BackgroundColor.DrawStyle = DRAWSTYLE_BACKGROUND_TRANSPARENT;
    else if (ColorType.GetIndex() == 2)
      BackgroundColor.DrawStyle = DRAWSTYLE_IGNORE;

    return;
  }

To this and recompile:

  if (sc.Index < TrendLength.GetInt())
  {
    swing = 1;

    if (ColorType.GetIndex() == 1)
      BackgroundColor.DrawStyle = DRAWSTYLE_BACKGROUND;
    else if (ColorType.GetIndex() == 2)
      BackgroundColor.DrawStyle = DRAWSTYLE_IGNORE;

    return;
  }

Maybe your computer wont allow transparent backgrounds.

And change BackgroundColor.PrimaryColor = COLOR_GREEN; to
BackgroundColor.PrimaryColor = COLOR_DARKGREEN;

and BackgroundColor.SecondaryColor = COLOR_RED; to
BackgroundColor.SecondaryColor = COLOR_DARKRED;
in the sc.SetDefaults Block, it wont be as harsh on the eyes.
[2018-09-12 03:55:14]
User701453 - Posts: 176
Made changes and still blank chart.
No candles and blank price scale.

I dont have forex data, broker only does futures.
[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 - 454 views
[2018-09-12 06:00:17]
User701453 - Posts: 176
That worked..
Screen shot attached.
I will play around with the settings and renko setting to get as close to ninja as possible...

Thanks so much for your assistance with this..
imagesc_josey2.PNG / V - Attached On 2018-09-12 05:45:00 UTC - Size: 55.19 KB - 391 views
[2018-09-12 06:08:12]
JoseyWales - Posts: 67
Great, I'm glad it's working for you.
[2018-09-12 06:18:06]
User701453 - Posts: 176
Josey I just sent you a DM.
[2018-09-12 07:54:18]
User701453 - Posts: 176
Josey,

Just found that when changing the factor input value.
Going from default 1.5 to 1.6 causes the lines to overlap or extend into the opposite color back ground region. Sometimes both long and short are visible at the same time.

The lines should begin and end with the matching corresponding back ground color.
Date Time Of Last Edit: 2018-09-12 07:55:53
imagesc_josey3.PNG / V - Attached On 2018-09-12 07:55:49 UTC - Size: 68.2 KB - 348 views
[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;
}

[2018-09-12 14:51:36]
User701453 - Posts: 176
made the code changes, but still the same results.
Attachment Deleted.
imagesc_josey5.PNG / V - Attached On 2018-09-12 14:47:20 UTC - Size: 70.38 KB - 348 views
[2018-09-12 16:03:31]
User701453 - Posts: 176
I think I have figured out the issue of the overlapping lines.
I changed the renko bar settings to not fill in the price gaps.

But there still both long and short lines are still appearing at the same time.

It still seems that the lines displayed should not be different then the background swing color.
Since they should both be based on the same price data.

However the gapfill, makes the number of candles per swing match up better with the ninja version.
Date Time Of Last Edit: 2018-09-12 16:17:56
imagesc_josey6_no gapfillchart.PNG / V - Attached On 2018-09-12 16:03:08 UTC - Size: 55.26 KB - 338 views
imagesc_josey6_no gapfillchartsettings.PNG / V - Attached On 2018-09-12 16:03:16 UTC - Size: 43.96 KB - 323 views
imagesc_josey6_no gapfillchart2.PNG / V - Attached On 2018-09-12 16:16:12 UTC - Size: 61.08 KB - 332 views
[2018-09-12 16:59:59]
JoseyWales - Posts: 67
Test this out, compile and remove the indicator from charts then re apply them. See how it behaves in real time.


#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];

  BullishLine[sc.Index] = 0;
  BearishLine[sc.Index] = 0;

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

[2018-09-12 18:40:31]
User701453 - Posts: 176
Did the copy and paste of code.
compiled and removed. then place study back on chart.

Made a factor input change from 1.6 to 2 and lines overlapped again.

Hit the insert key to reload and recal chart and lines matched the background switch again.
I thought it might need to wait until bar close to run the code.
So I added this code block before the persistant vars.

if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED)
  return;

Recompile and hit insert key.
Lines match the background.

Changed the factor value and lines no longer match.
Hit insert key and lines match again.
Lines are repainting.

So, I guess waiting until the bar closes doesn't solve the line and back ground mismatch.

Screen shots below..even tho the file name says no gap fill. chart is set for a gap fill of "fill all gaps"
Date Time Of Last Edit: 2018-09-12 18:53:06
imagesc_josey6_no gapfill_on input change.PNG / V - Attached On 2018-09-12 18:42:39 UTC - Size: 14.87 KB - 276 views
imagesc_josey6_no gapfill_after_chart_reload&cal.PNG / V - Attached On 2018-09-12 18:42:47 UTC - Size: 18.4 KB - 321 views
[2018-09-14 12:04:00]
User701453 - Posts: 176
Project update:
After spending lots of time fiddling with the SC chart settings and study that Josey was kind to assist me with.

I think I have finally got the SC renko candles to match Ninja custom bars.

In both size and number of red candle and green candles per wave.

Both background color swings match up in chart time,price and number of candles.

The lines however are close, but still could some more massaging..
Either in code or input settings.


Screen shots attached.
Date Time Of Last Edit: 2018-09-14 12:19:45
imageninja chart-1.PNG / V - Attached On 2018-09-14 12:02:00 UTC - Size: 33.81 KB - 324 views
imageSC chart-1.PNG / V - Attached On 2018-09-14 12:02:06 UTC - Size: 11.39 KB - 317 views
[2018-09-14 14:38:32]
User701453 - Posts: 176
Ran both Ninja and SC charts during the high volatility 9:30 am open to 10 am and the chart settings held up..
Matching up candle to candle on both platforms and each swing on the backgrounds...

The line values are not matching up as close in shape,will work on that this weekend.
See if they can be improved just a little bit..
[2019-03-07 20:06:09]
User420296 - Posts: 12
I am also a new user coming from NT to SC and needing NT's Renko bars (Mean Renko). Would it be too much to ask if User701453 could post the final version of JoseyWales's study and settings? It would be greatly appreciated.
Thanks
Ed
[2019-07-24 15:23:24]
User92573 - Posts: 465
I'd be very grateful for Scotts Chandelier version.

Thanks Ed. This post was really interesting and Josey Wales code helped a great deal.

Does any one know why the Kiwi Chandelier and this version produce such very different results when applied to a chart? Using the same inputs they differ significantly.

Many thanks, PH

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account