Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with SuperTrend Indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with SuperTrend Indicator

    Hello,
    Can someone help me with the code. This is a SuperTrend indicator. The problem is that the DownTrend line does not appear. See where the error is in the code? Thank you

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.LICO_indicators
    {
    public class LicoSuperTrend : Indicator
    {
    private Series<bool> Trend;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "LicoSuperTrend";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = false;
    DrawVerticalGridLines = false;
    PaintPriceMarkers = false;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    Period = 10;
    Multiplier = 2;
    
    AddPlot( new Stroke(Brushes.Lime, 2), PlotStyle.Line, "UpTrend");
    AddPlot( new Stroke(Brushes.Red, 2), PlotStyle.Line, "DownTrend");
    
    }
    else if (State == State.Configure)
    {
    Trend = new Series<bool>(this);
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar < Period)
    return;
    
    
    double bandUpper = Median[0] + Multiplier * ATR(Period)[0];
    double bandLower = Median[0] - Multiplier * ATR(Period)[0];
    
    if (Close[0] > DownTrend[1])
    Trend[0] = true;
    else if (Close[0] < UpTrend[1])
    Trend[0] = false;
    else
    Trend[0] = Trend[1];
    
    if (Trend[0] == true && Trend[1] == false)
    {
    UpTrend[0] = bandLower;
    UpTrend[1] = DownTrend[1];
    }
    else if (Trend[0] == false && Trend[1] == true)
    {
    DownTrend[0] = bandUpper;
    DownTrend[1] = UpTrend[1];
    }
    else if (Trend[0] == true)
    UpTrend[0] = bandLower > UpTrend[1] ? bandLower : UpTrend[1];
    else
    DownTrend[0] = bandUpper < DownTrend[1] ? bandUpper : DownTrend[1];
    
    }

    #2
    Hello locivata,

    Thanks for your post.

    Please note that in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services in our support. This is so that we can maintain a high level of service for all of our clients as well as our partners.

    That said, I do not see anything specific in the code you shared that would prevent the DownTrend plot from plotting.

    Debugging steps would need to be taken to understand why the script is behaving as it is. It is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi. Were you able to fix this? I have been looking for a simple Supertrend script and your script looks like it. Thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      41 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X