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

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 mattbsea, Today, 05:44 PM
      0 responses
      3 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      20 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Working...
      X