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

Horizontal line over date range

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

    Horizontal line over date range

    Hello guys,

    can someone help me with developing a very simple indicator?

    All I want is to plot a single line whose y axis would vary according to the date. For instance, I have a 1 minute chart for the last 3 days and I want the line to be y=2,543 for 3rd date, y=2,00192 for the 2nd date and y=1,921 for the latest day. All plotted in one chart.

    Thanks a lot for your support!
    Stepan.

    #2
    Stepan, if these values aren't changing very often, you could just draw lines on the chart with the F2 key and then change the prices to whatever you want. These lines can also be saved so they return if you restart NinjaTrader.
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Stepan, if these values aren't changing very often, you could just draw lines on the chart with the F2 key and then change the prices to whatever you want. These lines can also be saved so they return if you restart NinjaTrader.
      OK, thanks Austin. That;s what I thought. But would it be possible then to refference such changing line in the strategy? If not, how should I do that?
      Thanks a lot.
      Stepan

      Comment


        #4
        Stephen, you could reference the manual drawn lines according to their tag id assigned in the draw objects collection - http://www.ninjatrader.com/support/h...rawobjects.htm
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Stephen, you could reference the manual drawn lines according to their tag id assigned in the draw objects collection - http://www.ninjatrader.com/support/h...rawobjects.htm
          Hi,

          let me just get back to this post. I manually added two horizontal lines to the chart. How will i add them to the code and how will I se the condition: If price is above the line, then buy? I went through your link but it didnt help me that much.
          Thanks a lot!
          Stepan

          Comment


            #6
            Stepan, you can loop through all of the draw objects on the chart with the code from the bottom of the IDrawObject help guide page and check the tag of each. If the tag matches what you've set on the chart (right-clicking the line -> properties -> data -> tag), you can get the y-value of the line. From this y-value, you will be able to compare the movement of the bars and see if they cross the line.
            Code:
            foreach (IDrawObject draw in DrawObjects)
            {
                // this assumes you've given the line a tag of "line1" (without the quotes)
                if (draw.Tag == "line1" && draw.DrawType == DrawType.HorizontalLine)
                {
                    IHorizontalLine myLine = (IHorizontalLine) draw;
                    // get the y value
                    double linePrice = myLine.Y;
                    Print("line price is...:   " + linePrice.ToString());
                }
            }
            AustinNinjaTrader Customer Service

            Comment


              #7
              I pasted the last piece of code posted by Austin into a test file to start modifying it and it throws up error codes when compiling.

              I get:

              "The type or namespace name 'IDrawObject could not be found..."
              "The name 'DrawType' does not exist in the current context"
              "The type or namespace name 'IHorizontalLine' could not be found"

              Am I missing a dll here or is there something else incorrect?

              My declarations are:

              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Indicator;
              using NinjaTrader.Strategy;

              Comment


                #8
                Mr_T_Fx, to test the snippet provided please use the attached indicator, add a horizontal line to your chart, change it's tag to line1 and then reload the Ninjascript with the output window opend.
                Attached Files
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by TradeForge, 04-19-2024, 02:09 AM
                2 responses
                28 views
                0 likes
                Last Post TradeForge  
                Started by aprilfool, 12-03-2022, 03:01 PM
                3 responses
                327 views
                0 likes
                Last Post NinjaTrader_Adrian  
                Started by giulyko00, Today, 12:03 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by f.saeidi, Today, 12:14 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by AnnBarnes, Today, 12:17 PM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Working...
                X