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

Customizing Trend Line Indicator

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

    Customizing Trend Line Indicator

    Hey guys, I've started to customize the Autotrend indicator, and First question I have:

    1. I want to make an alert when price is near a DrawnObject. For instance let's say that:
    Code:
    DrawLine("HistoryLine"+lineCount.ToString(), false, upTrendStartBarsAgo, startBarPrice, 0, startBarPrice+(upTrendStartBarsAgo*changePerBar), UpHistColor, upHistStyle, lineWidth);
    Draws a Line.

    Is there a way to capture that Line in some kind of Variable that I can maybe use for a Conditional Statement?

    i.e. Variable1 = Drawline() etc.

    #2
    Hello ginx10k,

    You could make a variable using ILine like the code below
    Here is a link to the Documentation on this item.


    Code:
    ILine line = DrawLine("HistoryLine"+lineCount.ToString(), false, upTrendStartBarsAgo, startBarPrice, 0, startBarPrice+(upTrendStartBarsAgo*changePerBar), UpHistColor, upHistStyle, lineWidth);
    If you want to use this same line through all the sections of your code you could add a private variable in your variables section

    Code:
    private ILine line = null;
    
    protected override void OnBarUpdate()
    {
    line = DrawLine("HistoryLine"+lineCount.ToString(), false, upTrendStartBarsAgo, startBarPrice, 0, startBarPrice+(upTrendStartBarsAgo*changePerBar), UpHistColor, upHistStyle, lineWidth);
    }
    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Getting Error

      Okay first, Thank, you for quick response. I tried out the ILine and IRay to hold the lines in a variable.
      Code:
       #region Variables private IRay ray = null; #endregion  ray = DrawRay("UpTrendRay", false, upTrendStartBarsAgo, startBarPrice, upTrendEndBarsAgo, endBarPrice, UpTrendColor, upLineStyle, lineWidth);
      That's just a sample of the code. When I try to use a Conditional Statement, I keep getting errors.
      Code:
      if(CrossBelow(Low, ray, 1) )
      Errors: http://screencast.com/t/w2WEjDiL


      I've attached a the indicator full code here, Just look at line 107 and 116


      P.S. IF the Reason is because the Low[0] is a Double and the ray is another datatype, then how do can I actually do this. That was the whole point of Putting the Lines or Ray in a Variable so that I can use it in conditional statement.

      Thanks
      Attached Files

      Comment


        #4
        Hello ginx10k,

        Thank you for providing the code as that will help debugging this.

        First thing that I noticed is the use of a break; statement inside an if loop. This type of statement would be better used in a switch statement. you should instead use a return; this will accomplish the same but will not throw an error in an if loop.

        The next item is the comparison that is being used is comparing a DataSeries to a Ray. When using the CrossAbove or CrossBelow methods they do require a data series which you had and a double value which was not quite there. I just had to add the "Anchor1Y" to the ray object to get its value so it looks like this

        Code:
        if (CrossBelow (Low, ray.Anchor1Y, 1)) {
        I also noticed you are using a barsAgo variable which I did not locate so I have added it at the top with your variables.

        I have included the .cs file you attached but it has been debugged so it should plot when you recompile with the changes.

        Please let me know if I may be of additional assistance.
        Attached Files
        JesseNinjaTrader Customer Service

        Comment


          #5
          ??

          Okay, it's compiling fine, however Anchor1Y is: A double value representing the y value of the 1st anchor point.

          I just saw that in the guide. The problem is that my indicator only Alerts when the Low or High of the First Anchor point is actually broken. If I use Anchor2Y it only alerts when the second Anchor is broken.

          What I am trying to do is get an Alert when ever Price Goes above the Ray or Line, No Matter how far away from the Anchors it is.

          Example: http://screencast.com/t/TCoHIbE5Sn


          So what is it that I'm missing. perhaps some calculation or something.

          Comment


            #6
            New Problem

            Okay, nevermind the last problem about calculations. I've uploaded my full code. the indicator Plots the Trendline RAY on new trends. and when it closes on Other Side of Line it cancels drawing the Ray. that's fine, however, when price returns back above the Trend line it begins drawing Same Ray as before as if it's the same trend line. Example: http://screencast.com/t/340hPlAfSEIV

            Check LINE 116. STEP 4a. where it's suppose to cancel the Entire Trend once price Closes beyond the Line.

            I don't know what I'm Missing here.


            Please Help!!
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by elirion, Today, 01:36 AM
            0 responses
            3 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Started by samish18, Yesterday, 08:31 AM
            2 responses
            9 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            391 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            34 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Working...
            X