public override void Calculate(IDataSet dataSet) { DataSet = dataSet; if (!IsBacktester) { // FST sends the N bars for exit to the expert. Expert watches the position and closes it. return; } var nExit = (int) IndParam.NumParam[0].Value; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "N Bars Exit (" + nExit.ToString(CultureInfo.InvariantCulture) + ")", DataType = IndComponentType.ForceClose, ChartType = IndChartType.NoChart, ShowInDynInfo = true, FirstBar = 1, Value = new double[Bars] }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var entryHour = (int) IndParam.NumParam[0].Value; var entryMinute = (int) IndParam.NumParam[1].Value; var entryTime = new TimeSpan(entryHour, entryMinute, 0); // Calculation const int firstBar = 1; var adBars = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { adBars[bar] = Time[bar].TimeOfDay == entryTime ? Open[bar] : 0; } // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Entry hour", DataType = IndComponentType.OpenPrice, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = adBars }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation const int firstBar = 2; var adIb = new double[Bars]; for (int iBar = 2; iBar < Bars; iBar++) { adIb[iBar] = ((High[iBar - 1] < High[iBar - 2]) && (Low[iBar - 1] > Low[iBar - 2])) ? 1 : 0; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Allow long entry", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = adIb }; Component[1] = new IndicatorComp { CompName = "Allow short entry", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = adIb }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var price = (BasePrice) IndParam.ListParam[1].Index; double margin = IndParam.NumParam[0].Value*Point; int prvs = IndParam.CheckParam[0].Checked ? 1 : 0; // TimeExecution if (price == BasePrice.Open && Math.Abs(margin - 0) < Epsilon) IndParam.ExecutionTime = ExecutionTime.AtBarOpening; else if (price == BasePrice.Close && Math.Abs(margin - 0) < Epsilon) IndParam.ExecutionTime = ExecutionTime.AtBarClosing; // Calculation double[] adBasePr = Price(price); var adUpBand = new double[Bars]; var adDnBand = new double[Bars]; int firstBar = 1 + prvs; for (int iBar = firstBar; iBar < Bars; iBar++) { adUpBand[iBar] = adBasePr[iBar - prvs] + margin; adDnBand[iBar] = adBasePr[iBar - prvs] - margin; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Up Price", ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = adUpBand }; Component[1] = new IndicatorComp { CompName = "Down Price", ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = adDnBand }; switch (IndParam.ListParam[0].Text) { case "Enter long after an upward move": Component[0].DataType = IndComponentType.OpenLongPrice; Component[1].DataType = IndComponentType.OpenShortPrice; break; case "Enter long after a downward move": Component[0].DataType = IndComponentType.OpenShortPrice; Component[1].DataType = IndComponentType.OpenLongPrice; break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation var adClosePrice = new double[Bars]; for (int bar = 1; bar < Bars; bar++) if (Time[bar - 1].Day != Time[bar].Day) adClosePrice[bar - 1] = Close[bar - 1]; // Check the last bar TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int) Period, 0)); var tsDayClosing = new TimeSpan(24, 0, 0); if (tsBarClosing == tsDayClosing) adClosePrice[Bars - 1] = Close[Bars - 1]; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Closing price of the day", DataType = IndComponentType.ClosePrice, ChartType = IndChartType.NoChart, FirstBar = 2, Value = adClosePrice }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var fromHour = (int) IndParam.NumParam[0].Value; var fromMin = (int) IndParam.NumParam[1].Value; var untilHour = (int) IndParam.NumParam[2].Value; var untilMin = (int) IndParam.NumParam[3].Value; var fromTime = new TimeSpan(fromHour, fromMin, 0); var untilTime = new TimeSpan(untilHour, untilMin, 0); // Calculation const int firstBar = 1; var adBars = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { if (fromTime < untilTime) adBars[bar] = Time[bar].TimeOfDay >= fromTime && Time[bar].TimeOfDay < untilTime ? 1 : 0; else if (fromTime > untilTime) adBars[bar] = Time[bar].TimeOfDay >= fromTime || Time[bar].TimeOfDay < untilTime ? 1 : 0; else adBars[bar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Is long entry allowed", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = adBars }; Component[1] = new IndicatorComp { CompName = "Is short entry allowed", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = adBars }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var dowFromDay = (DayOfWeek) IndParam.ListParam[1].Index; var dowUntilDay = (DayOfWeek) IndParam.ListParam[2].Index; // Calculation const int firstBar = 1; var signal = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { if (dowFromDay < dowUntilDay) signal[bar] = Time[bar].DayOfWeek >= dowFromDay && Time[bar].DayOfWeek < dowUntilDay ? 1 : 0; else if (dowFromDay > dowUntilDay) signal[bar] = Time[bar].DayOfWeek >= dowFromDay || Time[bar].DayOfWeek < dowUntilDay ? 1 : 0; else signal[bar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Allow long entry", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = signal }; Component[1] = new IndicatorComp { CompName = "Allow short entry", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = signal }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var period = (int) IndParam.NumParam[0].Value; var multipl = (int) IndParam.NumParam[1].Value; int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + 2; var atr = new double[Bars]; for (int bar = 1; bar < Bars; bar++) atr[bar] = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]); atr = MovingAverage(period, 0, maMethod, atr); var atrStop = new double[Bars]; double pip = (Digits == 5 || Digits == 3) ? 10*Point : Point; double minStop = 5*pip; for (int bar = firstBar; bar < Bars - prev; bar++) atrStop[bar + prev] = Math.Max(atr[bar]*multipl, minStop); // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "ATR Stop margin", DataType = IndComponentType.IndicatorValue, FirstBar = firstBar, ShowInDynInfo = false, Value = atrStop }; Component[1] = new IndicatorComp { CompName = "ATR Stop for the transferred position", DataType = IndComponentType.Other, ShowInDynInfo = false, FirstBar = firstBar, Value = new double[Bars] }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Opening price of the bar", DataType = IndComponentType.OpenPrice, ChartType = IndChartType.NoChart, FirstBar = 2, Value = Open }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Close Price", DataType = (IndParam.SlotType == SlotTypes.Open) ? IndComponentType.OpenPrice : IndComponentType.ClosePrice, ChartType = IndChartType.NoChart, FirstBar = 2, Value = Close }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Trailing Stop for the transferred position", DataType = IndComponentType.Other, ShowInDynInfo = false, FirstBar = 1, Value = new double[Bars] }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Is long entry allowed", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, FirstBar = 0, Value = new double[Bars] }; Component[1] = new IndicatorComp { CompName = "Is short entry allowed", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, FirstBar = 0, Value = new double[Bars] }; // Calculation of the logic switch (IndParam.ListParam[0].Text) { case "Open long positions only": for (int i = 0; i < Bars; i++) { Component[0].Value[i] = 1; Component[1].Value[i] = 0; } break; case "Open short positions only": for (int i = 0; i < Bars; i++) { Component[0].Value[i] = 0; Component[1].Value[i] = 1; } break; } }
public IndicatorSlot() { SlotNumber = 0; SlotType = SlotTypes.NotDefined; LogicalGroup = ""; IsDefined = false; IsCalculated = false; IndicatorName = "Not defined"; IndParam = new IndicatorParam(); SeparatedChart = false; Component = new IndicatorComp[] {}; SpecValue = new double[] {}; MinValue = double.MaxValue; MaxValue = double.MinValue; SignalShiftType = SignalShiftType.At; SignalShift = 0; IndicatorSymbol = ""; IndicatorPeriod = DataPeriod.M1; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters int hour = (int) IndParam.NumParam[0].Value; int minute = (int) IndParam.NumParam[1].Value; // Calculation const int firstBar = 2; double[] signal = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { DateTime closeTime = Time[bar].AddMinutes((int) Period); if (closeTime.Hour == hour && closeTime.Minute == minute) signal[bar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Close out long position", DataType = IndComponentType.ForceCloseLong, ChartType = IndChartType.NoChart, ShowInDynInfo = true, FirstBar = firstBar, Value = signal }; Component[1] = new IndicatorComp { CompName = "Close out short position", DataType = IndComponentType.ForceCloseShort, ChartType = IndChartType.NoChart, ShowInDynInfo = true, FirstBar = firstBar, Value = signal }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var exitHour = (int) IndParam.NumParam[0].Value; var tsExitHour = new TimeSpan(exitHour, 0, 0); // Calculation const int firstBar = 1; var adBars = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars; bar++) { if (Time[bar - 1].DayOfYear == Time[bar].DayOfYear && Time[bar - 1].TimeOfDay < tsExitHour && Time[bar].TimeOfDay >= tsExitHour) adBars[bar - 1] = Close[bar - 1]; else if (Time[bar - 1].DayOfYear != Time[bar].DayOfYear && Time[bar - 1].TimeOfDay < tsExitHour) adBars[bar - 1] = Close[bar - 1]; else adBars[bar] = 0; } // Check the last bar if (Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int) Period, 0)) == tsExitHour) adBars[Bars - 1] = Close[Bars - 1]; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Exit hour", DataType = IndComponentType.ClosePrice, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = adBars }; }
public IndicatorComp Clone() { var indicatorComp = new IndicatorComp { CompName = CompName, DataType = DataType, ChartType = ChartType, ChartColor = ChartColor, FirstBar = FirstBar, UsePreviousBar = UsePreviousBar, ShowInDynInfo = ShowInDynInfo, PosPriceDependence = PosPriceDependence }; if (Value != null) { indicatorComp.Value = new double[Value.Length]; Value.CopyTo(indicatorComp.Value, 0); } return(indicatorComp); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation var adOpenPrice = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) if (Time[iBar - 1].Day != Time[iBar].Day) adOpenPrice[iBar] = Open[iBar]; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Opening price of the day", DataType = IndComponentType.OpenPrice, ChartType = IndChartType.NoChart, FirstBar = 2, Value = adOpenPrice }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation const int firstBar = 1; var adBars = new double[Bars]; // Calculation of the logic for (int bar = 0; bar < Bars - 1; bar++) { if (Time[bar].DayOfWeek > DayOfWeek.Wednesday && Time[bar + 1].DayOfWeek < DayOfWeek.Wednesday) adBars[bar] = Close[bar]; else adBars[bar] = 0; } // Check the last bar TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int) Period, 0)); var tsDayClosing = new TimeSpan(24, 0, 0); if (Time[Bars - 1].DayOfWeek == DayOfWeek.Friday && tsBarClosing == tsDayClosing) adBars[Bars - 1] = Close[Bars - 1]; // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp { CompName = "Week Closing", DataType = IndComponentType.ClosePrice, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = adBars }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var fromHour = (int) IndParam.NumParam[0].Value; var fromMin = (int) IndParam.NumParam[1].Value; var untilHour = (int) IndParam.NumParam[2].Value; var untilMin = (int) IndParam.NumParam[3].Value; var tsFromTime = new TimeSpan(fromHour, fromMin, 0); var tsUntilTime = new TimeSpan(untilHour, untilMin, 0); double shift = IndParam.NumParam[4].Value*Point; const int firstBar = 2; // Calculation var adHighPrice = new double[Bars]; var adLowPrice = new double[Bars]; double dMinPrice = double.MaxValue; double dMaxPrice = double.MinValue; adHighPrice[0] = 0; adLowPrice[0] = 0; bool bPrevPeriod = false; for (int iBar = 1; iBar < Bars; iBar++) { bool bPeriod; if (tsFromTime < tsUntilTime) bPeriod = Time[iBar].TimeOfDay >= tsFromTime && Time[iBar].TimeOfDay < tsUntilTime; else if (tsFromTime > tsUntilTime) bPeriod = Time[iBar].TimeOfDay >= tsFromTime || Time[iBar].TimeOfDay < tsUntilTime; else bPeriod = true; if (bPeriod) { if (dMaxPrice < High[iBar]) dMaxPrice = High[iBar]; if (dMinPrice > Low[iBar]) dMinPrice = Low[iBar]; } if (!bPeriod && bPrevPeriod) { adHighPrice[iBar] = dMaxPrice; adLowPrice[iBar] = dMinPrice; dMaxPrice = double.MinValue; dMinPrice = double.MaxValue; } else { adHighPrice[iBar] = adHighPrice[iBar - 1]; adLowPrice[iBar] = adLowPrice[iBar - 1]; } bPrevPeriod = bPeriod; } // Shifting the price var adUpperBand = new double[Bars]; var adLowerBand = new double[Bars]; for (int iBar = firstBar; iBar < Bars; iBar++) { adUpperBand[iBar] = adHighPrice[iBar] + shift; adLowerBand[iBar] = adLowPrice[iBar] - shift; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp { CompName = "Hourly High", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Level, ChartColor = Color.DarkGreen, FirstBar = firstBar, Value = adHighPrice }; Component[1] = new IndicatorComp { CompName = "Hourly Low", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Level, ChartColor = Color.DarkRed, FirstBar = firstBar, Value = adLowPrice }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.Open) { Component[2].CompName = "Long position entry price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[3].CompName = "Short position entry price"; Component[3].DataType = IndComponentType.OpenShortPrice; } else if (SlotType == SlotTypes.OpenFilter) { Component[2].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is short entry allowed"; Component[3].DataType = IndComponentType.AllowOpenShort; } else if (SlotType == SlotTypes.Close) { Component[2].CompName = "Long position closing price"; Component[2].DataType = IndComponentType.CloseLongPrice; Component[3].CompName = "Short position closing price"; Component[3].DataType = IndComponentType.CloseShortPrice; } else if (SlotType == SlotTypes.CloseFilter) { Component[2].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out short position"; Component[3].DataType = IndComponentType.ForceCloseShort; } switch (IndParam.ListParam[0].Text) { case "Enter long at the hourly high": case "Exit long at the hourly high": Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "Enter long at the hourly low": case "Exit long at the hourly low": Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The bar closes below the hourly high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band); break; case "The bar closes above the hourly high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below the hourly low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above the hourly low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; case "The position opens above the hourly high": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted hourly high"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted hourly low"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens below the hourly high": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted hourly high"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted hourly low"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens above the hourly low": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted hourly low"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted hourly high"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The position opens below the hourly low": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted hourly low"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted hourly high"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var basePrice = (BasePrice) IndParam.ListParam[2].Index; var iPeriod = (int) IndParam.NumParam[0].Value; var iSmooth = (int) IndParam.NumParam[1].Value; double dLevel = IndParam.NumParam[2].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = iPrvs + iPeriod + iSmooth + 2; var adMomentum = new double[Bars]; double[] adBasePrice = Price(basePrice); for (int iBar = iPeriod; iBar < Bars; iBar++) adMomentum[iBar] = adBasePrice[iBar] - adBasePrice[iBar - iPeriod]; if (iSmooth > 0) adMomentum = MovingAverage(iSmooth, 0, maMethod, adMomentum); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Momentum", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = iFirstBar, Value = adMomentum }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Momentum rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[] {0}; break; case "Momentum falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[] {0}; break; case "Momentum is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new[] {dLevel, -dLevel}; break; case "Momentum is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new[] {dLevel, -dLevel}; break; case "Momentum crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new[] {dLevel, -dLevel}; break; case "Momentum crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new[] {dLevel, -dLevel}; break; case "Momentum changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[] {0}; break; case "Momentum changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[] {0}; break; } OscillatorLogic(iFirstBar, iPrvs, adMomentum, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maSignalMAMethod = (MAMethod) IndParam.ListParam[2].Index; var period1 = (int) IndParam.NumParam[0].Value; var period2 = (int) IndParam.NumParam[1].Value; int prvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period1 + period2 + 2; var adOscillator = new double[Bars]; // --------------------------------------------------------- var roc1 = new RateOfChange(); roc1.Initialize(SlotType); roc1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; roc1.IndParam.ListParam[2].Index = IndParam.ListParam[3].Index; roc1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; roc1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; roc1.Calculate(DataSet); double[] adIndicator1 = roc1.Component[0].Value; double[] adIndicator2 = MovingAverage(period2, 0, maSignalMAMethod, adIndicator1); // ---------------------------------------------------------- for (int bar = firstBar; bar < Bars; bar++) { adOscillator[bar] = adIndicator1[bar] - adIndicator2[bar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Oscillator", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = adOscillator }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "ROC MA Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "ROC MA Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "ROC MA Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "ROC MA Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "ROC MA Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "ROC MA Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "ROC MA Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "ROC MA Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(firstBar, prvs, adOscillator, 0, 0, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var basePrice = (BasePrice) IndParam.ListParam[2].Index; var iPeriod = (int) IndParam.NumParam[0].Value; var iSmooth = (int) IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adBasePrice = Price(basePrice); var adCumulativeSum = new double[Bars]; adCumulativeSum[iPeriod - 1] = 0; for (int iBar = 0; iBar < iPeriod; iBar++) { adCumulativeSum[iPeriod - 1] += adBasePrice[iBar]; } for (int iBar = iPeriod; iBar < Bars; iBar++) { adCumulativeSum[iBar] = adCumulativeSum[iBar - 1] - adBasePrice[iBar - iPeriod] + adBasePrice[iBar]; } adCumulativeSum = MovingAverage(iSmooth, 0, maMethod, adCumulativeSum); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Cumulative Sum", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = iFirstBar, Value = adCumulativeSum }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Cumulative Sum rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "Cumulative Sum falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "Cumulative Sum changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "Cumulative Sum changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; } OscillatorLogic(iFirstBar, iPrvs, adCumulativeSum, 0, 0, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters double gapLimit = IndParam.NumParam[0].Value*Point; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] histogram = new double[Bars]; double[] longSignal = new double[Bars]; double[] shortSignal = new double[Bars]; int firstBar = 2; for (int bar = 1; bar < Bars; bar++) histogram[bar] = Open[bar] - Close[bar - 1]; double sigma = Sigma(); if (IndParam.ListParam[0].Text == "Do not trade on gap") { for (int bar = 1 + previous; bar < Bars; bar++) { double trade = Math.Abs(histogram[bar - previous]) < gapLimit - sigma ? 1 : 0; longSignal[bar] = trade; shortSignal[bar] = trade; } } else if (IndParam.ListParam[0].Text == "Trade on gap") { for (int bar = 1 + previous; bar < Bars; bar++) { double trade = Math.Abs(histogram[bar - previous]) >= gapLimit ? 1 : 0; longSignal[bar] = trade; shortSignal[bar] = trade; } } else if (IndParam.ListParam[0].Text == "Trade long on positive gap") { for (int bar = 1 + previous; bar < Bars; bar++) { longSignal[bar] = histogram[bar - previous] >= gapLimit ? 1 : 0; shortSignal[bar] = histogram[bar - previous] <= -gapLimit ? 1 : 0; } } else if (IndParam.ListParam[0].Text == "Trade long on negative gap") { for (int bar = 1 + previous; bar < Bars; bar++) { longSignal[bar] = histogram[bar - previous] <= -gapLimit ? 1 : 0; shortSignal[bar] = histogram[bar - previous] >= gapLimit ? 1 : 0; } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "Gap Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = histogram }; Component[1] = new IndicatorComp { CompName = "Is long entry allowed", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = longSignal }; Component[2] = new IndicatorComp { CompName = "Is short entry allowed", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = shortSignal }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var iPeriod = (int) IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = iPeriod + 2; var adDeMax = new double[Bars]; var adDeMin = new double[Bars]; var adDeMarker = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { adDeMax[iBar] = High[iBar] > High[iBar - 1] ? High[iBar] - High[iBar - 1] : 0; adDeMin[iBar] = Low[iBar] < Low[iBar - 1] ? Low[iBar - 1] - Low[iBar] : 0; } double[] adDeMaxMA = MovingAverage(iPeriod, 0, maMethod, adDeMax); double[] adDeMinMA = MovingAverage(iPeriod, 0, maMethod, adDeMin); for (int iBar = firstBar; iBar < Bars; iBar++) { if (Math.Abs(adDeMaxMA[iBar] + adDeMinMA[iBar] - 0) < Epsilon) adDeMarker[iBar] = 0; else adDeMarker[iBar] = adDeMaxMA[iBar]/(adDeMaxMA[iBar] + adDeMinMA[iBar]); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "DeMarker", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.RoyalBlue, FirstBar = firstBar, Value = adDeMarker }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "DeMarker rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new[] {0.5}; break; case "DeMarker falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new[] {0.5}; break; case "DeMarker is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new[] {dLevel, 1 - dLevel}; break; case "DeMarker is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new[] {dLevel, 1 - dLevel}; break; case "DeMarker crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new[] {dLevel, 1 - dLevel}; break; case "DeMarker crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new[] {dLevel, 1 - dLevel}; break; case "DeMarker changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new[] {0.5}; break; case "DeMarker changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new[] {0.5}; break; } OscillatorLogic(firstBar, iPrvs, adDeMarker, dLevel, 1 - dLevel, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; double dShift = IndParam.NumParam[0].Value*Point; // Calculation var adHighPrice = new double[Bars]; var adLowPrice = new double[Bars]; const int firstBar = 2; for (int iBar = firstBar; iBar < Bars; iBar++) { adHighPrice[iBar] = High[iBar - 1]; adLowPrice[iBar] = Low[iBar - 1]; } var adUpperBand = new double[Bars]; var adLowerBand = new double[Bars]; for (int bar = firstBar; bar < Bars; bar++) { adUpperBand[bar] = adHighPrice[bar] + dShift; adLowerBand[bar] = adLowPrice[bar] - dShift; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp { CompName = "Previous High", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Level, ChartColor = Color.DarkGreen, FirstBar = firstBar, Value = adHighPrice }; Component[1] = new IndicatorComp { CompName = "Previous Low", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Level, ChartColor = Color.DarkRed, FirstBar = firstBar, Value = adLowPrice }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.Open) { Component[2].CompName = "Long position entry price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[3].CompName = "Short position entry price"; Component[3].DataType = IndComponentType.OpenShortPrice; } else if (SlotType == SlotTypes.OpenFilter) { Component[2].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is short entry allowed"; Component[3].DataType = IndComponentType.AllowOpenShort; } else if (SlotType == SlotTypes.Close) { Component[2].CompName = "Long position closing price"; Component[2].DataType = IndComponentType.CloseLongPrice; Component[3].CompName = "Short position closing price"; Component[3].DataType = IndComponentType.CloseShortPrice; } else if (SlotType == SlotTypes.CloseFilter) { Component[2].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out short position"; Component[3].DataType = IndComponentType.ForceCloseShort; } switch (IndParam.ListParam[0].Text) { case "Enter long at the previous high": case "Exit long at the previous high": Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "Enter long at the previous low": case "Exit long at the previous low": Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The bar opens below the previous high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar opens above the previous high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band); break; case "The bar opens below the previous low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band); break; case "The bar opens above the previous low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band); break; case "The bar closes below the previous high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band); break; case "The bar closes above the previous high": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below the previous low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above the previous low": BandIndicatorLogic(firstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; case "The position opens above the previous high": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted previous high"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted previous low"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens below the previous high": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted previous high"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted previous low"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens above the previous low": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted previous low"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted previous high"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The position opens below the previous low": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted previous low"; Component[2].DataType = IndComponentType.Other; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted previous high"; Component[3].DataType = IndComponentType.Other; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters double dLevel = IndParam.NumParam[0].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adVolumes = new double[Bars]; int iFirstBar = iPrvs + 1; for (int iBar = 0; iBar < Bars; iBar++) { adVolumes[iBar] = Volume[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Volumes"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adVolumes; Component[1] = new IndicatorComp(); Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = new double[Bars]; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic switch (IndParam.ListParam[0].Text) { case "Volume rises": for (int iBar = iPrvs + 1; iBar < Bars; iBar++) { Component[1].Value[iBar] = adVolumes[iBar - iPrvs] > adVolumes[iBar - iPrvs - 1] + Sigma() ? 1 : 0; Component[2].Value[iBar] = adVolumes[iBar - iPrvs] > adVolumes[iBar - iPrvs - 1] + Sigma() ? 1 : 0; } break; case "Volume falls": for (int iBar = iPrvs + 1; iBar < Bars; iBar++) { Component[1].Value[iBar] = adVolumes[iBar - iPrvs] < adVolumes[iBar - iPrvs - 1] - Sigma() ? 1 : 0; Component[2].Value[iBar] = adVolumes[iBar - iPrvs] < adVolumes[iBar - iPrvs - 1] - Sigma() ? 1 : 0; } break; case "Volume is higher than the Level line": for (int iBar = iPrvs; iBar < Bars; iBar++) { Component[1].Value[iBar] = adVolumes[iBar - iPrvs] > dLevel + Sigma() ? 1 : 0; Component[2].Value[iBar] = adVolumes[iBar - iPrvs] > dLevel + Sigma() ? 1 : 0; } SpecialValues = new double[1] { dLevel }; break; case "Volume is lower than the Level line": for (int iBar = iPrvs; iBar < Bars; iBar++) { Component[1].Value[iBar] = adVolumes[iBar - iPrvs] < dLevel - Sigma() ? 1 : 0; Component[2].Value[iBar] = adVolumes[iBar - iPrvs] < dLevel - Sigma() ? 1 : 0; } SpecialValues = new double[1] { dLevel }; break; default: break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var basePrice = (BasePrice) IndParam.ListParam[2].Index; var period = (int) IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + 2; double[] adBasePrice = Price(basePrice); var adPos = new double[Bars]; var adNeg = new double[Bars]; var adRsi = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { if (adBasePrice[iBar] > adBasePrice[iBar - 1]) adPos[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1]; if (adBasePrice[iBar] < adBasePrice[iBar - 1]) adNeg[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar]; } double[] adPosMA = MovingAverage(period, 0, maMethod, adPos); double[] adNegMA = MovingAverage(period, 0, maMethod, adNeg); for (int bar = firstBar; bar < Bars; bar++) { if (Math.Abs(adNegMA[bar] - 0) < Epsilon) adRsi[bar] = 100; else adRsi[bar] = 100 - (100/(1 + adPosMA[bar]/adNegMA[bar])); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp { CompName = "RSI", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.RoyalBlue, FirstBar = firstBar, Value = adRsi }; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } // Calculation of the logic var indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "RSI rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[] {50}; break; case "RSI falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[] {50}; break; case "RSI is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new[] {dLevel, 100 - dLevel}; break; case "RSI is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new[] {dLevel, 100 - dLevel}; break; case "RSI crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new[] {dLevel, 100 - dLevel}; break; case "RSI crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new[] {dLevel, 100 - dLevel}; break; case "RSI changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[] {50}; break; case "RSI changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[] {50}; break; } OscillatorLogic(firstBar, iPrvs, adRsi, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic); }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var year = (int) IndParam.NumParam[0].Value; var month = (int) IndParam.NumParam[1].Value; var keyDate = new DateTime(year, month, 1); // Calculation int firstBar = 0; var values = new double[Bars]; // Calculation of the logic. if (IsBacktester) { switch (IndParam.ListParam[0].Text) { case "Do not open positions after": for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] < keyDate) values[bar] = 1; break; case "Do not open positions before": for (int bar = firstBar; bar < Bars; bar++) if (Time[bar] >= keyDate) { firstBar = bar; break; } firstBar = Math.Min(firstBar, Bars - 300); for (int bar = firstBar; bar < Bars; bar++) values[bar] = 1; break; } } else { for (int bar = firstBar; bar < Bars; bar++) values[bar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp { CompName = "Allow Open Long", DataType = IndComponentType.AllowOpenLong, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = values }; Component[1] = new IndicatorComp { CompName = "Allow Open Short", DataType = IndComponentType.AllowOpenShort, ChartType = IndChartType.NoChart, ShowInDynInfo = false, FirstBar = firstBar, Value = values }; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var basePrice = (BasePrice) IndParam.ListParam[2].Index; var nPeriod = (int) IndParam.NumParam[0].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = 2*nPeriod + 2; double[] ma1 = MovingAverage(nPeriod, 0, maMethod, Price(basePrice)); double[] ma2 = MovingAverage(nPeriod, 0, maMethod, ma1); double[] ma3 = MovingAverage(nPeriod, 0, maMethod, ma2); var adTrix = new double[Bars]; for (int bar = firstBar; bar < Bars; bar++) adTrix[bar] = 100*(ma3[bar] - ma3[bar - 1])/ma3[bar - 1]; double[] adSignal = MovingAverage(nPeriod, 0, maMethod, adTrix); // adHistogram represents Trix Index oscillator var adHistogram = new double[Bars]; for (int bar = firstBar; bar < Bars; bar++) adHistogram[bar] = adTrix[bar] - adSignal[bar]; // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp { CompName = "Histogram", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Histogram, FirstBar = firstBar, Value = adHistogram }; Component[1] = new IndicatorComp { CompName = "Signal", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Gold, FirstBar = firstBar, Value = adSignal }; Component[2] = new IndicatorComp { CompName = "Trix Line", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = firstBar, Value = adTrix }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[4] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.OpenFilter) { Component[3].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is long entry allowed"; Component[4].DataType = IndComponentType.AllowOpenShort; Component[4].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[3].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out long position"; Component[4].DataType = IndComponentType.ForceCloseShort; Component[4].CompName = "Close out short position"; } switch (IndParam.ListParam[0].Text) { case "Trix Index line rises": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_rises); break; case "Trix Index line falls": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_falls); break; case "Trix Index line is higher than zero": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "Trix Index line is lower than zero": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; case "Trix Index line crosses the zero line upward": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "Trix Index line crosses the zero line downward": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "Trix Index line changes its direction upward": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_upward); break; case "Trix Index line changes its direction downward": OscillatorLogic(firstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_downward); break; case "Trix Index line crosses the Signal line upward": OscillatorLogic(firstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "Trix Index line crosses the Signal line downward": OscillatorLogic(firstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "Trix Index line is higher than the Signal line": OscillatorLogic(firstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "Trix Index line is lower than the Signal line": OscillatorLogic(firstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; var maMethod = (MAMethod) IndParam.ListParam[1].Index; var basePrice = (BasePrice) IndParam.ListParam[2].Index; var iNJaws = (int) IndParam.NumParam[0].Value; var iSJaws = (int) IndParam.NumParam[1].Value; var iNTeeth = (int) IndParam.NumParam[2].Value; var iSTeeth = (int) IndParam.NumParam[3].Value; var iNLips = (int) IndParam.NumParam[4].Value; var iSLips = (int) IndParam.NumParam[5].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = Math.Max(iNJaws + iSJaws + 2, iNTeeth + iSTeeth + 2); iFirstBar = Math.Max(iFirstBar, iNLips + iSLips + 2); // Calculation double[] adJaws = MovingAverage(iNJaws, iSJaws, maMethod, Price(basePrice)); double[] adTeeth = MovingAverage(iNTeeth, iSTeeth, maMethod, Price(basePrice)); double[] adLips = MovingAverage(iNLips, iSLips, maMethod, Price(basePrice)); // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp { CompName = "Jaws", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = iFirstBar, Value = adJaws }; Component[1] = new IndicatorComp { CompName = "Teeth", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Red, FirstBar = iFirstBar, Value = adTeeth }; Component[2] = new IndicatorComp { CompName = "Lips", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Lime, FirstBar = iFirstBar, Value = adLips }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; Component[4] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; // Sets the Component's type. if (SlotType == SlotTypes.OpenFilter) { Component[3].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is long entry allowed"; Component[4].DataType = IndComponentType.AllowOpenShort; Component[4].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.CloseFilter) { Component[3].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out long position"; Component[4].DataType = IndComponentType.ForceCloseShort; Component[4].CompName = "Close out short position"; } switch (IndParam.ListParam[0].Text) { case "The Jaws rises": IndicatorRisesLogic(iFirstBar, iPrvs, adJaws, ref Component[3], ref Component[4]); break; case "The Jaws falls": IndicatorFallsLogic(iFirstBar, iPrvs, adJaws, ref Component[3], ref Component[4]); break; case "The Teeth rises": IndicatorRisesLogic(iFirstBar, iPrvs, adTeeth, ref Component[3], ref Component[4]); break; case "The Teeth falls": IndicatorFallsLogic(iFirstBar, iPrvs, adTeeth, ref Component[3], ref Component[4]); break; case "The Lips rises": IndicatorRisesLogic(iFirstBar, iPrvs, adLips, ref Component[3], ref Component[4]); break; case "The Lips falls": IndicatorFallsLogic(iFirstBar, iPrvs, adLips, ref Component[3], ref Component[4]); break; case "The Lips crosses the Teeth upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adLips, adTeeth, ref Component[3], ref Component[4]); break; case "The Lips crosses the Teeth downward": IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adLips, adTeeth, ref Component[3], ref Component[4]); break; case "The Lips crosses the Jaws upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adLips, adJaws, ref Component[3], ref Component[4]); break; case "The Lips crosses the Jaws downward": IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adLips, adJaws, ref Component[3], ref Component[4]); break; case "The Teeth crosses the Jaws upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adTeeth, adJaws, ref Component[3], ref Component[4]); break; case "The Teeth crosses the Jaws downward": IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adTeeth, adJaws, ref Component[3], ref Component[4]); break; } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Calculation var adPrevBarOpening = new double[Bars]; const int firstBar = 1; for (int bar = firstBar; bar < Bars; bar++) { adPrevBarOpening[bar] = Open[bar - 1]; } // Saving the components if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close) { Component = new IndicatorComp[1]; } else { Component = new IndicatorComp[3]; Component[1] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[2] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; } Component[0] = new IndicatorComp { DataType = IndComponentType.IndicatorValue, CompName = "Previous Bar Opening", ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = adPrevBarOpening }; // Sets the Component's type if (SlotType == SlotTypes.Open) { Component[0].DataType = IndComponentType.OpenPrice; } else if (SlotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.Close) { Component[0].DataType = IndComponentType.ClosePrice; } else if (SlotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } if (SlotType == SlotTypes.OpenFilter || SlotType == SlotTypes.CloseFilter) { switch (IndParam.ListParam[0].Text) { case "The bar opens below the previous Bar Opening": BarOpensBelowIndicatorLogic(firstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]); break; case "The bar opens above the previous Bar Opening": BarOpensAboveIndicatorLogic(firstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]); break; case "The position opens above the previous Bar Opening": Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower; Component[1].DataType = IndComponentType.Other; Component[2].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].ShowInDynInfo = false; break; case "The position opens below the previous Bar Opening": Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher; Component[1].DataType = IndComponentType.Other; Component[2].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].ShowInDynInfo = false; break; case "The bar closes below the previous Bar Opening": BarClosesBelowIndicatorLogic(firstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]); break; case "The bar closes above the previous Bar Opening": BarClosesAboveIndicatorLogic(firstBar, 0, adPrevBarOpening, ref Component[1], ref Component[2]); break; } } }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod) IndParam.ListParam[1].Index; var price = (BasePrice) IndParam.ListParam[2].Index; var nMA = (int) IndParam.NumParam[0].Value; double dDeviation = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adPrice = Price(price); double[] adMA = MovingAverage(nMA, 0, maMethod, adPrice); var adUpBand = new double[Bars]; var adDnBand = new double[Bars]; int iFirstBar = nMA + iPrvs + 2; for (int iBar = nMA; iBar < Bars; iBar++) { adUpBand[iBar] = adMA[iBar]*(1 + dDeviation/100); adDnBand[iBar] = adMA[iBar]*(1 - dDeviation/100); } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp { CompName = "Upper Band", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = iFirstBar, Value = adUpBand }; Component[1] = new IndicatorComp { CompName = "Moving Average", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Gold, FirstBar = iFirstBar, Value = adMA }; Component[2] = new IndicatorComp { CompName = "Lower Band", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = iFirstBar, Value = adDnBand }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; Component[4] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = iFirstBar, Value = new double[Bars] }; // Sets the Component's type. if (SlotType == SlotTypes.Open) { Component[3].DataType = IndComponentType.OpenLongPrice; Component[3].CompName = "Long position entry price"; Component[4].DataType = IndComponentType.OpenShortPrice; Component[4].CompName = "Short position entry price"; } else if (SlotType == SlotTypes.OpenFilter) { Component[3].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is long entry allowed"; Component[4].DataType = IndComponentType.AllowOpenShort; Component[4].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.Close) { Component[3].DataType = IndComponentType.CloseLongPrice; Component[3].CompName = "Long position closing price"; Component[4].DataType = IndComponentType.CloseShortPrice; Component[4].CompName = "Short position closing price"; } else if (SlotType == SlotTypes.CloseFilter) { Component[3].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out long position"; Component[4].DataType = IndComponentType.ForceCloseShort; Component[4].CompName = "Close out short position"; } if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close) { if (nMA > 1) { for (int iBar = iFirstBar; iBar < Bars; iBar++) { // Covers the cases when the price can pass through the band without a signal. double dOpen = Open[iBar]; // Current open price // Upper band double dValueUp = adUpBand[iBar - iPrvs]; // Current value double dValueUp1 = adUpBand[iBar - iPrvs - 1]; // Previous value double dTempValUp = dValueUp; if ((dValueUp1 > High[iBar - 1] && dValueUp < dOpen) || // The Open price jumps above the indicator (dValueUp1 < Low[iBar - 1] && dValueUp > dOpen) || // The Open price jumps below the indicator (Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Open price is in a positive gap (Close[iBar - 1] > dValueUp && dValueUp > dOpen)) // The Open price is in a negative gap dTempValUp = dOpen; // The entry/exit level is moved to Open price // Lower band double dValueDown = adDnBand[iBar - iPrvs]; // Current value double dValueDown1 = adDnBand[iBar - iPrvs - 1]; // Previous value double dTempValDown = dValueDown; if ((dValueDown1 > High[iBar - 1] && dValueDown < dOpen) || // The Open price jumps above the indicator (dValueDown1 < Low[iBar - 1] && dValueDown > dOpen) || // The Open price jumps below the indicator (Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Open price is in a positive gap (Close[iBar - 1] > dValueDown && dValueDown > dOpen)) // The Open price is in a negative gap dTempValDown = dOpen; // The entry/exit level is moved to Open price if (IndParam.ListParam[0].Text == "Enter long at Upper Band" || IndParam.ListParam[0].Text == "Exit long at Upper Band") { Component[3].Value[iBar] = dTempValUp; Component[4].Value[iBar] = dTempValDown; } else { Component[3].Value[iBar] = dTempValDown; Component[4].Value[iBar] = dTempValUp; } } } else { for (int iBar = 2; iBar < Bars; iBar++) { if (IndParam.ListParam[0].Text == "Enter long at Upper Band" || IndParam.ListParam[0].Text == "Exit long at Upper Band") { Component[3].Value[iBar] = adUpBand[iBar - iPrvs]; Component[4].Value[iBar] = adDnBand[iBar - iPrvs]; } else { Component[3].Value[iBar] = adDnBand[iBar - iPrvs]; Component[4].Value[iBar] = adUpBand[iBar - iPrvs]; } } } } else { switch (IndParam.ListParam[0].Text) { case "The bar opens below Upper Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar opens above Upper Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band); break; case "The bar opens below Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band); break; case "The bar opens above Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band); break; case "The bar opens below Upper Band after opening above it": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it); break; case "The bar opens above Upper Band after opening below it": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it); break; case "The bar opens below Lower Band after opening above it": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it); break; case "The bar opens above Lower Band after opening below it": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it); break; case "The position opens above Upper Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[2].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[0].UsePreviousBar = iPrvs; Component[2].UsePreviousBar = iPrvs; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens below Upper Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[2].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[0].UsePreviousBar = iPrvs; Component[2].UsePreviousBar = iPrvs; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens above Lower Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[0].UsePreviousBar = iPrvs; Component[2].UsePreviousBar = iPrvs; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens below Lower Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[0].UsePreviousBar = iPrvs; Component[2].UsePreviousBar = iPrvs; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The bar closes below Upper Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Upper_Band); break; case "The bar closes above Upper Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; } } }