Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Identification of Trend using LinReg

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

    Identification of Trend using LinReg

    I'm trying to write a simple indicator that will print text on screen when conditions are met between the last bar close and the last bar LinReg(80) value. If the close value is higher than the LinReg(80) value I want to print "Up Market". If the close value is lower than the LinReg(80) value I want to print "Down Market." However, being a newbie with NT, I can't seem to get the code to perform this task. Here is the snippet.

    if (CrossAbove(LinReg(80), Close,1))
    {
    DrawTextFixed("UpMarket", "UpMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopRight);
    }
    if (CrossBelow(LinReg(80), Close,1))
    {
    DrawTextFixed("DownMarket", "DownMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopLeft);
    }

    The text prints, but BOTH of the IF statements yield a TRUE value which results in both lines of text being printed on screen. Both conditions can't be TRUE at the same time. What am I doing wrong?

    Thanks

    #2
    Hello Mikefra,

    Welcome to the NinjaTrader forums!

    DrawTextFixed() will draw the first time there is a crossover, and there's no logic there to remove it. You can use RemoveDrawObject() to remove it.

    if (CrossAbove(LinReg(80), Close,1))
    {
    DrawTextFixed("UpMarket", "UpMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopRight);
    }

    else
    RemoveDrawObject("UpMarket");

    if (CrossBelow(LinReg(80), Close,1))
    {
    DrawTextFixed("DownMarket", "DownMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopLeft);
    }

    else
    RemoveDrawObject("DownMarket");
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Why use two text boxes?

      Or just try this:

      if (CrossAbove(LinReg(80), Close,1))
      {
      DrawTextFixed("UpDnText", "UpMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopRight);
      }

      if (CrossBelow(LinReg(80), Close,1))
      {
      DrawTextFixed("UpDnText", "DownMkt: " + LinReg(80)[1] + " close: " + Close[1], TextPosition.TopRight);
      }

      Untested though.

      Dan
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        These replies were both very helpful. I figured it out. Thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X