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 Rapine Heihei, 04-23-2024, 07:51 PM
      2 responses
      30 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by Shansen, 08-30-2019, 10:18 PM
      24 responses
      943 views
      0 likes
      Last Post spwizard  
      Started by Max238, Today, 01:28 AM
      0 responses
      9 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by rocketman7, Today, 01:00 AM
      0 responses
      5 views
      0 likes
      Last Post rocketman7  
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      28 views
      0 likes
      Last Post wzgy0920  
      Working...
      X