Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ways of plotting within a strategy

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

    ways of plotting within a strategy

    Hi,
    short question:
    Which possibilities are there to plot text and lines from within a strategy?
    I am trying to plot text at different(current pricelevels) at a fixed x coordinate of the chart, or a fixed amount away from the last bar which does not change if I zoom in or out, drawtext does not really do, what I want. are there other ways to do that.
    It is important to work from within a strategy.
    Last edited by keepsimple; 09-24-2014, 08:11 AM.

    #2
    Hello,

    Thank you for the question.

    I want to ask, are you trying to get the text's X position to stay with the initial bar position that you set it at?

    So as the bars progress the text would continue to the left with the bars, is this correct?

    If so you would need to store the texts X value as a variable and subtract that from the CurrentBar to get a bars ago. Here is a short example of that.

    Code:
    int textBar = 0;
            protected override void OnBarUpdate()
            {
    			if(CurrentBar == Count - 2)
    				textBar = CurrentBar - 25; // this will give an initial bar number once the chart has loaded
    			DrawText("tag", Close[0].ToString(), CurrentBar - textBar, Close[CurrentBar -textBar], Color.Red);
            }
    The code above will create a text that has a starting position of the CurrentBar - 25 bars.
    Now every time the bar updates it will subtract the initial bar location from the CurrentBar giving you the difference or the BarsAgo value.

    If this is not the result you are looking for please let me know.

    I look forward to being of further assistance.

    Comment


      #3
      Not sure if you really understood, what i meant, but I think that might work for my purposes too. I will give this a try and post back if I have any additional questions.

      thanks for quick reply and help

      Comment


        #4
        Sorry, think this is not, what I need.
        I have somrthing like DrawText("Name", "" + Value, -50, Currentprice, Color).
        And additional text in an similar way set to lets say -60 and - 70 bars ago.
        What happens when I zoom in or out, is that the difference between the Plots narrows till they finally overlap. so how can I get a fixed location or difference between the plots, independent from barwidth, or zoomfactor.
        I have an Indicator doing the same, where I used graphics.drawstring which works perfect.
        I need smething which works within a strategy.
        Last edited by keepsimple; 09-24-2014, 09:39 AM.

        Comment


          #5
          Hello,

          Thank you for the question.

          So to make sure I understand, you are more worried about the X position of the text in relation to the charts window and not to the bars them self am I correct? What I mean is you are trying to make the text not scale when you compress or decompress your X axis, is this right?

          If this is not correct please state exactly what you are trying to accomplish or an image of what you are seeing that you do not want to happen.

          If this is that you are trying to control the x of the text to not adjust for X Compression/ de compression this would need to be something that is done using the Plot override. Unfortunately there is not a lot of documentation related to this as it is not supported. If the above question is correct I can provide details on this and where you can find information about it.

          I look forward to being of further assistance.

          Comment


            #6
            Yes exactly, compression and decompression should have no effect on text.
            Problem is that for my understanding I cannot use override Plotmethod in straregy.

            Comment


              #7
              Hello,

              Thank you for the clarification.

              You are correct as you can not use this in the strategy.

              This would be something that if you are using it in combination with a strategy, you would need to create an indicator containing the strategy logic minus the order methods,this can then provide signals to your strategy.

              You could use the logic in the indicator to control your Plot override and text and then call the indicator from the strategy to create it. In the strategy you would use your core logic in determining when to place orders based on the indicators values.

              Please let me know if I may be of additional assistance.

              Comment


                #8
                Yes, thats what I thought.
                I just wondered because I saw strategies, where the plots had a fixed amount of difference from the bars, which stayed the same when compressed or decompressed, but moved with the bars with the fixed amount when you scrolled historically, so I think they were somehow anchored on the bars or a vertical line or whatever, they were not anchored in the chartwindow, like it whould be using graphics with coordinates.

                Comment


                  #9
                  Hello,

                  Yes this is most likely how they accomplished that sort of result. You are able to either anchor using the ChartControl bounds or also get x and y positions from specific bars/ price values so this is probably how the other items are displaying the data. If you use math you can calculate new widths for the text as it is drawn conforming to the bars around it.

                  There are a few resources on this if you did want to look into it. There is an example called CustomPlotSample, Also the Pivots indicator uses the Plot override to draw its lines.

                  There are some additional references on this forum and in random places throughout the internet using a google search but as this is a more advanced topic there is not a lot of content related to it.

                  If you decide to use the Plot override, if you have any questions regarding it please let me know and I will try to answer as best as I can on the subject as I have used it in a few situations for basic items so I am familiar with it.

                  I look forward to being of further assistance.

                  Comment


                    #10
                    Thanks,
                    the plot works fine in the indicator, only thing I whould have to work on, is how to include a indicator in a strategy which contains all that and has several input parameters.
                    Do you just use the initialize section using add? And do I use the parameter(input variable names) so that the inputs can be changed from the strategy properties?

                    Comment


                      #11
                      Hello,

                      Please see this document for adding indicators using a strategy: http://www.ninjatrader.com/support/h....html?add2.htm

                      You are correct though you use the Add() in initialize. If you want to use the Input from a public property you can just make sure you are using the private variable in the overload, here is an example of what I mean.

                      Code:
                      private int period = 10;
                      protected override void Initialize()
                      {
                               Add(SMA(period)); // use period not Period for your add statement
                      }
                      [Description("Period for slow MA")]
                      [GridCategory("Parameters")]
                      public int Period
                      {
                      	get { return period; }
                      	set { period = Math.Max(1, value); }
                      }
                      Please let me know if I may be of additional assistance .

                      Comment


                        #12
                        Yes, one last question.
                        When I add the indicator it asks for a Dataseries parameter? What do I put in there?

                        Comment


                          #13
                          Hello,

                          If an indicator asks for a DataSeries in the overloads it is referring to your price object or Open, Close, High, Low etc.. any of these would work.

                          Please note that Close is a dataSeries while Close[0] is the double value at 0 bars ago of the data series, so the indicator is just asking for Close without the BarsAgo or SMA(Close, 14) for example.

                          Please let me know if I may be of additional assistance.

                          Comment


                            #14
                            Thanks,
                            works so far, if I have any additional questions, I will post back.
                            You were of great help.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            656 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            371 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            109 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            574 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            579 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X