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 DJ888, 04-16-2024, 06:09 PM
      4 responses
      12 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by terofs, Today, 04:18 PM
      0 responses
      7 views
      0 likes
      Last Post terofs
      by terofs
       
      Started by nandhumca, Today, 03:41 PM
      0 responses
      6 views
      0 likes
      Last Post nandhumca  
      Started by The_Sec, Today, 03:37 PM
      0 responses
      3 views
      0 likes
      Last Post The_Sec
      by The_Sec
       
      Started by GwFutures1988, Today, 02:48 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Working...
      X