Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,772 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X