Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trend Line doesn't work

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

    Trend Line doesn't work

    Hi, i am really novice. I wanted to developed indicator, that make trend line from first bar of seasson to end bar of seasson, but it is does not working and i do not know where is the issue. Any advice? Thank you.

    namespace NinjaTrader.NinjaScript.Indicators.Lucky
    {
    public class SessionTrendLine : Indicator
    {
    private int startBar = -1;
    private int endBar = -1;
    private double closeBar = -1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Indikátor, který vytváří trendovou linii spojující první a poslední svíčku v seanci.";
    Name = "SessionTrendLine";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    AddPlot(Brushes.Transparent, "InvisiblePlot");
    }
    }

    protected override void OnBarUpdate()
    {
    // Pokud není zvolena daily, weekly nebo monthly svíčka
    if (BarsInProgress != 0)
    return;

    // Zjisti, zda se jedná o první svíčku v seanci
    if (Bars.IsFirstBarOfSession)
    {
    startBar = CurrentBar;
    }

    // Zjisti, zda se jedná o poslední svíčku v seanci
    if (Bars.IsLastBarOfSession)
    {
    endBar = CurrentBar;
    closeBar= Close[0];

    // Vytvoření trendové linie

    if (startBar >= 0 && endBar >= 0)
    {
    Print(startBar);
    Print(endBar);
    Print(closeBar);
    Draw.Line(this, "tag1" + CurrentBar, false, startBar, closeBar, endBar, closeBar, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
    }
    }
    }
    }
    }​

    #2
    I already made that.

    Comment


      #3
      Hello LuckyChillda,

      Thank you for your post.

      Are you trying to draw 1 trend line? Or many lines?

      To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, 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.

      In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition.

      The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

      The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

      Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

      I am happy to assist you with analyzing the output from the output window.

      Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

      Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

      https://support.ninjatrader.com/s/ar...nd-TraceOrders

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      368 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      571 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X