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

DrawLine Help

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

    DrawLine Help

    Hi Guys,

    What I am trying to accomplish seems very simple, but is driving me crazy. I simply want an indicator that plots a line segment that lasts 5 bars just as the attached file.

    Specifically in the attached the segment start on the low of the bar, after 4 consecutive lows. This is the code I am using, it gives me no compiling errors, but when I apply this indicator to a chart nothing really happens, can anybody advise what I am doing wrong:

    protected override void Initialize()
    {

    CalculateOnBarClose = false;
    Overlay = true;

    }

    protected override void OnBarUpdate()
    {

    if (Low[0] <Low[1] && Low[1] <Low[2] &&Low[2] <Low[3])
    {
    DrawLine("tag1" + CurrentBar, true, 0000, Low[0], 0000, Low[0] + 5, Color.Red, DashStyle.Solid, 2);
    }

    I tried following NT website instruction on DrawLine() but I am sure I am missing out in the variables(), initiatialize() and/or protect override void() sections.
    Attached Files

    #2
    Originally posted by sburtt View Post
    Hi Guys,

    What I am trying to accomplish seems very simple, but is driving me crazy. I simply want an indicator that plots a line segment that lasts 5 bars just as the attached file.

    Specifically in the attached the segment start on the low of the bar, after 4 consecutive lows. This is the code I am using, it gives me no compiling errors, but when I apply this indicator to a chart nothing really happens, can anybody advise what I am doing wrong:

    protected override void Initialize()
    {

    CalculateOnBarClose = false;
    Overlay = true;

    }

    protected override void OnBarUpdate()
    {

    if (Low[0] <Low[1] && Low[1] <Low[2] &&Low[2] <Low[3])
    {
    DrawLine("tag1" + CurrentBar, true, 0000, Low[0], 0000, Low[0] + 5, Color.Red, DashStyle.Solid, 2);
    }

    I tried following NT website instruction on DrawLine() but I am sure I am missing out in the variables(), initiatialize() and/or protect override void() sections.
    Ok basically i figured out exaclty how to DrawLine, however i still have an ISSUE. If I use a condition such as:

    if (CrossAbove(Close, SMA(20), 1))
    {

    DrawLine(...)

    it works perfectly, but if I use the condition as below, nothing happens on the chart:

    if (Low[0] <Low[1] && Low[1] <Low[2] &&Low[2] <Low[3])

    Please could somebody explain to me why?

    Comment


      #3
      Originally posted by sburtt View Post
      Hi Guys,

      protected override void OnBarUpdate()
      {

      Code:
          if (Low[0] <Low[1] && Low[1] <Low[2] &&Low[2] <Low[3])
      {


      I tried following NT website instruction on DrawLine() but I am sure I am missing out in the variables(), initiatialize() and/or protect override void() sections.
      If you open up tools->options->output window or something like that, you should see an error message about "index out of range".

      This should help you resolve the error:

      Comment


        #4
        thanks all sorted, really helpful!

        I was missing this:

        if(CurrentBar < 10)
        return; if(CurrentBar < 10)
        return;

        I have 1 last thing to ask you, do you know how I can apply text next to the line specifing the value of the close? so a number rather than simple text
        Last edited by sburtt; 02-16-2013, 10:56 AM.

        Comment


          #5
          Sledge, would you know how to make this indicator visible in a strategy? It works on my charts, but I am unable to build a strategy that goes long on the breach of the high (first condition) or short on the breach of the low (second condition):

          public class aatest : Indicator
          {
          #region Variables
          private int plotWidth = 2;
          #endregion


          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          Overlay = true;
          PlotsConfigurable = false;
          }

          protected override void OnBarUpdate()
          {
          if(CurrentBar < 10)
          return;

          if (Low[0] < Low[1] && Low[1] < Low[2])
          {
          DrawLine("" + CurrentBar, false, -1, High[2], -5, High[2], Color.Green, DashStyle.Solid, plotWidth);
          }

          if (High[0] > High[1] && High[1] > High[2])
          {
          DrawLine("" + CurrentBar, false, -1, Low[2], -5, Low[2], Color.Red, DashStyle.Solid, plotWidth);
          }

          }
          #region Properties


          [Description("Width.")]
          [Category("Plot Parameters")]
          [Gui.Design.DisplayNameAttribute("Width")]
          public int PlotWidth
          {
          get { return plotWidth; }
          set { plotWidth = Math.Max(1, value); }
          }

          }
          #endregion
          }

          is it possible to create a Value.Set and Add(new Plot) for a DrawLine?

          Comment


            #6
            Originally posted by sburtt View Post
            ... would you know how to make this indicator visible in a strategy?
            You Add() it to the Strategy in the Initialize() method. That is the only purpose of the statement when used in a Strategy. At least that is what the NT Help says.

            ref: http://www.ninjatrader.com/support/h...s/nt7/add2.htm

            ... is it possible to create a Value.Set and Add(new Plot) for a DrawLine?
            The way that you intend to use your construct, that is called a Donchian Channel. You are using it with a period of 4. It ships with NT.

            Comment


              #7
              Originally posted by koganam View Post
              You Add() it to the Strategy in the Initialize() method. That is the only purpose of the statement when used in a Strategy. At least that is what the NT Help says.

              ref: http://www.ninjatrader.com/support/h...s/nt7/add2.htm



              The way that you intend to use your construct, that is called a Donchian Channel. You are using it with a period of 4. It ships with NT.
              Hi Koganam, it's not really a Donchian channel.. I am looking at a series of lows, to then buy the break of the high. However, this is not the point. If you read the code I've attached, my indicator only draws a line, doesn't have a value.set, hence when you add() to strategy, you can view the indicator on the chart, but that is it. For example, you would be unable to use the indicator for a CrossAbove EntryLong() signal as there is nothing to cross, let me know if this is clear. Thanks,

              said this I could use the Donchian channel, but only for an entry valid in the next 5 bars, would you know how to code that?
              Last edited by sburtt; 02-17-2013, 10:42 AM.

              Comment


                #8
                Originally posted by sburtt View Post
                Hi Koganam, it's not really a Donchian channel.. I am looking at a series of lows, to then buy the break of the high. However, this is not the point. If you read the code I've attached, my indicator only draws a line, doesn't have a value.set, hence when you add() to strategy, you can view the indicator on the chart, but that is it. For example, you would be unable to use the indicator for a CrossAbove EntryLong() signal as there is nothing to cross, let me know if this is clear. Thanks,

                said this I could use the Donchian channel, but only for an entry valid in the next 5 bars, would you know how to code that?
                I am confused. I agree that I may have misunderstood. Could you specify the requirements in proper mechanical order then?

                You said this: "... that goes long on the breach of the high (first condition) or short on the breach of the low (second condition):". Maybe I misunderstood the qualifying condition and what high/low break qualifies the signal?

                Comment


                  #9
                  Originally posted by koganam View Post
                  I am confused. I agree that I may have misunderstood. Could you specify the requirements in proper mechanical order then?

                  You said this: "... that goes long on the breach of the high (first condition) or short on the breach of the low (second condition):". Maybe I misunderstood the qualifying condition and what high/low break qualifies the signal?
                  your right, prob I should have been more specific, I was referencing to the following code:

                  protected override void OnBarUpdate()
                  {
                  if(CurrentBar < 10)
                  return;

                  if (Low[0] < Low[1] && Low[1] < Low[2])
                  {
                  DrawLine("" + CurrentBar, false, -1, High[2], -5, High[2], Color.Green, DashStyle.Solid,1);
                  }



                  Basically this script draws green segment lines that last only for 3 sessions, and that I would like to use to go long once these lines (see attached) are crossed over by the Close value. The code above enables me to draw the lines, but not to use them as a signal. Are you able to explain me what to do in order to transform the segmented line into a proper signal to introduce in a strategy? Thanks
                  Attached Files

                  Comment


                    #10
                    Originally posted by sburtt View Post
                    your right, prob I should have been more specific, I was referencing to the following code:

                    protected override void OnBarUpdate()
                    {
                    if(CurrentBar < 10)
                    return;

                    if (Low[0] < Low[1] && Low[1] < Low[2])
                    {
                    DrawLine("" + CurrentBar, false, -1, High[2], -5, High[2], Color.Green, DashStyle.Solid,1);
                    }


                    Basically this script draws green segment lines that last only for 3 sessions, and that I would like to use to go long once these lines (see attached) are crossed over by the Close value. The code above enables me to draw the lines, but not to use them as a signal. Are you able to explain me what to do in order to transform the segmented line into a proper signal to introduce in a strategy? Thanks
                    Sorry, still not clear. So the trigger line is the unconditional High[2], or the highest high reached within those qualifying bars?

                    Comment


                      #11
                      the trigger line is the unconditional High[2].

                      so lets assume I am trading ES on a 60min chart and that the following condition is true:

                      Low[0] < Low[1] && Low[1] < Low[2]

                      Lets assume ES closes at 1500, hence Close[0] = 1500 and that High[2] = 1520

                      Starting from the next 60 min observation period I would go long we trade above 1520, this long trigger signal would last only for 5 periods.

                      Is this clear? Thanks,

                      Comment


                        #12
                        Originally posted by sburtt View Post
                        the trigger line is the unconditional High[2].

                        so lets assume I am trading ES on a 60min chart and that the following condition is true:

                        Low[0] < Low[1] && Low[1] < Low[2]

                        Lets assume ES closes at 1500, hence Close[0] = 1500 and that High[2] = 1520

                        Starting from the next 60 min observation period I would go long we trade above 1520, this long trigger signal would last only for 5 periods.

                        Is this clear? Thanks,
                        So what action is required if at the open of bar0, it is already above High[2]?

                        Comment


                          #13
                          Originally posted by koganam View Post
                          So what action is required if at the open of bar0, it is already above High[2]?
                          With bar0 i guess you refer to the new bar. If this is the case, giving thr scenario above, we are assuming that ES jumps over 20 points in just a second, however the action reqred would be EnterLong.

                          I want to EnterLong on a breakout of High[2], but only if the condition stated in my earlier thread is true, and i would like this entry signal to remain valid only for the next 5 bars.

                          Is there a way i can tell my NT strategy to keep an unconditional trigger only for a number n of bars?

                          Comment


                            #14
                            Originally posted by sburtt View Post
                            With bar0 i guess you refer to the new bar. If this is the case, giving thr scenario above, we are assuming that ES jumps over 20 points in just a second, however the action reqred would be EnterLong.

                            I want to EnterLong on a breakout of High[2], but only if the condition stated in my earlier thread is true, and i would like this entry signal to remain valid only for the next 5 bars.

                            Is there a way i can tell my NT strategy to keep an unconditional trigger only for a number n of bars?
                            So let us write the technical spec then.

                            Trigger Condition: 3 consecutive bars where the low on each is lower than the low of the previous bar.
                            Entry Condition: Go long on break of the high of the first bar in the pattern (High[2])
                            Entry Validity: If no entry after 5 bars of the trigger, entry is invalid.
                            Plots: Entry Level.

                            Is that correct? Is that the only Plot that you want to see?

                            Comment


                              #15
                              Yes, it looks correct.
                              Yes the only plot i would like to see is the Entry Level ( for only 5 bars)

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rocketman7, Today, 09:41 AM
                              4 responses
                              15 views
                              0 likes
                              Last Post rocketman7  
                              Started by selu72, Today, 02:01 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Started by WHICKED, Today, 02:02 PM
                              2 responses
                              12 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by f.saeidi, Today, 12:14 PM
                              8 responses
                              21 views
                              0 likes
                              Last Post f.saeidi  
                              Started by Mikey_, 03-23-2024, 05:59 PM
                              3 responses
                              52 views
                              0 likes
                              Last Post Sam2515
                              by Sam2515
                               
                              Working...
                              X