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

Having problem in drawing lines in session template

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

    Having problem in drawing lines in session template

    Hello Guys!

    I am new in Ninja trading, I have a problem in drawing pivots. A kind of problem is my pivots starts at "12:00 PM" and ends at "12:00 PM" which range type is daily, what I want is to start my pivots line at "6:00 AM" and ends at "5:17 PM" session template. Do you have any Idea which part of the code to be change? Please help. Here is the code:

    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    {
    if (Bars == null || ChartControl == null)
    return;

    int barWidth = ChartControl.ChartStyle.GetBarPaintWidth(ChartCont rol.BarWidth);
    for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
    {
    SolidBrush brush = brushes[seriesCount];
    DateTime lastDate = Cbi.Globals.MinDate;
    DateTime lastWeek = Cbi.Globals.MinDate;
    DateTime lastMonth = Cbi.Globals.MinDate;
    int firstX = -1;
    int lastX = -1;
    int lastY = -1;
    int xcounter = 0;
    SmoothingMode oldSmoothingMode = graphics.SmoothingMode;
    GraphicsPath path = new GraphicsPath();
    DataSeries series = (DataSeries)Values[seriesCount];
    Gui.Chart.Plot plot = Plots[seriesCount];


    if (brush.Color != plot.Pen.Color && Textcolorispencolor)
    brush = new SolidBrush(plot.Pen.Color);
    else
    brush = new SolidBrush(TextColor);


    for (int count = ChartControl.BarsPainted - 1; count >= ChartControl.BarsPainted - (Math.Min(ChartControl.BarsPainted, Width)+500); count--)
    {

    int idx = ChartControl.LastBarPainted - ChartControl.BarsPainted + 1 + count;
    if (idx - Displacement < 0 || idx - Displacement >= Bars.Count || (!ChartControl.ShowBarsRequired && idx - Displacement < BarsRequired))
    continue;
    else if (!series.IsValidPlot(idx))
    continue;

    if (pivotRangeType == PivotRange.Daily && lastDate == Cbi.Globals.MinDate && sessionTemplate == false)
    lastDate = Bars.Get(idx).Time.Date;
    else if (pivotRangeType == PivotRange.Weekly && lastWeek == Cbi.Globals.MinDate && sessionTemplate == false)
    lastWeek = RoundUpTimeToPeriodTime(Bars.Get(idx).Time.Date, PivotRange.Weekly);
    else if (pivotRangeType == PivotRange.Monthly && lastMonth == Cbi.Globals.MinDate && sessionTemplate == false)
    lastMonth = RoundUpTimeToPeriodTime(Bars.Get(idx).Time.Date, PivotRange.Monthly);
    else if (pivotRangeType == PivotRange.Daily && lastDate != Bars.Get(idx).Time.Date
    || pivotRangeType == PivotRange.Weekly && lastWeek != RoundUpTimeToPeriodTime(Bars.Get(idx).Time.Date, PivotRange.Weekly)
    || pivotRangeType == PivotRange.Monthly && lastMonth != RoundUpTimeToPeriodTime(Bars.Get(idx).Time.Date, PivotRange.Monthly) && sessionTemplate == false)
    continue;


    double val = series.Get(idx);
    int x = (int)(ChartControl.CanvasRight - ChartControl.BarMarginRight - barWidth / 2
    - (ChartControl.BarsPainted - 1) * ChartControl.BarSpace + count * ChartControl.BarSpace);
    int y = (int)((bounds.Y + bounds.Height) - ((val - min) / Gui.Chart.ChartControl.MaxMinusMin(max, min)) * bounds.Height);

    if (xcounter == 0)
    {
    firstX = x;
    }
    if (lastX >= 0)
    {
    if (y != lastY) // Problem here is, that last bar of old day has date of new day
    y = lastY;
    path.AddLine(lastX - plot.Pen.Width / 2, lastY, x - plot.Pen.Width / 2, y);

    }
    lastX = x + RtMargin;
    lastY = y;

    xcounter++;
    }

    graphics.SmoothingMode = SmoothingMode.AntiAlias;
    graphics.DrawPath(plot.Pen, path);
    graphics.SmoothingMode = oldSmoothingMode;


    }
    }
    #endregion

    #2
    For which instrument do you want to draw pivots? Are you talking stocks, futures or FOREX?

    Do you want to draw full session (entire trading day) or regular session pivots?

    Are you talking about floor pivots, fibonacci pivots, JacksonZones or Camarilla pivots?

    Comment


      #3
      thanks for your reply

      Im using CL 12-13,Light Sweet Crude - NYMEX, future type.

      I want to draw using this session... see attached image

      I am talking about MurreyMathLines.

      Please help.
      Attached Files
      Last edited by Danville.Sumobay; 11-12-2013, 02:22 AM.

      Comment


        #4
        Originally posted by Danville.Sumobay View Post
        Im using CL 12-13,Light Sweet Crude - NYMEX, future type.

        I want to draw using this session... see attached image

        I am talking about MurreyMathLines.

        Please help.

        The first thing to do is to open a chart that uses that session template. If you apply the NinjaTrader pivots indicator, it will use that template.

        If you want to use Murrey Math lines, then you would need to replace the floor pivot formulae in that indicator with the Murrey Math formulae.

        Comment


          #5
          Danville.Sumobay, welcome to our forums - Harry's approach is correct here, the default Pivots indicator would do the plotting exactly as you desire, therefore the suggestion would be to use it as the base and apply your modifications in its base structure provided. I'm aware of several Murrey Math implementations floating around but believe they would be designed to start plotting from the current day midnight only as you had seen.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks Beltrand and Harry...
            Now I know that most of Murrey Math is designed to start plotting from current day midnight. I will just try to modify its structure. Once again Thanks.

            Comment


              #7
              MurreyMathLines

              Harry
              Thanks. MurreyMathLines is now working by session template. I used your suggestion.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              601 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              16 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Started by agclub, 04-21-2024, 08:57 PM
              3 responses
              17 views
              0 likes
              Last Post TradingLoss  
              Working...
              X