/// <summary> /// OnExecution of orders /// </summary> /// <param name="execution"></param> protected override void OnOrderExecution(IExecution execution) { ////info: was uncommented because exired date is not working in simulation mode or in backtesting mode AND also not in AT 1.9 ////set expiration date to close at the end of the trading day //if (this.CloseOrderBeforeEndOfTradingDay) //{ // foreach (AgenaTrader.Helper.TradingManager.Trade item in this.Root.Core.TradingManager.ActiveOpenedTrades) // { // if ((this._orderenterlong != null && item.EntryOrder.Name == this._orderenterlong.Name) // || (this._orderentershort != null && item.EntryOrder.Name == this._orderentershort.Name)) // { // item.Expiration = this._orb_indicator.getDateTimeForClosingBeforeTradingDayEnds(this.Bars, this.Bars[0].Timestamp, this.TimeFrame, this.CloseXCandlesBeforeEndOfTradingDay); // //Print("Expiration: " + item.Expiration.ToString()); // } // } //} ////Create statistic for execution ////todo use it or delete it - there is no try! //if (this.StatisticBacktesting) //{ // this._StatisticContainer.Add(this.Root.Core.TradingManager, this, execution); //} //send email if (this.Send_email) { this.SendEmail(Core.Settings.MailDefaultFromAddress, Core.PreferenceManager.DefaultEmailAddress, GlobalUtilities.GetEmailSubject(execution), GlobalUtilities.GetEmailText(execution, this.GetType().Name)); } }
public void drawTarget(IBars bars, int curbar) { if (this.DrawLinesOnChart && curbar == PopGunTriggerBar) { AddChartText(("PopGunSize" + curbar), (Math.Round((((bars[0].High - bars[0].Low) / bars[0].Close) * 100), 2)).ToString(), 0, bars.GetByIndex(PopGunTriggerBar).Low - TickSize * bars[0].Close, Color.Black); } if (curbar <= PopGunTarget && curbar > PopGunTriggerBar && curbar > 0) { DateTime lineend = GlobalUtilities.GetTargetBar(bars, bars.GetByIndex(PopGunTriggerBar).Time, TimeFrame, PopGunExpires); if (this.DrawLinesOnChart) { string strPopGunLong = "PopGunLong" + curbar; string strPopGunShort = "PopGunShort" + curbar; AddChartLine(strPopGunLong, true, bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerLong, lineend, PopGunTriggerLong, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); AddChartLine(strPopGunShort, true, bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerShort, lineend, PopGunTriggerShort, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); } if (this.IsSnapshotActive && curbar == PopGunTarget) { GlobalUtilities.SaveSnapShot("PopGun", bars.Instrument.Name, this.Root.Core.ChartManager.AllCharts, bars, TimeFrame); } } }
protected override void OnCalculate() { //Check if peridocity is valid for this script if (this.IsProcessingBarIndexLast && !DatafeedPeriodicityIsValid(Bars.TimeFrame)) { GlobalUtilities.DrawWarningTextOnChart(this, Const.DefaultStringDatafeedPeriodicity); } switch (SeasonalDateType) { case SeasonalDateType.SellInMay: this.calculate_Sell_in_May(); break; case SeasonalDateType.SantaClausRally: this.calculate_Santa_Claus_Rally(); break; case SeasonalDateType.fourthofjuly: this.calculate_4th_of_July_Rally(); break; case SeasonalDateType.manual: this.calculate_manual(); break; default: break; } }
protected override void OnOrderExecution(IExecution execution) { DateTime ts_Ausstieg; // ts_Ausstieg = Reversal2NextBar_Indicator().GetTargetBar(Bars[-1].Timestamp); ts_Ausstieg = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1); Print("Ausstieg: " + ts_Ausstieg + "Bars[-1].Time: " + Bars[-1].Time); ////todo this is not working in 1.9 //foreach (Trade item in this.Root.Core.TradingManager.ActiveOpenedTrades) //{ // if (item.EntryOrder.Name == SignalNameEnter // || item.EntryOrder.Name == SignalNameStop) // { // item.Expiration = ts_Ausstieg; // } //} if (execution.PositionType == PositionType.Flat) { oStop = null; //den Stop zuerst oEnter = null; } }
/// <summary> /// Create Short Order and Stop. /// </summary> private void DoEnterShort() { _orderentershort = SubmitOrder(new StrategyOrderParameters { Direction = OrderDirection.Sell, Type = OrderType.Market, Quantity = GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), SignalName = this.GetType().Name + " " + PositionType.Short + "_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(), Instrument = this.Instrument, TimeFrame = this.TimeFrame }); SetUpStopLoss(_orderentershort.Name, CalculationMode.Price, Bars[0].Close * 1.05, false); SetUpProfitTarget(_orderentershort.Name, CalculationMode.Price, Bars[0].Close / 1.11); }
/// <summary> /// Create Long Order and Stop. /// </summary> private void DoEnterLong() { _orderenterlong = EnterLong(GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), this.GetType().Name + " " + PositionType.Long + "_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(), this.Instrument, this.TimeFrame); //SetStopLoss(_orderenterlong.Name, CalculationMode.Price, this._orb_indicator.RangeLow, false); //SetStopLoss(_orderenterlong.Name, CalculationMode.Price, Bars[0].Close * 0.95, false); //SetStopLoss(_orderenterlong.Name, CalculationMode.Price, this._orb_indicator.RangeLow, false); //SetProfitTarget(_orderenterlong.Name, CalculationMode.Price, this._orb_indicator.TargetLong); }
//todo -100 wird noch nicht zurückgegeben oder? public int calculate(IBars bars, int curbar) { int returnvalue = 0; //We need at least three bars if (curbar < 2) { return(0); } double TwoBarsAgo_High = bars[2].High; double TwoBarsAgo_Low = bars[2].Low; double OneBarAgo_High = bars[1].High; double OneBarAgo_Low = bars[1].Low; double CurrentBar_High = bars[0].High; double CurrentBar_Low = bars[0].Low; // 2) Determine, if 1 Bar ago, there was an inside bar if (TwoBarsAgo_High > OneBarAgo_High && TwoBarsAgo_Low < OneBarAgo_Low) { //One Bar ago was an inside bar, so lets check if current bar is outside bar if (TwoBarsAgo_High < CurrentBar_High && TwoBarsAgo_Low > CurrentBar_Low) { // current bar is outside bar -> lets pop the gun this.PopGunTarget = curbar + this.PopGunExpires; PopGunTriggerBar = CurrentBar; this.PopGunTriggerLong = CurrentBar_High; this.PopGunTriggerShort = CurrentBar_Low; this.PopGunTargetDateTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, PopGunExpires); } } if (curbar < this.PopGunTarget) { if (bars[0].Close > this.PopGunTriggerLong) { returnvalue = 100; } else if (bars[0].Close < this.PopGunTriggerShort) { returnvalue = -100; } } drawTarget(); evaluation(); return(returnvalue); }
/// <summary> /// OnExecution of orders /// </summary> /// <param name="execution"></param> protected override void OnOrderExecution(IExecution execution) { //Create statistic for execution if (this.StatisticBacktesting) { //this._StatisticContainer.Add(this.Root.Core.TradingManager, this, execution); } //send email if (this.Send_email) { this.SendEmail(Core.Settings.MailDefaultFromAddress, Core.PreferenceManager.DefaultEmailAddress, GlobalUtilities.GetEmailSubject(execution), GlobalUtilities.GetEmailText(execution, this.GetType().Name)); } }
/// <summary> /// Saves a snapshot of the current chart. /// </summary> /// <param name="Indicator"></param> /// <param name="InstrumentName"></param> /// <param name="Chart"></param> /// <param name="Bars"></param> /// <param name="TimeFrame"></param> public static void SaveSnapShot(string Indicator, String InstrumentName, IEnumerable <IChart> AllCharts, IBars Bars, ITimeFrame TimeFrame) { string filepart = GlobalUtilities.CleanFileName(Indicator + "_" + TimeFrame.PeriodicityValue + TimeFrame.Periodicity + "_" + InstrumentName + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm")); string directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Auswertung\\SnapShot\\" + filepart + "\\"; System.IO.Directory.CreateDirectory(directory); string fileName = InstrumentName + "_" + TimeFrame.PeriodicityValue + TimeFrame.Periodicity + "_" + Bars[0].Time.ToString("yyyy_MM_dd_HH_mm") + ".jpg"; fileName = GlobalUtilities.CleanFileName(fileName); //take 20 Bars to future and 20 Bars from the past (but only if they exist, if not, just take first or last) DateTime ChartStart = DateTime.MinValue; DateTime ChartEnd = DateTime.MinValue; if (Bars.GetByIndex(Bars.GetIndex(Bars[0]) + 20) != null) { ChartEnd = Bars.GetByIndex(Bars.GetIndex(Bars[0]) + 20).Time; } else { ChartEnd = Bars.Last().Time; } if (Bars.GetByIndex(Bars.GetIndex(Bars[0]) - 20) != null) { ChartStart = Bars.GetByIndex(Bars.GetIndex(Bars[0]) - 20).Time; } else { ChartStart = Bars.First().Time; } //pick the right chart matching the current timeframe foreach (IChart chart in AllCharts) { if (chart.HistoryRequest.TimeFrame.Periodicity == TimeFrame.Periodicity && chart.HistoryRequest.TimeFrame.PeriodicityValue == TimeFrame.PeriodicityValue) { chart.SetDateRange(ChartStart, ChartEnd); chart.SaveChart(directory + fileName); } } }
private void DoEnterShort() { _orderentershort = SubmitOrder(new StrategyOrderParameters { Direction = OrderDirection.Sell, Type = OrderType.Market, Quantity = GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), SignalName = "PopGun_Short_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(), Instrument = this.Instrument, TimeFrame = this.TimeFrame }); if (UseStopLoss) { SetUpStopLoss(_orderentershort.Name, CalculationMode.Price, this._popgun_indicator.PopGunTriggerLong, false); } if (UseTrailingStop) { SetUpTrailStop(_orderenterlong.Name, CalculationMode.Ticks, 10, false); } //SetUpProfitTarget(_orderentershort.Name, CalculationMode.Price, <<<<TARGET>>>>); }
public override void OnPaint(Graphics g, Rectangle r, double min, double max) { if (Bars == null || Chart == null) { return; } //Only draw button if parameters are available. if (this.Instrument != null && _list != null && _list.Count > 0) { using (Font font1 = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point)) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; if (String.IsNullOrEmpty(Shortcut_list)) { if (this.Name_of_list.Count() >= 5) { this.Shortcut_list = this.Name_of_list.Substring(0, 5); } else { this.Shortcut_list = this.Name_of_list; } } this.Core.GetDataDirectory(); Brush tempbrush = new SolidBrush(GlobalUtilities.AdjustOpacity(((SolidBrush)_brush).Color, 0.5F)); _rect = new RectangleF(r.Width - 100, 10, 86, 27); g.FillRectangle(tempbrush, _rect); g.DrawString(Shortcut_list, font1, Brushes.White, _rect, stringFormat); _rect2 = new RectangleF(r.Width - 100, 40, 86, 27); //g.DrawRectangle(_pen, Rectangle.Round(_rect)); } } }
protected override void OnCalculate() { this.MyPlot1.Set(SMA(50)[0]); this.MyPlot2.Set(SMA(150)[0]); this.MyPlot3.Set(SMA(200)[0]); //Lets call the calculate method and save the result with the trade action ResultValue returnvalue = this.calculate(Close); //If the calculate method was not finished we need to stop and show an alert message to the user. if (returnvalue.ErrorOccured) { //Display error just one time if (!this.ErrorOccured) { GlobalUtilities.DrawAlertTextOnChart(this, Const.DefaultStringErrorDuringCalculation); this.ErrorOccured = true; } return; } //Entry if (returnvalue.Entry.HasValue) { switch (returnvalue.Entry) { case OrderDirection.Buy: //AddChartDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen); //this.MyPlot1.Set(1); AddChartArrowUp("ArrowLong_Entry" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, Color.LightGreen); break; } } else { //Value was null so nothing to do. //this.MyPlot1.Set(0); } }
public override void OnPaint(Graphics g, Rectangle r, double min, double max) { if (Bars == null || Chart == null) { return; } //Only draw button if parameters are available. if (this.Instrument != null) { string strtext = "open browser"; //Only stocks are possible to lookup if (this.Instrument.InstrumentType == InstrumentType.Stock) { _brush = Brushes.Green; } else { _brush = Brushes.Gray; strtext = "not supported"; } using (Font font1 = new Font("Arial", 8, FontStyle.Bold, GraphicsUnit.Point)) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; this.Core.GetDataDirectory(); Brush tempbrush = new SolidBrush(GlobalUtilities.AdjustOpacity(((SolidBrush)_brush).Color, 0.5F)); _rect = new RectangleF(r.Width - 100, 10, 86, 27); g.FillRectangle(tempbrush, _rect); g.DrawString(strtext, font1, Brushes.White, _rect, stringFormat); _rect2 = new RectangleF(r.Width - 100, 40, 86, 27); } } }
public void drawTarget() { if (CurrentBar <= PopGunTarget && CurrentBar > PopGunTriggerBar && CurrentBar > 0) { string strPopGunLong = "PopGunLong" + CurrentBar; string strPopGunShort = "PopGunShort" + CurrentBar; DateTime lineend = GlobalUtilities.GetTargetBar(Bars, Bars.GetByIndex(PopGunTriggerBar).Time, TimeFrame, PopGunExpires); DrawLine(strPopGunLong, true, Bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerLong, lineend, PopGunTriggerLong, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); DrawLine(strPopGunShort, true, Bars.GetByIndex(PopGunTriggerBar).Time, PopGunTriggerShort, lineend, PopGunTriggerShort, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); if (this.IsSnapshotActive && CurrentBar == PopGunTarget) { GlobalUtilities.SaveSnapShot("PopGun", Instrument.Name, this.Root.Core.ChartManager.AllCharts, Bars, TimeFrame); } } }
protected override void OnCalculate() { //MyPlot1.Set(InSeries[0]); if (Bars != null && Bars.Count > 0 && IsProcessingBarIndexLast) { //Check if peridocity is valid for this script if (!DatafeedPeriodicityIsValid(Bars.TimeFrame)) { GlobalUtilities.DrawWarningTextOnChart(this, Const.DefaultStringDatafeedPeriodicity); return; } DateTime start = Bars.Where(x => x.Time.Date == Bars[0].Time.Date).FirstOrDefault().Time; DateTime start_date = start.Date; DateTime end = Bars[0].Time; //Selektiere alle g�ltigen Kurse und finde low und high. IEnumerable <IBar> list = Bars.Where(x => x.Time >= start).Where(x => x.Time <= end); if (list != null && !list.IsEmpty()) { double minvalue = list.Where(x => x.Low == list.Min(y => y.Low)).LastOrDefault().Low; double maxvalue = list.Where(x => x.High == list.Max(y => y.High)).LastOrDefault().High; double range = maxvalue - minvalue; DateTime enddrawing_string = end.AddSeconds(this.TimeFrame.GetSeconds() + this.TimeFrame.GetSeconds() * 0.15); DateTime enddrawing_line = end.AddSeconds(this.TimeFrame.GetSeconds()); string[] arr_WhichLinesShouldWeUse = this.WhichLinesShouldWeUse.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); //Dictionary<string, string> dict = arr_WhichLinesShouldWeUse.ToDictionary<string, string>(x => x.ToString(), x => x.ToString()); if (Array.IndexOf(arr_WhichLinesShouldWeUse, "100") != -1) { AddChartText("Fibonacci_Session_LowLine_String", true, minvalue.ToString("N2") + " (100%)", enddrawing_string, minvalue, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_LowLine", true, start, minvalue, enddrawing_line, minvalue, this.Color_Fibo_Level_100, DashStyle.Solid, this.Fibo_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "0") != -1) { AddChartText("Fibonacci_Session_HighLine_String", true, maxvalue.ToString("N2") + " (0%)", enddrawing_string, maxvalue, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_HighLine", true, start, maxvalue, enddrawing_line, maxvalue, this.Color_Fibo_Level_0, DashStyle.Solid, this.Fibo_0_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "23") != -1) { double _fibo_lv_2361 = maxvalue - ((range / 100) * 23.61); AddChartText("Fibonacci_Session_23.61_String", true, _fibo_lv_2361.ToString("N2") + " (23.61%)", enddrawing_string, _fibo_lv_2361, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_23.61_Line", true, start, _fibo_lv_2361, enddrawing_line, _fibo_lv_2361, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "38") != -1) { double _fibo_lv_382 = maxvalue - ((range / 100) * 38.2); AddChartText("Fibonacci_Session_38.2_String", true, _fibo_lv_382.ToString("N2") + " (38.2%)", enddrawing_string, _fibo_lv_382, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_38.2", true, start, _fibo_lv_382, enddrawing_line, _fibo_lv_382, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "50") != -1) { double _fibo_lv_500 = maxvalue - ((range / 100) * 50.0); AddChartText("Fibonacci_Session_50.0_String", true, _fibo_lv_500.ToString("N2") + " (50.0%)", enddrawing_string, _fibo_lv_500, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_50.0", true, start, _fibo_lv_500, enddrawing_line, _fibo_lv_500, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "61") != -1) { double _fibo_lv_618 = maxvalue - ((range / 100) * 61.8); AddChartText("Fibonacci_Session_61.8_String", true, _fibo_lv_618.ToString("N2") + " (61.8%)", enddrawing_string, _fibo_lv_618, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_61.8", true, start, _fibo_lv_618, enddrawing_line, _fibo_lv_618, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "76") != -1) { double _fibo_lv_7640 = maxvalue - ((range / 100) * 76.4); AddChartText("Fibonacci_Session_76.40_String", true, _fibo_lv_7640.ToString("N2") + " (76.4%)", enddrawing_string, _fibo_lv_7640, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_76.40", true, start, _fibo_lv_7640, enddrawing_line, _fibo_lv_7640, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } if (Array.IndexOf(arr_WhichLinesShouldWeUse, "78") != -1) { double _fibo_lv_7862 = maxvalue - ((range / 100) * 78.62); AddChartText("Fibonacci_Session_78.62_String", true, _fibo_lv_7862.ToString("N2") + " (78.62%)", enddrawing_string, _fibo_lv_7862, 0, this.Color_Text, new Font("Arial", 7.5f), StringAlignment.Far, Color.Transparent, Color.Transparent, 100); AddChartLine("Fibonacci_Session_78.62", true, start, _fibo_lv_7862, enddrawing_line, _fibo_lv_7862, this.Color_Fibo_Level_0_100, DashStyle.Solid, this.Fibo_0_100_LineWidth); } } } }
protected override void OnCalculate() { Bollinger bb = Bollinger(this.StandardDeviation, this.Period); if (Close[0] > bb.Upper[0]) { if (ShowSignalOnChartBackground) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorLongSignalBackground, this.OpacityLongSignal / 100.0); } _signals.Set(1); } else if (Close[0] < bb.Lower[0]) { if (ShowSignalOnChartBackground) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorShortSignalBackground, this.OpacityShortSignal / 100.0); } _signals.Set(-1); } else { _signals.Set(_signals[1]); if (_signals[1] == 1) { if (ShowSignalOnChartBackground) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorLongSignalBackground, this.OpacityLongSignal / 100.0); } } else { if (ShowSignalOnChartBackground) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorShortSignalBackground, this.OpacityShortSignal / 100.0); } } } if (this.ShowSignalOnChartArrow) { if (_signals[0] == 1 && _signals[1] != 1) { AddChartArrowUp("ArrowLong_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, this.ColorLongSignalArrow); } else if (_signals[0] == -1 && _signals[1] != -1) { AddChartArrowDown("ArrowShort_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].High, this.ColorShortSignalArrow); } } //set bb this.Plot_Middle.Set(bb.Middle[0]); this.Plot_High.Set(bb.Upper[0]); this.Plot_Low.Set(bb.Lower[0]); //Set the color PlotColors[0][0] = this.Color_1; OutputDescriptors[0].PenStyle = this.DashStyle_1; OutputDescriptors[0].Pen.Width = this.LineWidth_1; PlotColors[1][0] = this.Color_2; OutputDescriptors[1].PenStyle = this.DashStyle_2; OutputDescriptors[1].Pen.Width = this.LineWidth_2; PlotColors[2][0] = this.Color_3; OutputDescriptors[2].PenStyle = this.DashStyle_3; OutputDescriptors[2].Pen.Width = this.LineWidth_3; }
//todo -100 wird noch nicht zur�ckgegeben oder? public int calculate(IBars bars, int curbar, PopGunType popguntype) { bool noPopGunTrigger = false; int returnvalue = 0; //We need at least three bars if (curbar < 2) { return(0); } double TwoBarsAgo_High = bars[2].High; double TwoBarsAgo_Low = bars[2].Low; double OneBarAgo_High = bars[1].High; double OneBarAgo_Low = bars[1].Low; double CurrentHigh = bars[0].High; double CurrentLow = bars[0].Low; if (this.PopGunType == UserCode.PopGunType.Classic) { // 2) Determine, if 1 Bar ago, there was an inside bar if (TwoBarsAgo_High > OneBarAgo_High && TwoBarsAgo_Low < OneBarAgo_Low) { //One Bar ago was an inside bar, so lets check if current bar is outside bar if (TwoBarsAgo_High < CurrentHigh && TwoBarsAgo_Low > CurrentLow) { // current bar is outside bar -> lets pop the gun this.PopGunTargetDateTime = GlobalUtilities.GetTargetBar(bars, bars[0].Time, TimeFrame, PopGunExpires); //check, if target bar would be on the following day, and therefor a risks of gap is given if (Filter_NoTriggerEOD && PopGunTargetDateTime.Date > bars[0].Time.Date) { //reject current PopGun Trigger and reset TargetDateTime PopGunTargetDateTime = DateTime.MinValue; noPopGunTrigger = true; } if (noPopGunTrigger == false) { this.PopGunTarget = curbar + this.PopGunExpires; PopGunTriggerBar = ProcessingBarIndex; this.PopGunTriggerLong = CurrentHigh; this.PopGunTriggerShort = CurrentLow; } } } if (curbar < this.PopGunTarget) { if (bars[0].Close > this.PopGunTriggerLong) { returnvalue = 100; } else if (bars[0].Close < this.PopGunTriggerShort) { returnvalue = -100; } } drawTarget(bars, curbar); evaluation(bars, curbar); } else if (this.PopGunType == UserCode.PopGunType.ThreeBarReversal) { if (bars[2].IsFalling && bars[1].IsFalling && TwoBarsAgo_Low > OneBarAgo_Low && bars[0].Close > TwoBarsAgo_High && bars[0].Close > OneBarAgo_High) { returnvalue = 100; if (this.DrawLinesOnChart) { AddChartLine("high_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[0].Close, bars[0].Time.AddDays(5), bars[0].Close, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); AddChartLine("low_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[1].Close, bars[0].Time.AddDays(5), bars[1].Close, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); } } else if (bars[2].IsGrowing && bars[1].IsGrowing && TwoBarsAgo_High < OneBarAgo_High && bars[0].Close < TwoBarsAgo_Low && bars[0].Close < OneBarAgo_Low) { returnvalue = -100; if (this.DrawLinesOnChart) { AddChartLine("high_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[0].Close, bars[0].Time.AddDays(5), bars[0].Close, Color.Red, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); AddChartLine("low_" + bars[0].Time.Ticks.ToString(), true, bars[0].Time, bars[1].Close, bars[0].Time.AddDays(5), bars[1].Close, Color.Green, Const.DefaultIndicatorDashStyle, Const.DefaultLineWidth_large); } } } else { throw new NotImplementedException(); } return(returnvalue); }
private void evaluation(IBars bars, int curbar) { if (IsEvaluationActive == false) { return; } if (curbar != PopGunTarget || curbar == 0) { return; } bool LongTrade = false; double PunkteLongTrade; bool ShortTrade = false; double PunkteShortTrade; int i; Statistic statistic = new Statistic("PopGun"); #region LongAuswertung i = PopGunExpires - 1; //weil 0-Index do { if (bars[i].Close > PopGunTriggerLong) { LongTrade = true; statistic.EntryDateTime = bars[i].Time; statistic.TradeDirection = PositionType.Long; statistic.EntryPrice = PopGunTriggerLong; statistic.StopPrice = PopGunTriggerShort; break; } i--; } while (i >= 1); #endregion #region ShortAuswertung i = PopGunExpires - 1; do { if (bars[i].Close < PopGunTriggerShort && ShortTrade == false) { ShortTrade = true; statistic.EntryDateTime = bars[i].Time; statistic.EntryPrice = PopGunTriggerShort; statistic.StopPrice = PopGunTriggerLong; statistic.TradeDirection = PositionType.Short; break; } i--; } while (i >= 1); #endregion if (LongTrade == true && ShortTrade == true) { // DoubleBreakOut = true; } else if (LongTrade == true) { PunkteLongTrade = bars[0].Close - PopGunTriggerLong; if (PunkteLongTrade > 0) { PopGunTradeWinCounterLong += 1; } else { PopGunTradeFailCounterLong += 1; } PopGunTradeCounterLong += 1; PopGunTradeResultTotalLong = PopGunTradeResultTotalLong + (decimal)PunkteLongTrade; } else if (ShortTrade == true) { PunkteShortTrade = bars[0].Close - PopGunTriggerShort; if (PunkteShortTrade < 0) { PopGunTradeWinCounterShort += 1; } else { PopGunTradeFailCounterShort += 1; } PopGunTradeCounterShort += 1; PopGunTradeResultTotalShort = PopGunTradeResultTotalShort + (decimal)PunkteShortTrade; } if (statistic.EntryDateTime > DateTime.MinValue) { statistic.TimeFrame = TimeFrame.PeriodicityValue.ToString() + TimeFrame.Periodicity.ToString(); statistic.ExitDateTime = GlobalUtilities.GetTargetBar(bars, bars[0].Time, TimeFrame, 1); statistic.Instrument = bars.Instrument.Symbol.ToString(); statistic.ExitPrice = bars[0].Close; statistic.ExitReason = "Expired (" + _PopGunExpires + " Bars)"; // Print(statistic.getCSVData()); statistic.AppendToFile(); } }
protected override void OnCalculate() { if (this.MA_1 != 0 && this.MA_1 > this.RequiredBarsCount || this.MA_2 != 0 && this.MA_2 > this.RequiredBarsCount || this.MA_3 != 0 && this.MA_3 > this.RequiredBarsCount || this.MA_4 != 0 && this.MA_4 > this.RequiredBarsCount || this.MA_5 != 0 && this.MA_5 > this.RequiredBarsCount || this.MA_6 != 0 && this.MA_6 > this.RequiredBarsCount) { AddChartTextFixed("AlertText", "Required bars must be at least as high as the largest moving average period.", TextPosition.Center, Color.Red, new Font("Arial", 30), Color.Red, Color.Red, 20); } int _signal_value = 0; int _enabled_ifs = 0; if (this.MA_1 != 0) { Plot_1.Set(this.GetValue(this.MA_1_Selected, this.MA_1)); } if (this.MA_2 != 0) { Plot_2.Set(this.GetValue(this.MA_2_Selected, this.MA_2)); } if (this.MA_3 != 0) { Plot_3.Set(this.GetValue(this.MA_3_Selected, this.MA_3)); } if (this.MA_4 != 0) { Plot_4.Set(this.GetValue(this.MA_4_Selected, this.MA_4)); } if (this.MA_5 != 0) { Plot_5.Set(this.GetValue(this.MA_5_Selected, this.MA_5)); } if (this.MA_6 != 0) { Plot_6.Set(this.GetValue(this.MA_6_Selected, this.MA_6)); } //Signals if (this.If_1_over_2) { _enabled_ifs++; if (this.MA_1 != 0 && this.MA_2 != 0 && Plot_1.Last() > Plot_2.Last()) { _signal_value++; } else if (this.MA_1 != 0 && this.MA_2 != 0 && Plot_1.Last() < Plot_2.Last()) { _signal_value--; } } if (this.If_2_over_3) { _enabled_ifs++; if (this.MA_2 != 0 && this.MA_3 != 0 && Plot_2.Last() > Plot_3.Last()) { _signal_value++; } else if (this.MA_2 != 0 && this.MA_3 != 0 && Plot_2.Last() < Plot_3.Last()) { _signal_value--; } } if (this.If_3_over_4) { _enabled_ifs++; if (this.MA_3 != 0 && this.MA_4 != 0 && Plot_3.Last() > Plot_4.Last()) { _signal_value++; } else if (this.MA_3 != 0 && this.MA_4 != 0 && Plot_3.Last() < Plot_4.Last()) { _signal_value--; } } if (this.If_4_over_5) { _enabled_ifs++; if (this.MA_4 != 0 && this.MA_5 != 0 && Plot_4.Last() > Plot_5.Last()) { _signal_value++; } else if (this.MA_4 != 0 && this.MA_5 != 0 && Plot_4.Last() < Plot_5.Last()) { _signal_value--; } } if (this.If_5_over_6) { _enabled_ifs++; if (this.MA_5 != 0 && this.MA_6 != 0 && Plot_5.Last() > Plot_6.Last()) { _signal_value++; } else if (this.MA_5 != 0 && this.MA_6 != 0 && Plot_5.Last() < Plot_6.Last()) { _signal_value--; } } //signal if (_signal_value == _enabled_ifs) { _signals.Set(1); } else if (_signal_value == _enabled_ifs * -1) { _signals.Set(-1); } else { _signals.Set(0); } //days if (_signals[0] == 0) { _days.Set(0); } else { if (_signals[0] == 1 && _signals[1] == 1) { _days.Set(_days[1] + 1); } else if (_signals[0] == -1 && _signals[1] == -1) { _days.Set(_days[1] - 1); } else { if (_signals[0] == 1 && _signals[1] == 0 || _signals[0] == 1 && _signals[1] == -1) { _days.Set(1); } else { _days.Set(-1); } } } if (ShowSignalOnChartBackground) { //color an background if (_signals[0] == 1) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorLongSignalBackground, this.OpacityLongSignal / 100.0); } else if (_signals[0] == -1) { this.BackColor = GlobalUtilities.AdjustOpacity(this.ColorShortSignalBackground, this.OpacityShortSignal / 100.0); } } //if (this.ShowSignalOnChartPercent) //{ // //percent on all signals with more _enabled_ifs // if (_signals[0] == 0 && _signals[1] != 0) // { // this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); // } // else if (_signals[0] == 1 && _signals[1] == -1) // { // this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); // } // else if (_signals[0] == -1 && _signals[1] == 1) // { // this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); // } // //percent on last candle // if (_signals[0] != 0 && IsProcessingBarIndexLast) // { // this.drawpercentlines(0, this.DashStyleLineLast, this.PlotWidthLineLast); // } //} //percent //percent on all signals with more _enabled_ifs if (_signals[0] == 0 && _signals[1] != 0) { _percent.Set(this.getpercent(1)); if (this.ShowSignalOnChartPercent) { this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); } } else if (_signals[0] == 1 && _signals[1] == -1) { _percent.Set(this.getpercent(1)); if (this.ShowSignalOnChartPercent) { this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); } } else if (_signals[0] == -1 && _signals[1] == 1) { _percent.Set(this.getpercent(1)); if (this.ShowSignalOnChartPercent) { this.drawpercentlines(1, this.DashStyleLine, this.PlotWidthLine); } } //percent on last candle if (_signals[0] != 0 && IsProcessingBarIndexLast) { _percent.Set(this.getpercent(0)); if (this.ShowSignalOnChartPercent) { this.drawpercentlines(0, this.DashStyleLineLast, this.PlotWidthLineLast); } } if (this.ShowSignalOnChartArrow) { if (_signals[0] == 1 && _signals[1] != 1) { AddChartArrowUp("ArrowLong_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].Low, this.ColorLongSignalArrow); } else if (_signals[0] == -1 && _signals[1] != -1) { AddChartArrowDown("ArrowShort_MA" + +Bars[0].Time.Ticks, this.IsAutoAdjustableScale, 0, Bars[0].High, this.ColorShortSignalArrow); } } //Set the color PlotColors[0][0] = this.Color_1; OutputDescriptors[0].PenStyle = this.DashStyle_1; OutputDescriptors[0].Pen.Width = this.LineWidth_1; PlotColors[1][0] = this.Color_2; OutputDescriptors[1].PenStyle = this.DashStyle_2; OutputDescriptors[1].Pen.Width = this.LineWidth_2; PlotColors[2][0] = this.Color_3; OutputDescriptors[2].PenStyle = this.DashStyle_3; OutputDescriptors[2].Pen.Width = this.LineWidth_3; PlotColors[3][0] = this.Color_4; OutputDescriptors[3].PenStyle = this.DashStyle_4; OutputDescriptors[3].Pen.Width = this.LineWidth_4; PlotColors[4][0] = this.Color_5; OutputDescriptors[4].PenStyle = this.DashStyle_5; OutputDescriptors[4].Pen.Width = this.LineWidth_5; PlotColors[5][0] = this.Color_6; OutputDescriptors[5].PenStyle = this.DashStyle_6; OutputDescriptors[5].Pen.Width = this.LineWidth_6; }
protected override void OnBarUpdate() { if (this.DatafeedPeriodicityIsValid(Bars)) { //new day session is beginning so we need to calculate the open range breakout //if we are calculation "older" trading days the whole day will be calculated because to enhance performance. if (this.CurrentdayOfUpdate.Date < Bars[0].Time.Date) { ORB_Result resultvalue = calculate(this.Bars, this.Bars[0]); //Draw if the calculate method was processed till the end if (resultvalue.IsCompleted) { //Set Color for open range Color openrangecolorvalidornot = this.Color_ORB; if (!resultvalue.IsORBValid) { openrangecolorvalidornot = this.Color_ORB_invalid; } //Draw the Open Range DrawRectangle("ORBRect" + resultvalue.StartDate.Ticks, true, resultvalue.Start, this.RangeLow, resultvalue.End, this.RangeHigh, openrangecolorvalidornot, openrangecolorvalidornot, this.Opacity); DrawText("ORBRangeString" + resultvalue.StartDate.Ticks, true, Math.Round((this.RangeHeight), 2).ToString(), resultvalue.Start, this.RangeHigh, 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Gray, openrangecolorvalidornot, this.Opacity); //if we are live on the trading day if (this.Bars.Last().Time.Date == resultvalue.StartDate) { DrawHorizontalLine("LowLine" + resultvalue.StartDate.Ticks, true, this.RangeLow, openrangecolorvalidornot, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); DrawHorizontalLine("HighLine" + resultvalue.StartDate.Ticks, true, this.RangeHigh, openrangecolorvalidornot, this.CurrentSessionLineStyle, this.CurrentSessionLineWidth); } //Draw the target areas DrawRectangle("TargetAreaLong" + resultvalue.StartDate.Ticks, true, this.getOpenRangeEnd(this.getOpenRangeStart(this.Bars, resultvalue.StartDate)), this.RangeHigh, this.getEndOfTradingDay(this.Bars, resultvalue.StartDate), this.TargetLong, this.Color_TargetAreaLong, this.Color_TargetAreaLong, this.Opacity); DrawRectangle("TargetAreaShort" + resultvalue.StartDate.Ticks, true, this.getOpenRangeEnd(this.getOpenRangeStart(this.Bars, resultvalue.StartDate)), this.RangeLow, this.getEndOfTradingDay(this.Bars, resultvalue.StartDate), this.TargetShort, this.Color_TargetAreaShort, this.Color_TargetAreaShort, this.Opacity); } } //Set the indicator value on each bar update, if the breakout is on the current bar if (this.LongBreakout != null && this.LongBreakout.Time == Bars[0].Time) { BarColor = Color.Turquoise; Value.Set(1); DrawArrowUp("ArrowLong" + Bars[0].Time.Date.Ticks, true, this.LongBreakout.Time, this.LongBreakout.Low, Color.Green); } else if (this.ShortBreakout != null && this.ShortBreakout.Time == Bars[0].Time) { BarColor = Color.Purple; Value.Set(-1); DrawArrowDown("ArrowShort" + Bars[0].Time.Date.Ticks, true, this.ShortBreakout.Time, this.ShortBreakout.High, Color.Red); } else { Value.Set(0); } //todo statistic for timeout //todo statistic for stops //Draw the Long Target if this is necessary if (this.LongTargetReached != null) { DrawArrowDown("ArrowTargetLong" + Bars[0].Time.Date.Ticks, true, this.LongTargetReached.Time, this.LongTargetReached.High, Color.Red); //todo add statistic data //this._StatisticContainer.Add(); } //Draw the Short Target if this is necessary if (this.ShortTargetReached != null) { DrawArrowUp("ArrowTargetShort" + Bars[0].Time.Date.Ticks, true, this.ShortTargetReached.Time, this.ShortTargetReached.Low, Color.Green); //todo add statistic data //this._StatisticContainer.Add(); } //Set the color PlotColors[0][0] = this.Plot1Color; Plots[0].PenStyle = this.Dash0Style; Plots[0].Pen.Width = this.Plot0Width; //When finished set the last day variable //If we are online during the day session we do not set this variable so we are redrawing and recalculating the current session again and again if (GlobalUtilities.IsCurrentBarLastDayInBars(this.Bars, this.Bars[0])) { //the last session has started (current trading session, last day in Bars object, and so on) } else { this.CurrentdayOfUpdate = this.Bars[0].Time.Date; } } else { //Data feed perodicity is not valid, print info in chart panel if (IsCurrentBarLast) { DrawTextFixed("AlertText", Const.DefaultStringDatafeedPeriodicity, TextPosition.Center, Color.Red, new Font("Arial", 30), Color.Red, Color.Red, 20); } } }
/// <summary> /// Create SHORT order. /// </summary> private void DoEnterShort() { if (_orderentershort == null) { _orderentershort = SubmitOrder(new StrategyOrderParameters { Direction = OrderDirection.Sell, Type = OrderType.Market, Quantity = GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), SignalName = this.DisplayName + "_" + OrderDirection.Sell + "_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(), Instrument = this.Instrument, TimeFrame = this.TimeFrame }); //SetUpStopLoss(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.RangeHigh, false); //SetUpProfitTarget(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.TargetShort); } }
protected override void OnCalculate() { ////we need more contrast //this.BarColor = Color.White; //calculate data ResultValue returnvalue = this.calculate(InSeries, Open, High, null, null, this.Bollinger_Period, this.Bollinger_Standard_Deviation, this.Momentum_Period, this.RSI_Period, this.RSI_Smooth, this.RSI_Level_Low, this.RSI_Level_High, this.Momentum_Level_Low, this.Momentum_Level_High); //If the calculate method was not finished we need to stop and show an alert message to the user. if (returnvalue.ErrorOccured) { //Display error just one time if (!this.ErrorOccured) { GlobalUtilities.DrawAlertTextOnChart(this, Const.DefaultStringErrorDuringCalculation); this.ErrorOccured = true; } return; } Plot_1.Set(bb_upper); Plot_2.Set(bb_middle); Plot_3.Set(bb_lower); //Entry if (returnvalue.Entry.HasValue) { switch (returnvalue.Entry) { case OrderDirection.Buy: AddChartDot("ArrowLong_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen); //this.Indicator_Curve_Entry.Set(1); break; case OrderDirection.Sell: AddChartDiamond("ArrowShort_Entry" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.LightGreen); //this.Indicator_Curve_Entry.Set(-1); break; } } //else //{ // //Value was null so nothing to do. // this.Indicator_Curve_Entry.Set(0); //} //Exit if (returnvalue.Exit.HasValue) { switch (returnvalue.Exit) { case OrderDirection.Buy: AddChartDiamond("ArrowShort_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red); //this.Indicator_Curve_Exit.Set(0.5); break; case OrderDirection.Sell: AddChartDot("ArrowLong_Exit" + Bars[0].Time.Ticks, true, Bars[0].Time, Bars[0].Open, Color.Red); //this.Indicator_Curve_Exit.Set(-0.5); break; } } //else //{ // //Value was null so nothing to do. // this.Indicator_Curve_Exit.Set(0); //} }
/// <summary> /// Create Short Order and Stop. /// </summary> private void DoEnterShort() { if (this._orderentershort == null) { string entryreason = "ORB_Short_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(); _orderentershort = SubmitOrder(new StrategyOrderParameters { Direction = OrderDirection.Sell, Type = OrderType.Market, Quantity = GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), SignalName = entryreason, Instrument = this.Instrument, TimeFrame = this.TimeFrame }); if (this.UseStopLoss) { SetUpStopLoss(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.RangeHigh, false); } if (this.UseProfitTarget) { SetUpProfitTarget(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.TargetShort); } if (this.StatisticBacktesting) { _statisticshort = new Statistic(this, PositionType.Short); this._statisticshort.SetEntry(entryreason, _orderentershort.Quantity, Bars[0].Close, Bars[0].Time, OrderType.Market); } } }
public void process_ShowGap() { //Prüfen, ob 15min Chart aktiviert ist, anonsten -> raus if (Bars != null && Bars.Count > 0 && TimeFrame.Periodicity == DatafeedHistoryPeriodicity.Minute && TimeFrame.PeriodicityValue == 15) { } else { return; } //Prüfen, ob es sich um die erste Kerze des Tage handelt, nur mit dieser kann Gap berechnet werden if (Bars.BarsCountForSession == 0) { sessionprocessed = false; } //Marktöffnungszeit für Instrument lesen TimeSpan openingtime = GlobalUtilities.GetOfficialMarketOpeningTime(Instrument.Symbol); //Prüfen, ob aktuelle Kerze nach der offiziellen Marktöffnung ist, oder ob es eine vorbörsliche Kerze ist if (Bars.GetTime(ProcessingBarIndex).TimeOfDay > openingtime && //größer 09.00 geht für 15M und 1Std (und 1Tag?) sessionprocessed == false) //Tag noch nicht verarbeitet { sessionprocessed = true; GapTradeLong = GapTradeShort = false; //Erste Kerze des Tages besorgen und deren Errönfnungskurs lesen IBar GapOpenBar = GlobalUtilities.GetFirstBarOfCurrentSession(Bars, Bars[0].Time.Date); GapOpen = GapOpenBar.Open; //Tagesschlusskurs von gestern besorgen double LastDayClose = PriorDayOHLC(Closes[0]).PriorClose[0]; //Wenn es keinen LastDayClose Wert gibt -> raus (immer am Anfang des Charts) if (LastDayClose == 0) { return; } PunkteGapMax = (decimal)LastDayClose * _PunkteGapMaxProz; PunkteGapMin = (decimal)LastDayClose * _PunkteGapMinProz; //gestrige Schlusskurs soll auch als InitialStop für etwaige Orders verwendet werden StopForShowGapTrade = LastDayClose; //Gapgröße berechnen GapSize = GapOpen - LastDayClose; //DateTime von gestrigen Schlusskurs IBar GapCloseBar = GlobalUtilities.GetLastBarOfLastSession(Bars, Bars[0].Time.Date); DateTime LastDayCloseDate = GapCloseBar.Time; DateTime LastPeriod = Time[1]; //Prüfen ob es überhaupt ein Gap gab if (LastDayClose > 0 && Math.Abs(GapSize) > 0) { existgap = true; //Gap markieren (08.00 - 09.15) string strMyRect = "MyRect" + Count; string strMyGapSize = "MyGapSize" + Count; //Gap zeigt nach oben if (IsUpwardsGap() == true) { //Long AddChartRectangle(strMyRect, true, LastDayCloseDate, LastDayClose, LastPeriod, GlobalUtilities.GetHighestHigh(Bars, Bars.BarsCountForSession), _col_gap, _col_gap, 70); AddChartText(strMyGapSize, true, Math.Round(GapSize, 1).ToString(), GapOpenBar.Time, LastDayClose - (60 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, Color.Azure, 1); if (GapIndicatesTradeLong() == true) { //Chancenreicher SuccessTrade Long PrepareTradeLong(); } } //Gap zeigt nach unten else { //Short AddChartRectangle(strMyRect, true, LastDayCloseDate, LastDayClose, LastPeriod, GlobalUtilities.GetLowestLow(Bars, Bars.BarsCountForSession), _col_gap, _col_gap, 70); AddChartText(strMyGapSize, true, Math.Round(GapSize, 1).ToString(), GapOpenBar.Time, LastDayClose + (60 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, Color.Azure, 1); if (GapIndicatesTradeShort() == true) { ////Chancenreicher SuccessTrade Short PrepareTradeShort(); } } if (GapTradeShort == true || GapTradeLong == true) { //Auswertung PrintBasicTradeInfo(); } } else { existgap = false; } } //09.15. - 09.30 Kerze // else if (Bars.BarsCountForSession == 6 && existgap == true) else if (Bars[0].Time.TimeOfDay == new TimeSpan(9, 15, 0)) { //Auswertung nach ShowGap Handelszeit (=09.30) printAuswertung(); GlobalUtilities.SaveSnapShot("ShowGap", Instrument.Name, this.Root.Core.ChartManager.AllCharts, Bars, TimeFrame); } }
protected override void OnCalculate() { string strReversalTradeLong = "ReversalTradeLong" + ProcessingBarIndex; string strReversalTradeShort = "ReversalTradeShort" + ProcessingBarIndex; string strTradeResultLong; string strTradeResultShort; Color colorTextBox; // 1 umkehr fallend auf steigend //-1 umkehr steigend auf fallend if (IsReversalLongTrade() == true) { ReversalTradeStartTSLong = Bars[0].Time; //TargetBarTime = GetTargetBar(Bars[0].Time); TargetBarTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1); OutSeries.Set(100); Reversal2NextBar.Set(100); } else if (IsReversalShortTrade() == true) { ReversalTradeStartTSShort = Bars[0].Time; //TargetBarTime = GetTargetBar(Bars[0].Time); TargetBarTime = GlobalUtilities.GetTargetBar(Bars, Bars[0].Time, TimeFrame, 1); OutSeries.Set(-100); } else { Reversal2NextBar.Set(0); } //TradingKerze ist fertig, Zeiteinheit ist abgelaufen if (Bars[0].Time == TargetBarTime) { ReversalTradeResult = (decimal)Bars.GetClose(ProcessingBarIndex) - (decimal)Bars.GetOpen(ProcessingBarIndex); TradeCounter += 1; if (ReversalTradeStartTSLong > DateTime.MinValue) { ReversalTradeResultTotalLong = ReversalTradeResultTotalLong + ReversalTradeResult; if (ReversalTradeResult < 0) { strTradeResultLong = "Fail " + ReversalTradeResult.ToString(); colorTextBox = colFail; TradeCounterLongFail += 1; } else { strTradeResultLong = "Win " + ReversalTradeResult.ToString(); colorTextBox = colWin; TradeCounterLongWin += 1; } AddChartText(strReversalTradeLong, true, strTradeResultLong, Time[1], Bars.GetHigh(ProcessingBarIndex) + (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70); } else if (ReversalTradeStartTSShort > DateTime.MinValue) { ReversalTradeResultTotalShort = ReversalTradeResultTotalShort + ReversalTradeResult; if (ReversalTradeResult < 0) { strTradeResultShort = "Win " + ReversalTradeResult.ToString(); colorTextBox = colWin; TradeCounterShortWin += 1; } else { strTradeResultShort = "Fail " + ReversalTradeResult.ToString(); colorTextBox = colFail; TradeCounterShortFail += 1; } AddChartText(strReversalTradeShort, true, strTradeResultShort, Time[1], Bars.GetHigh(ProcessingBarIndex) - (100 * TickSize), 9, Color.Black, new Font("Arial", 9), StringAlignment.Center, Color.Black, colorTextBox, 70); } //Variablen Resetten ReversalTradeStartTSLong = DateTime.MinValue; ReversalTradeStartTSShort = DateTime.MinValue; } if (IsProcessingBarIndexLast) { // Print("LongWin: " + TradeCounterLongWin + " LongFail: " + TradeCounterLongFail + " ShortWin: " + TradeCounterShortWin + " ShortFail: " + TradeCounterShortFail); // Print(Instrument.Name + "Trades: " + TradeCounter + " LongPunkte: " + ReversalTradeResultTotalLong + " ShortPunkte: " + ReversalTradeResultTotalShort); } }
/// <summary> /// Create Short Order and Stop. /// </summary> private void DoEnterShort() { _orderentershort = EnterShort(GlobalUtilities.AdjustPositionToRiskManagement(this.Root.Core.AccountManager, this.Root.Core.PreferenceManager, this.Instrument, Bars[0].Close), "ORB_Short_" + this.Instrument.Symbol + "_" + Bars[0].Time.Ticks.ToString(), this.Instrument, this.TimeFrame); SetStopLoss(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.RangeHigh, false); SetProfitTarget(_orderentershort.Name, CalculationMode.Price, this._orb_indicator.TargetShort); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnCalculate() { int temp_signal_value = 0; double actualhigh = High[0]; double actuallow = Low[0]; if (this.Type == enum_swingray_type.open) { actualhigh = Open[0]; actuallow = Open[0]; } else if (this.Type == enum_swingray_type.close) { actualhigh = Close[0]; actuallow = Close[0]; } // build up cache of recent High and Low values // code devised from default Swing Indicator by marqui@BMT, 10-NOV-2010 lastHighCache.Add(actualhigh); if (lastHighCache.Count > (2 * strength) + 1) { lastHighCache.RemoveAt(0); // if cache is filled, drop the oldest value } lastLowCache.Add(actuallow); if (lastLowCache.Count > (2 * strength) + 1) { lastLowCache.RemoveAt(0); } // if (lastHighCache.Count == (2 * strength) + 1) // wait for cache of Highs to be filled { // test for swing high bool isSwingHigh = true; double swingHighCandidateValue = (double)lastHighCache[strength]; for (int i = 0; i < strength; i++) { if ((double)lastHighCache[i] >= swingHighCandidateValue - double.Epsilon) { isSwingHigh = false; // bar(s) to right of candidate were higher } } for (int i = strength + 1; i < lastHighCache.Count; i++) { if ((double)lastHighCache[i] > swingHighCandidateValue - double.Epsilon) { isSwingHigh = false; // bar(s) to left of candidate were higher } } // end of test if (isSwingHigh) { lastSwingHighValue = swingHighCandidateValue; } if (isSwingHigh) // if we have a new swing high then we draw a ray line on the chart { AddChartRay("highRay" + (ProcessingBarIndex - strength), false, strength, lastSwingHighValue, 0, lastSwingHighValue, swingHighColor, DashStyle.Solid, 1); RayObject newRayObject = new RayObject("highRay" + (ProcessingBarIndex - strength), strength, lastSwingHighValue, 0, lastSwingHighValue); swingHighRays.Push(newRayObject); // store a reference so we can remove it from the chart later } else if (actualhigh > lastSwingHighValue) // otherwise, we test to see if price has broken through prior swing high { if (swingHighRays.Count > 0) // just to be safe { //IRay currentRay = (IRay)swingHighRays.Pop(); // pull current ray from stack RayObject currentRay = (RayObject)swingHighRays.Pop(); // pull current ray from stack if (currentRay != null) { if (enableAlerts) { ShowAlert("Swing High at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile)); } temp_signal_value = 1; if (keepBrokenLines) // draw a line between swing point and break bar { int barsAgo = currentRay.BarsAgo1; ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingHighColor, DashStyle.Dot, 2); } RemoveChartDrawing(currentRay.Tag); if (swingHighRays.Count > 0) { //IRay priorRay = (IRay)swingHighRays.Peek(); RayObject priorRay = (RayObject)swingHighRays.Peek(); lastSwingHighValue = priorRay.Y1; // needed when testing the break of the next swing high } else { lastSwingHighValue = double.MaxValue; // there are no higher swings on the chart; reset to default } } } } } if (lastLowCache.Count == (2 * strength) + 1) // repeat the above for the swing lows { // test for swing low bool isSwingLow = true; double swingLowCandidateValue = (double)lastLowCache[strength]; for (int i = 0; i < strength; i++) { if ((double)lastLowCache[i] <= swingLowCandidateValue + double.Epsilon) { isSwingLow = false; // bar(s) to right of candidate were lower } } for (int i = strength + 1; i < lastLowCache.Count; i++) { if ((double)lastLowCache[i] < swingLowCandidateValue + double.Epsilon) { isSwingLow = false; // bar(s) to left of candidate were lower } } // end of test for low if (isSwingLow) { lastSwingLowValue = swingLowCandidateValue; } if (isSwingLow) // found a new swing low; draw it on the chart { AddChartRay("lowRay" + (ProcessingBarIndex - strength), false, strength, lastSwingLowValue, 0, lastSwingLowValue, swingLowColor, DashStyle.Solid, 1); RayObject newRayObject = new RayObject("lowRay" + (ProcessingBarIndex - strength), strength, lastSwingLowValue, 0, lastSwingLowValue); swingLowRays.Push(newRayObject); } else if (actuallow < lastSwingLowValue) // otherwise test to see if price has broken through prior swing low { if (swingLowRays.Count > 0) { //IRay currentRay = (IRay)swingLowRays.Pop(); RayObject currentRay = (RayObject)swingLowRays.Pop(); if (currentRay != null) { if (enableAlerts) { ShowAlert("Swing Low at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile)); } temp_signal_value = -1; if (keepBrokenLines) // draw a line between swing point and break bar { int barsAgo = currentRay.BarsAgo1; ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingLowColor, DashStyle.Dot, 2); } RemoveChartDrawing(currentRay.Tag); if (swingLowRays.Count > 0) { //IRay priorRay = (IRay)swingLowRays.Peek(); RayObject priorRay = (RayObject)swingLowRays.Peek(); lastSwingLowValue = priorRay.Y1; // price level of the prior swing low } else { lastSwingLowValue = double.MinValue; // no swing lows present; set this to default value } } } } } if (enablesignalline) { SignalLine.Set(temp_signal_value); } else { this.SwingHighs.Set(lastSwingHighValue); this.SwingLows.Set(lastSwingLowValue); this.PriceLines.Set(InSeries[0]); } //Set the color PlotColors[0][0] = this.Signal; OutputDescriptors[0].PenStyle = DashStyle.Solid; OutputDescriptors[0].Pen.Width = this.Plot0Width; PlotColors[1][0] = this.swingHighColor; OutputDescriptors[1].PenStyle = DashStyle.Solid; OutputDescriptors[1].Pen.Width = this.Plot0Width; PlotColors[2][0] = this.swingLowColor; OutputDescriptors[2].PenStyle = DashStyle.Solid; OutputDescriptors[2].Pen.Width = this.Plot0Width; PlotColors[3][0] = this.Signal; OutputDescriptors[3].PenStyle = DashStyle.Solid; OutputDescriptors[3].Pen.Width = this.Plot0Width; }
protected override void OnStart() { decimal vdax_new = GlobalUtilities.GetCurrentVdaxNew(this.CheckEveryXSeconds); AddChartTextFixed("VDAX_NEW", "VDAX-NEW: " + vdax_new, this.TextPosition, Color.Black, new Font("Arial", this.TextSize), Color.Transparent, Color.Transparent); }