Beispiel #1
0
        void ChartControl_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (!_fDragging)
            {
                return;
            }

            _iBarEnd = BarFromX((int)e.GetPosition(ChartPanel).X);

            if (!High.IsValidDataPoint(_iBarEnd) || !Low.IsValidDataPoint(_iBarEnd))
            {
                return;
            }

            if (_fDrawAB)
            {
                _priceEnd = swingDir > 0 ? High[_iBarEnd] : Low[_iBarEnd];
                lineAB    = UDrawLine("dDwABLine");
            }
            else
            {
                _priceEnd = swingDir < 0 ? High[_iBarEnd] : Low[_iBarEnd];
                lineBC    = UDrawLine("dDwBCLine");
            }

            ChartControl.InvalidateVisual();
        }
Beispiel #2
0
 private NinjaTrader.NinjaScript.DrawingTools.Line UDrawLine(string labelStr)
 {
     NinjaTrader.NinjaScript.DrawingTools.Line Lrtn = null;
     TriggerCustomEvent(
         delegate(object state) {
         try
         {
             Lrtn = Draw.Line(this,
                              labelStr, false,
                              _iBarStart, _priceStart,
                              _iBarEnd, _priceEnd,
                              swingColor, DashStyleHelper.Solid, 2);
         }
         catch { }
     },
         null
         );
     return(Lrtn);
 }
Beispiel #3
0
        // Draw objects after any reload of data (if possible)
        // currently wont restore if one of points is -1 (unfinished bar, when calc per bar close)
        private void RestoreDrawObjects()
        {
            //check all dates for bars to validate they exist.
            //if(APDate == DateTime.MinValue) return;	//works, but could still be older than oldest bar.
            //make sure All our saved dates are available on chart (null save = 01/01/0001).
            DateTime oldestDate = Time[CurrentBar];

            if (oldestDate > APDate || oldestDate > BPDate || oldestDate > CPDate)
            {
                return;
            }
            if (Time[0] < APDate || Time[0] < BPDate || Time[0] < CPDate)
            {
                return;
            }

            swingDir   = APVal >= BPVal ? -1 : 1;
            swingColor = swingDir > 0 ? SwingColorUp : SwingColorDn;

            //Draw AB line and text, using date info
            lineAB = Draw.Line(this, "dDwABLine", false, APDate, APVal, BPDate, BPVal, swingColor, DashStyleHelper.Solid, 2);
            lineBC = Draw.Line(this, "dDwBCLine", false, BPDate, BPVal, CPDate, CPVal, swingColor, DashStyleHelper.Solid, 2);

            //ChartControl.InvalidateVisual();
            ForceRefresh();

            //Place 'A' text
            Draw.Text(this, "dDwALabel", IsAutoScale, "A",
                      APDate, APVal, textOffset2 * swingDir * -1, swingColor, textFontLabel,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            Draw.Text(this, "dDwAPct", IsAutoScale, APVal.ToString(),
                      APDate, APVal, textOffset * swingDir * -1, swingColor, textFont,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);

            //Place 'B' text
            double moveVal = RoundInst(Math.Abs(APVal - BPVal));

            Draw.Text(this, "dDwBLabel", IsAutoScale, "B",
                      BPDate, BPVal, textOffset2 * swingDir, swingColor, textFontLabel,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            Draw.Text(this, "dDwBPrice", IsAutoScale, moveVal.ToString() + "c - " + BPVal.ToString(),
                      BPDate, BPVal, textOffset * swingDir, swingColor, textFont,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);

            //Draw 'C' text
            moveVal = RoundInst(Math.Abs(BPVal - CPVal));
            double movePct = (moveVal / Math.Abs(APVal - BPVal)) * 100;

            Draw.Text(this, "dDwCLabel", IsAutoScale, "C",
                      CPDate, CPVal, textOffset3 * swingDir * -1, swingColor, textFontLabel,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            //move point value and %
            Draw.Text(this, "dDwCPct", IsAutoScale, movePct.ToString("f1") + "%",
                      CPDate, CPVal, textOffset2 * swingDir * -1, swingColor, textFont,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
            Draw.Text(this, "dDwCPrice", IsAutoScale, moveVal.ToString() + "c - " + CPVal.ToString(),
                      CPDate, CPVal, textOffset * swingDir * -1, swingColor, textFont,
                      TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);

            //setup and call fib draws
            _ABbarStart   = CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, APDate);
            _ABbarEnd     = CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, BPDate);
            _ABpriceStart = APVal;
            _ABpriceEnd   = BPVal;
            _BCbarStart   = _ABbarEnd;
            _BCbarEnd     = CurrentBar - ChartBars.GetBarIdxByTime(ChartControl, CPDate);
            _BCpriceStart = BPVal;
            _BCpriceEnd   = CPVal;

            DoDrawFibs(1, FibABRets, FibABExtends, FibABColor);
            DoDrawFibs(2, FibBCRets, FibBCExtends, FibBCColor);
            DoDrawFibs(3, FibMMRets, FibMMExtends, swingColor);
        }