• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plot() with chart periods filtering

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

    Plot() with chart periods filtering

    Hello

    I use my indicator on 1 min chart.

    1. I got blink effect of drawed rectangles on chart. Suppose this is because I filter 1 tick period in Plot(). But I dont need draw indicator for 1tick Bars on chart. And without filter I got error "Index out of range".
    How can I get Bars object for main period of chart?

    2. Why ChartControl.BarWidth is smaller than actual candle width on chart? Where is true width of a candle?

    Code:
                // AggressiveTradeDraw class 
                public void Draw(Graphics graphics)
                {
                    int barWidth = indicator.ChartControl.BarWidth + 4;
                    int x0 = indicator.ChartControl.GetXByBarIdx(indicator.Bars, AggressiveTrade.StartBarIdx) - barWidth / 2;
                    int x1 = indicator.ChartControl.GetXByBarIdx(indicator.Bars, AggressiveTrade.StopBarIdx) + barWidth / 2;
                    int y0 = indicator.ChartControl.GetYByValue(indicator.Bars, AggressiveTrade.StartPrice);
                    int y1 = indicator.ChartControl.GetYByValue(indicator.Bars, AggressiveTrade.StopPrice);
                    int h = Math.Abs(y0 - y1);
                    y0 = Math.Min(y0, y1);
    
                    graphics.FillRectangle(brush, x0, y0, x1 - x0, h);
                }
    
            protected override void Initialize()
            {
                Add(PeriodType.Tick, 1);
                CalculateOnBarClose = false;
                Overlay = true;
                //LogLevel = 3;
            }
    
           public override void Plot( Graphics graphics, Rectangle bounds, double min, double max)
            {
                //base.Plot(graphics, bounds, min, max);
    
                if (BarsInProgress == 0)
                {
                    SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
                    graphics.SmoothingMode = SmoothingMode.AntiAlias;
    
                    foreach (AggressiveTradeDraw d in aggressiveTradeDraw)
                    {
    #if DEBUG
                        //WinLog(3, "mzAggressiveTrade", d.AggressiveTrade.ToString());
    #endif
                        d.Draw(graphics);
                    }
                    graphics.SmoothingMode = oldSmoothingMode;
                }
            }
    Last edited by ren37; 01-11-2016, 08:44 AM.

    #2
    Hello,

    Thanks for your post.

    BarsArray[0] will refer to the chart bar series.

    I'm not sure why your width is not correct, you might try using print statements to see what values you are working with for x0 and x1.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanx. BarsArray[0] helps me.

      I'll post screen about ChartControl.BarWidth issue.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by thgamey, Yesterday, 08:38 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by stredtity, Today, 01:21 AM
      0 responses
      4 views
      0 likes
      Last Post stredtity  
      Started by superg3, Yesterday, 10:12 PM
      0 responses
      8 views
      0 likes
      Last Post superg3
      by superg3
       
      Started by johnnybegoode, Yesterday, 07:02 PM
      0 responses
      10 views
      0 likes
      Last Post johnnybegoode  
      Started by YevhenShynkarenko, Yesterday, 05:02 PM
      1 response
      15 views
      0 likes
      Last Post YevhenShynkarenko  
      Working...
      X