• 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 sandman, Today, 11:20 AM
        0 responses
        6 views
        0 likes
        Last Post sandman
        by sandman
         
        Started by Impeesa, Today, 09:19 AM
        0 responses
        12 views
        0 likes
        Last Post Impeesa
        by Impeesa
         
        Started by halozone, Today, 08:33 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by persoguillermo, Yesterday, 04:38 PM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by algunion, Today, 03:56 AM
        0 responses
        43 views
        0 likes
        Last Post algunion  
        Working...
        X