Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time and price draw rectangle

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

    time and price draw rectangle

    hi! (sry my english!)

    i wanna see my trades in rectangle

    my idea is

    i use this prices and times

    for example

    almost every day i open 15-20 trades
    but i dont want to paint a rectangle one bye one
    so my idea is

    im using this

    Draw.Rectangle(this, "tag1", false, 10, Low[10] - TickSize, 5, High[5] + TickSize, Brushes.PaleGreen, Brushes.PaleGreen, 2);

    but how i can change it to work on prices and times ?

    open date
    09.16.2015 10:03
    close date
    09.16.2015 10:09
    open price
    1.12732
    close price
    1.12567

    this datas i wanna to draw a rectangle

    this is possible ?
    or other way?

    #2
    Hello hunadamka,

    Thank you for writing in.
    Please use the following override:
    Code:
    Draw.Rectangle(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, Brush areaBrush, int areaOpacity);
    Based on your example, your code might look like the following:
    Code:
    Draw.Rectangle(this, "tag1", false, openDate, openPrice, closeDate, closePrice, Brushes.PaleGreen, Brushes.PaleGreen, 2);
    where openDate is a DateTime variable set to 09.16.2015 10:03, openPrice is a double variable set to 1.12732, closeDate is a DateTime variable set to 09.16.2015 10:09 and closePrice is a double variable set to 1.12567

    More information on this method can be found in our help guide here: http://ninjatrader.com/support/helpG...draw.rectangle

    Please let me know if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      can you write an example
      my time and price ?

      beucase i try but not working maybe a problem i not use ninja 8

      Comment


        #4
        Hello hunadamka,

        Could you please clarify which version of the platform you are using? The code you originally provided is for NinjaTrader 8. Are you trying to create a NinjaTrader 7 code?

        Thank you in advance.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          oO yes i'm workig on ninja 7 (7.0.1000.26)

          sry i dont know is an ninja 8 code

          Draw.Rectangle(this, "tag1", false, 10, Low[10] - TickSize, 5, High[5] + TickSize, Brushes.PaleGreen, Brushes.PaleGreen, 2);

          so if "this" in a code is mean a ninja 8 code ?

          and this is a 7 ?

          DrawRectangle("tag1", false, 10, Low[10] - TickSize, 5, High[5] + TickSize, Color.PaleGreen, Color.PaleGreen, 2);

          Comment


            #6
            Hello hunadamka,

            To clarify, in Ninjatrader 8, the Draw methods were all moved into the Draw class. This is why you use "Draw.Rectangle" instead of "DrawRectangle" like in NinjaTrader 7.

            The same code I presented below but for NinjaTrader 7 would use the following override:
            Code:
            DrawRectangle(string tag, bool autoScale, DateTime startTime, double startY, DateTime endTime, double endY, Color color, Color areaColor, int areaOpacity)
            The same code based on your earlier example would look like the following:
            Code:
            DrawRectangle("tag1", false, openDate, openPrice, closeDate, closePrice, Color.PaleGreen, Color.PaleGreen, 2);
            Here is a full example of what I believe is the idea you are trying to develop:
            Code:
                    #region Variables
            			private int maxPositions = 5, counter = 0;
            			private bool isExiting = false;
            			private IOrder firstOrder, lastOrder, middleOrder;
            			private DateTime firstTime = DateTime.MinValue, lastTime = DateTime.MinValue;
                    #endregion
                    protected override void Initialize()
                    {
                        CalculateOnBarClose = true;
                    }
                    protected override void OnBarUpdate()
                    {
            			if(Historical) return;
            			if(counter < maxPositions)
            			{
            				EnterLong();
            				counter++;
            			}
                    }
            		protected override void OnExecution(IExecution e)
            		{
            			if(firstTime == DateTime.MinValue && e.Order.OrderState == OrderState.Filled)
            			{
            				firstTime = e.Time;
            			}
            			else if(Position.Quantity == maxPositions && e.Order.OrderState == OrderState.Filled){
            				isExiting = true;
            				ExitLong();
            			}
            			else if(isExiting && e.Order.OrderState == OrderState.Filled)
            			{
            				lastTime = e.Time;
            				DrawRectangle("Rectangle" + CurrentBar.ToString(), false, CurrentBar - Bars.GetBar(firstTime), Low[CurrentBar - Bars.GetBar(firstTime)] - 2 * TickSize, CurrentBar - Bars.GetBar(lastTime), High[CurrentBar - Bars.GetBar(lastTime)] + 2 * TickSize, Color.PaleGreen, Color.PaleGreen, 2);
            				firstTime = DateTime.MinValue;
            				isExiting = false;
            			}
            		}
            Please let me know if I may be of further assistance.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              thank you!
              tomorrow i try it
              (I don't have orders)

              but i think this code is useful if i trading on ninja
              but i'm not trading on ninja i just analysing my trades



              i'm try to share more details

              so i trading on fxcm analysing on ninja

              copy my trades the excel files same like this

              Code:
                                        A                          B                                         C                     D
                 1            open date               close date                       open price       close price            
                 2       09.16.2015 10:03      09.16.2015 10:09             1.12732           1.12567
              so after i finish trading just copy this numbers and ninjatrader drawing boxes

              Comment


                #8
                Hello hunadamka,

                Thank you for clarifying.

                You just need to create and populate the following variables:
                Code:
                private DateTime openDate = Convert.ToDateTime("09/16/2015 10:03:00.00");
                private double openPrice = 1.12732;
                private DateTime closeDate = Convert.ToDateTime("09/16/2015 10:09:00.00");
                private double closePrice = 1.12567;
                Once your variables are set, you can simply use the following code inside your OnBarUpdate method:
                Code:
                DrawRectangle("tag1", false, openDate, openPrice, closeDate, closePrice, Color.PaleGreen, Color.PaleGreen, 2);
                Please let me know if I may be of further assistance.
                Michael M.NinjaTrader Quality Assurance

                Comment


                  #9
                  Yes now its working!

                  Thank you very much!


                  + 1 question

                  and if i wanna to draw 3-4 or more rectangle ?

                  Comment


                    #10
                    Hello hunadamka,

                    If all your data is setup the same way, you could try something like this:
                    Code:
                    #region Variables
                        private DateTime[] openDates, closeDates;
                        private double[] openPrices, closePrices;
                        private int numRectangles = 4; //Number of rectangles to draw
                    #endregion
                    protected override void Initialize()
                    {
                    openDates = new DateTime[numRectangles];
                    openPrices = new double[numRectangles];
                    closeDates = new DateTime[numRectangles];
                    closePrices = new double[numRectangles];
                    
                    //First Rectangle
                    openDates[0] = Convert.ToDateTime("09/16/2015 10:03:00.00");
                    openPrices[0] = 1.12732;
                    closeDates[0] = Convert.ToDateTime("09/16/2015 10:09:00.00");
                    closePrices[0] = 1.12567;
                    
                    //Second Rectangle
                    openDates[1] = Convert.ToDateTime("09/17/2015 10:03:00.00");
                    openPrices[1] = 1.12732;
                    closeDates[1] = Convert.ToDateTime("09/17/2015 10:09:00.00");
                    closePrices[1] = 1.12567;
                    
                    //Third Rectangle
                    openDates[2] = Convert.ToDateTime("09/18/2015 10:03:00.00");
                    openPrices[2] = 1.12732;
                    closeDates[2] = Convert.ToDateTime("09/18/2015 10:09:00.00");
                    closePrices[2] = 1.12567;
                    
                    //Fourth Rectangle
                    openDates[3] = Convert.ToDateTime("09/19/2015 10:03:00.00");
                    openPrices[3] = 1.12732;
                    closeDates[3] = Convert.ToDateTime("09/19/2015 10:09:00.00");
                    closePrices[3] = 1.12567;
                    
                    }
                    protected override void OnBarUpdate()
                    {
                        for(int i = 0; i < numRectangles; i++)
                        {
                            DrawRectangle("Rect" + i.ToString(), false, openDates[i], openPrices[i], closeDates[i], closePrices[i], Color.PaleGreen, Color.PaleGreen, 2);
                        }
                    }
                    Please let me know if I may be of further assistance.
                    Michael M.NinjaTrader Quality Assurance

                    Comment


                      #11
                      perfect! : )

                      thx!

                      now i happy to working

                      and next time maybe ninja read my excel file (.xlsx)
                      and drawing rectangle's
                      but i think this is a future : )

                      Comment


                        #12
                        Hello hunadamka,

                        It is always my pleasure. Please have a great rest of your week!
                        Michael M.NinjaTrader Quality Assurance

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by xiinteractive, Today, 08:29 AM
                        1 response
                        3 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by DT215, 08-08-2023, 11:03 AM
                        3 responses
                        442 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by Thomas79, Today, 08:14 AM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by linneon, Yesterday, 09:04 PM
                        2 responses
                        15 views
                        0 likes
                        Last Post linneon
                        by linneon
                         
                        Started by burtoninlondon, 10-03-2023, 03:59 AM
                        3 responses
                        763 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X