public DynamicTrailingStop(ChartSlopeTrader strategy, RayContainer rayContainer, bool isPreAnalyze, bool isPost) { //Setting the variables _strategy = strategy; _rayContainer = rayContainer; _isFirstSlope = true; PositonType = rayContainer.PositionType; _isWaitSlope = true; _lastMinimumOrMaximum = 0; _lastSlope = new Slope(0, 0); NewBar(); UpdateFirstBar(); if (isPreAnalyze) { //Getting the first slope Slope tempSlope = GetFirstStlope(0, Math.Min(PreAnalyzeValue, strategy.Low.Count - 1), isPost); if (_strategy.SwingIndicatorBars <= 1) { MessageBox.Show("You can not start pre-analyze with one or less bars"); return; } if (PositonType == MarketPosition.Long && Math.Abs(tempSlope.Price - strategy.High[1]) < strategy.RealTickSize) { MessageBox.Show("Your swing price want to be set as same as previous bar"); return; } if (PositonType == MarketPosition.Short && Math.Abs(tempSlope.Price - strategy.Low[1]) < strategy.RealTickSize) { MessageBox.Show("Your swing price want to be set as same as previous bar"); return; } _currentSlope = tempSlope; UpdateSlopeLine(_currentSlope); _isFirstSlope = false; _isWaitSlope = true; _strategy.SendMail_dtsNewSlopeLineNew(_currentSlope.Price); } else { _isWaitSlope = true; } }
public void UpdateFirstBar() { //If we do not wait for new Slow if (_isWaitSlope) //We wait for a slope { Slope tempSlope = GetLastSlope(0, Math.Max(_lastMinimumOrMaximum, _lastSlope.Bar)); if (Math.Abs(tempSlope.Price) < 0.01) { return; } if ((PositonType == MarketPosition.Long && tempSlope.Price > _lastSlope.Price) || (PositonType == MarketPosition.Short && tempSlope.Price < _lastSlope.Price) || _isFirstSlope) { _isFirstSlope = false; _currentSlope = tempSlope; UpdateSlopeLine(_currentSlope); _isWaitSlope = false; _strategy.SendMail_dtsNewSlopeLineNew(_currentSlope.Price); } } }