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

ATR Trend Indicator

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

    ATR Trend Indicator

    First, I'll start off by stating that I'm not a programmer, rather I'm working to learn and understand it so that I too can write my own code. Thus please bear with me, and I'll apologize upfront if some of this is basic to those with more experience.

    I have a couple of indicators that I use in Tradingview that I would like to duplicate the best I can in NinjaTrader. Below is the code out of Tradingview for the first indicator that I'm working on. This particular indicator looks at the WMA of the ATR, mixed with a couple of additional parameters, and plots it over the price bars. I've started by working to address each line individually and converting it into C#. However, when I attempt to compile it right now, I'm getting two errors; CS1502 & CS1503. One appears to state that it's overloaded and the second cannot convert from double to NinjaTrader. NinjaScript.Iseries<double>. These errors are specific to this line of code here: double AvgTR = WMA(ATR1, 21)[0];

    That being said, I've printed the full code that I've written in the attached PDF. If there is anyone that can help point me in the right direction, and perhaps provide some feedback, I would appreciate it.

    study(title="Trend Trader Strategy", overlay = true)
    Length = input(21, minval=1),
    Multiplier = input(3, minval=0.000001)
    avgTR = wma(atr(1), Length)
    highestC = highest(Length)
    lowestC = lowest(Length)
    hiLimit = highestC[1]-(avgTR[1] * Multiplier)
    loLimit = lowestC[1]+(avgTR[1] * Multiplier)
    ret = 0.0
    pos = 0.0
    ret:= iff(close > hiLimit and close > loLimit, hiLimit,
    iff(close < loLimit and close < hiLimit, loLimit, nz(ret[1], close)))
    pos:= iff(close > ret, 1,
    iff(close < ret, -1, nz(pos[1], 0)))
    barcolor(pos == -1 ? color.red: pos == 1 ? color.green : color.blue )
    plot(ret, color= color.blue , title="Trend Trader Strategy")
    Attached Files

    #2
    Import or View 'ExtATRTrend.cs' code in zip file
    Attached Files

    Comment


      #3
      Thank you MrSmart . I appreciate the help. I'll examine the code and learn from it to see what I was doing wrong.

      Comment


        #4
        Hello Lowerlevel1,

        Note, that programming in C# comes pre-requisite to writing NinjaScripts.
        Below is a link to a forum post with helpful resources on getting started with C# and NinjaScript.


        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          MrSmart

          Thank you for the help on the other indicator. And as I mentioned in my original post, it was one of two I was working to convert. The second one is an STC (Schaff Trend Cycle) indicator. Through different resources, I've managed to get most of it to work. However, the one piece that I'm missing, is getting the plot line to change colors based on a MACD equation that was used for direction. I'll copy and paste the original Pine Editor script below and attach my STC zip file but, would you be so kind to take a look at this one as well? Currently, it plots the line in a solid color correctly, but I'd like it to change the plot colors based on the value as it relates to the previous bar. In short, if it is greater than the bar before, plot green. Whereas if it is less, plot it red. Thanks in advance for any help you can provide.

          EEEEEE = input(12, 'Length')
          BBBB = input(26, 'FastLength')
          BBBBB = input(50, 'SlowLength')

          AAAA(BBB, BBBB, BBBBB) =>
          fastMA = ta.ema(BBB, BBBB)
          slowMA = ta.ema(BBB, BBBBB)
          AAAA = fastMA - slowMA
          AAAA

          AAAAA(EEEEEE, BBBB, BBBBB) =>
          AAA = input(0.5)
          var CCCCC = 0.0
          var DDD = 0.0
          var DDDDDD = 0.0
          var EEEEE = 0.0
          BBBBBB = AAAA(close, BBBB, BBBBB)
          CCC = ta.lowest(BBBBBB, EEEEEE)
          CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
          CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
          DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
          DDDD = ta.lowest(DDD, EEEEEE)
          DDDDD = ta.highest(DDD, EEEEEE) - DDDD
          DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
          EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
          EEEEE

          mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
          mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)



          if mAAAAA[3] <= mAAAAA[2] and mAAAAA[2] > mAAAAA[1] and mAAAAA > 75
          alert("Red", alert.freq_once_per_bar)
          if mAAAAA[3] >= mAAAAA[2] and mAAAAA[2] < mAAAAA[1] and mAAAAA < 25
          alert("Green", alert.freq_once_per_bar)


          plot(mAAAAA, color=mColor, title='STC', linewidth=2)

          ul = plot(25, color=color.new(color.gray, 70))
          ll = plot(75, color=color.new(color.gray, 70))
          fill(ul, ll, color=color.new(color.gray, 96))
          Attached Files

          Comment


            #6
            Lowerlevel1

            Your ZIP file has some problem.
            My web borwser deny downloading it because zip file has a problem.

            Anyway
            ...

            1. Goto EchoSystem


            2. Download

            3. Edit OnBarupdate method

            Original Code
            ----------------------
            protected override void OnBarUpdate()
            {
            sFrac1[0] = sMAX[0] - sMIN[0] > 0 ? 100 * (sMACD[0] - sMIN[0]) / (sMAX[0] - sMIN[0]) : sFrac1[1];
            sPF[0] = CurrentBar <= 1 ? sFrac1[0] : sPF[1] + (Factor * (sFrac1[0] - sPF[1]));
            sFrac2[0] = pMAX[0] - pMIN[0] > 0 ? 100 * (sPF[0] - pMIN[0]) / (pMAX[0] - pMIN[0]) : sFrac2[1];
            sPFF[0] = CurrentBar <= 1 ? sFrac2[0] : sPFF[1] + (Factor * (sFrac2[0] - sPFF[1]));

            Values[0][0] = sPFF[0];
            }


            Edit Code
            -------------------
            protected override void OnBarUpdate()
            {
            sFrac1[0] = sMAX[0] - sMIN[0] > 0 ? 100 * (sMACD[0] - sMIN[0]) / (sMAX[0] - sMIN[0]) : sFrac1[1];
            sPF[0] = CurrentBar <= 1 ? sFrac1[0] : sPF[1] + (Factor * (sFrac1[0] - sPF[1]));
            sFrac2[0] = pMAX[0] - pMIN[0] > 0 ? 100 * (sPF[0] - pMIN[0]) / (pMAX[0] - pMIN[0]) : sFrac2[1];
            sPFF[0] = CurrentBar <= 1 ? sFrac2[0] : sPFF[1] + (Factor * (sFrac2[0] - sPFF[1]));

            Values[0][0] = sPFF[0];

            // Add this codes
            //----------------------------
            if (CurrentBar > 0 )
            {
            PlotBrushes[0][0] = Values[0][0] > Values[0][1] ? Brushes.Lime : (Values[0][0] < Values[0][1] ? Brushes.Red : Brushes.DimGray);
            }

            }

            Good luck!

            Comment


              #7
              Thank you again Mr. Smart!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              3 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              0 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              13 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              2 views
              0 likes
              Last Post DanielTynera  
              Started by yertle, 04-18-2024, 08:38 AM
              9 responses
              42 views
              0 likes
              Last Post yertle
              by yertle
               
              Working...
              X