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

Draw Support&Reistance On a Chart

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

    Draw Support&Reistance On a Chart

    Hi,

    I want to draw two type of S&R on a chart;

    1) Draw 2 lines, 1% above (Close[0] * 1.1) and 1% below (Close[0] * 0.9) current price for a certain period (for example last 30 bars). For clarification look at First.png attachment.
    2) I want to draw open price of third day of each month continuously. For clarification look at Second.png attachment.

    This indicators are only for example, the formula that what i really want to do is a little bit complex.
    I didn't open seperate topic for these indicators because i think they are very similar to each other.
    I want to do these indicators as possible as simple but effective (fast process is important because many S&R will be draw on a chart at the same time)
    Also i want to use these indicators in a strategy. I think, simply calculate levels on a memory and draw a line via override plot method not work for me.

    Could you please tell me what is the best way to develop these type of indicators with ninjatrader.
    Or Could you please tell me is there any example about these type of indicators for guide me.

    Could you please tell me how can i solve my problem on ninjatrader.

    Regards,
    Aytac
    Attached Files

    #2
    Hello aytacasan,

    If you are developing new scripts, my first recommendation would be to use NinjaTrader 8 and not the legacy NinjaTrader 7 which is no longer in development and in it's final days of support.

    You can draw lines with Draw.Line() at any price value you calculate and use DashStyleHelper.Dash if you would like.



    Below I am providing a link to a forum post with helpful information about getting started with NinjaScript and C#.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your response.

      I have some third party indicators that not available nt8 and i'm writing indicators that similar of them. Because of that for now using nt7. After finish my investigation of course i'll write same indicators for nt8 which is better then nt7. Still thanks for your recomendation.

      You suggestion is each bar calculate value, override plot method and use drawline method for draw lines on chart(any where/any length/any style). Isn't it?
      Ok if so when i use drawline method, i can draw a line anywhere on chart. But if i'm not wrong, i can't access them from strategies. Solution is use in memory DataSeries object? Store all calculations on dataseries use that on plot method for drawing and access them from strategies?

      Thanks,
      Aytac

      Comment


        #4
        See the first attachement please.

        After a little work i create an indicator which is using DrarArrowUp/Down and DrawDot methods.

        First i want to ask two questions;
        1. I call them inside OnBarUpdate method. Is this a problem? Is it important that where i call them? for example i have to call them inside OnPlot method?
        2. They are drawing under price bars. Is there a way draw them over price bars? Shortly is there a z index or something like that for give an order to ninjatrader?

        Second some identifications;
        1. I can not see values (inside data box) of object that draw on a chart. So of course can not access them inside strategy that using the indicator.
        2. Which i understand form NT logic. There is a 3 way for ploting;
        2.1. You can override Plot method and with help Graphics object you can freely draw whatever you want. For them there is no data box support, they are not cache on dataseries, they are not setting indicators's values array.
        2.2. Narrow scope but easier vs first way you can use predefined methods like DrawDot, DrawArrow, DrawLine. Like first way they are only drawing on a chart and not store values anywhere.
        2.3. Or we can use Plot class which is using for plot formating purposes and somehow (i don't understand how) ninja associate it with dataseries. We can see them in indicator properties window. We can see in data box. We can access values inside any strategy.

        At that point i'm so confused

        I want to use plot support which u can customize plot from indcator propertis window and u can see values on data box window and because of values stroing dataseries u can access values in strategies. But also dont want to reset/change values continuously because of want to see output like second attachment(line drwaing only last 10 bar with current bar calculated value).

        I look at examples on your links and will continue to explore...
        Attached Files

        Comment


          #5
          Hello aytacasan,

          I was attempting to answer your question about how to draw a line. This is what you would like to achieve, is this correct?

          You can also have plots, which can be used as signals to strategies, alerts, or the market analyzer. When the plot is set, the drawing object can be drawn. (The regression channel indicator is an example of this)

          Drawing objects are fine to be drawn in data driven method like OnBarUpdate(), OnMarketData(), or OnMarketDepth().

          With non-data-driven methods, like a custom method from an event handler or a timer, will need to use TriggerCustomEvent() to synchronize the series first and allow the barsAgo values for the drawing object to be correct.


          Drawing objects are drawn at the price you specify. Try setting the price to High[0] + 3 * TickSize to calculate a price 3 ticks above the high.

          NinjaTrader does not support overriding the Plot method in an indicator for NinjaTrader 7 at all. If you choose to do this, you are on your own and our staff cannot assist.
          NinjaTrader 8 does fully support custom rendering in OnRender() and our staff is able to assist.


          Add(new Plot()) or AddPlot() adds a series. The Values collection is a collection of series used for the plot values for every bar on the chart. The Strategy Builder requires a plot from an indicator to be used as a hosted script. An unlocked script can directly access any public properties.



          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hello Chelsea,

            Yes you are right, my question is about draw a line. But at the same time i'm trying to understand what is the NinjaTrader logic that behind indicators.

            Yes i know plots, when there is a unique value for easch bar (like SMA indicator) i'm absolutely using them they are easy to use, user can customize their view via an indicator parameters window, you dont care how they will draw on a chart ninja doing that for you, you can access calculated values from a strategy etc.

            Here i have to do calculation for each bar but draw values different way. Think about that in real time when new bar appear i want to calculate 20 period SMA and plot current value on a chart a line start from current bar and end to currentbar - 10 (which is last 10 bar). So here we can not use plots If we do for each bar we have to set last 10 bars with new value and for all other bars we have to reset plot values which is dont think so, it is logical or effective way. With your suggestion and help i finished that step. I calculate value and draw a line on a chart. Because i'm using same Tag value for line it's updating correctly. But i'll explore regression channel indicator which is sounds good for me, maybe my other problems will solve.

            At that point i have two problems and preivous post i asked them. Fist i asked is it problem to call draw methods on OnBarUpdate and you said no problem you can call them data driven methods (i dont need call them from non data driven methods). I'm hapy to hear that, so i dont need to change my code.

            Also asked that is there a way to draw my objects front of bars. I think you look at my first attachment and see arrows and dots and because of that you suggest use High[0] + 3 * TickSize. But if you look at my second attachment you will see there is a support lines that behind bars which is disturbing. So i want to ask again is there a way draw objects front of main data series?


            Try to cut short my posts as possible as but i can't Sorry for stealing your time.

            For now i understand that we can freely plot our calculations on a chart via drawing methods. If we want to use indicator in a strategy for calculated values. We have to set indicators Values data series which interited from ninja's indicator base class. I hope it's easy as i thought, i'll test that.

            Thanks,
            Aytac

            Comment


              #7
              Hello Aytac,

              For NinjaTrader 7, there is no supported control for z-order.
              Call the drawing objects in the order you want them layered. Objects called first will be on the bottom.
              The z-order of drawing objects will be within the z-order of the host.


              With NinjaTrader 8 there is support for controlling z-order through NinjaScript. The z-order of drawing objects will still be within the z-order of the host, so be sure to the set the host z-order above the bars or other scripts you want this to default on top of.


              You can assign a drawing object to variable and then set the ZOrderType.
              Code:
              Rectangle myRect = Draw.Rectangle(this, "recta", true, 20, Close[0] + 30 * TickSize, 0, Close[0] - 5 * TickSize, Brushes.Blue, Brushes.Blue, 100);
              myRect.ZOrderType = DrawingToolZOrder.AlwaysDrawnLast; // this will be drawn on top


              Setting the myRect.ZOrder directly is not offically supported, meaning there may be unexpected behavior in specific circumstance, but tends to work in practice. SetZOrder() does not apply to calling drawing object methods.
              "Note: The ZOrder index should NOT be set using this property. Please use the dedicated SetZOrder() for this purpose."



              Where you have mentioned: "If we want to use indicator in a strategy for calculated values. We have to set indicators Values data series which interited from ninja's indicator base class."
              I'm not entirely sure what you mean. The host strategy can access any public object from the indicator.
              Code:
              private MyIndicator myIndy;
              
              In State.DataLoaded:
              myIndy = MyIndicator();
              
              In OnBarBarUpdate:
              myIndy.Update();
              myIndy.Values[0][0] = CurrentBar; // some value being assigned to the first plot in the indicator with AddPlot()
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hello Chelsea,

                Thanks for your very detailed explanation about ZOrder. It's so clear for me now.

                You said "I'm not entirely sure what you mean". It's normal because of my poor english and don't understand some parts of ninjatrader correctly. Previous post i think i can set indicator's Values dataseries whenever i want. Now i understand that if we add any plot via Add method after that we can set/use Values dataseries of indicator. For use Values[0] i have to add at least a plot to my indicator.

                Thanks for your tolerance to me and to my questions. I try to develop other parts of my indicator with your suggestions.

                Thanks a lot,
                Aytac

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Johnny Santiago, 10-11-2019, 09:21 AM
                95 responses
                6,193 views
                0 likes
                Last Post xiinteractive  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                2 responses
                11 views
                0 likes
                Last Post xiinteractive  
                Started by Irukandji, Today, 09:34 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by RubenCazorla, Today, 09:07 AM
                1 response
                5 views
                0 likes
                Last Post RubenCazorla  
                Started by TraderBCL, Today, 04:38 AM
                3 responses
                25 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X