/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Calculation int iFirstBar = 2; double[] 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(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = adIB; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = adIB; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iEntryHour = (int)IndParam.NumParam[0].Value; int iEntryMinute = (int)IndParam.NumParam[1].Value; TimeSpan tsEntryHour = new TimeSpan(iEntryHour, iEntryMinute, 0); // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { adBars[iBar] = Time[iBar].TimeOfDay == tsEntryHour ? Open[iBar] : 0; } // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp(); Component[0].CompName = "Entry hour"; Component[0].DataType = IndComponentType.OpenPrice; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Calculation int iFirstBar = 2; double[] 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(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = adIB; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = adIB; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Calculation double[] adClosePrice = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) if (Time[iBar - 1].Day != Time[iBar].Day) adClosePrice[iBar - 1] = Close[iBar - 1]; // Check the last bar TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int)Period, 0)); TimeSpan 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(); Component[0].CompName = "Closing price of the day"; Component[0].DataType = IndComponentType.ClosePrice; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = 2; Component[0].Value = adClosePrice; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iFromHour = (int)IndParam.NumParam[0].Value; int iFromMin = (int)IndParam.NumParam[1].Value; int iUntilHour = (int)IndParam.NumParam[2].Value; int iUntilMin = (int)IndParam.NumParam[3].Value; TimeSpan tsFromTime = new TimeSpan(iFromHour, iFromMin, 0); TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0); // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (tsFromTime < tsUntilTime) { adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime && Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0; } else if (tsFromTime > tsUntilTime) { adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime || Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0; } else { adBars[iBar] = 1; } } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Is long entry allowed"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "Is short entry allowed"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters DayOfWeek dowFromDay = (DayOfWeek)IndParam.ListParam[1].Index; DayOfWeek dowUntilDay = (DayOfWeek)IndParam.ListParam[2].Index; // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (dowFromDay < dowUntilDay) { adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay && Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0; } else if (dowFromDay > dowUntilDay) { adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay || Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0; } else { adBars[iBar] = 1; } } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Returns signals for the logic rule "The Indicator is lower than the AnotherIndicator" /// </summary> protected void IndicatorIsLowerThanAnotherIndicatorLogic(int firstBar, int previous, double[] adIndValue, double[] adAnotherIndValue, ref IndicatorComp indCompLong, ref IndicatorComp indCompShort) { double sigma = Sigma(); for (int bar = firstBar; bar < Bars; bar++) { int currentBar = bar - previous; indCompLong.Value[bar] = adIndValue[currentBar] < adAnotherIndValue[currentBar] - sigma ? 1 : 0; indCompShort.Value[bar] = adIndValue[currentBar] > adAnotherIndValue[currentBar] + sigma ? 1 : 0; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iExitHour = (int)IndParam.NumParam[0].Value; TimeSpan tsExitHour = new TimeSpan(iExitHour, 0, 0); // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (Time[iBar - 1].DayOfYear == Time[iBar].DayOfYear && Time[iBar - 1].TimeOfDay < tsExitHour && Time[iBar].TimeOfDay >= tsExitHour) { adBars[iBar - 1] = Close[iBar - 1]; } else if (Time[iBar - 1].DayOfYear != Time[iBar].DayOfYear && Time[iBar - 1].TimeOfDay < tsExitHour) { adBars[iBar - 1] = Close[iBar - 1]; } else { adBars[iBar] = 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(); Component[0].CompName = "Exit hour"; Component[0].DataType = IndComponentType.ClosePrice; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int period = (int)IndParam.NumParam[0].Value; int multipl = (int)IndParam.NumParam[1].Value; int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + 2; double[] 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); double[] 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(); Component[0].CompName = "ATR Stop margin"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].FirstBar = firstBar; Component[0].ShowInDynInfo = false; Component[0].Value = ATRStop; Component[1] = new IndicatorComp(); Component[1].CompName = "ATR Stop for the transferred position"; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[1].FirstBar = firstBar; Component[1].Value = new double[Bars]; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = 0; iBar < Bars - 1; iBar++) { if (Time[iBar].DayOfWeek > DayOfWeek.Wednesday && Time[iBar + 1].DayOfWeek < DayOfWeek.Wednesday) { adBars[iBar] = Close[iBar]; } else { adBars[iBar] = 0; } } // Check the last bar TimeSpan tsBarClosing = Time[Bars - 1].TimeOfDay.Add(new TimeSpan(0, (int)Period, 0)); TimeSpan 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(); Component[0].CompName = "Week Closing"; Component[0].DataType = IndComponentType.ClosePrice; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters // Calculation int iFirstBar = 0; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { adBars[iBar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Allow Open Long"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow Open Short"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Returns signals for the logic rule "The Indicator crosses AnotherIndicator downward" /// </summary> protected void IndicatorCrossesAnotherIndicatorDownwardLogic(int firstBar, int previous, double[] adIndValue, double[] adAnotherIndValue, ref IndicatorComp indCompLong, ref IndicatorComp indCompShort) { double sigma = Sigma(); for (int bar = firstBar; bar < Bars; bar++) { int currentBar = bar - previous; int baseBar = currentBar - 1; while (Math.Abs(adIndValue[baseBar] - adAnotherIndValue[baseBar]) < sigma && baseBar > firstBar) { baseBar--; } indCompLong.Value[bar] = adIndValue[currentBar] < adAnotherIndValue[currentBar] - sigma && adIndValue[baseBar] > adAnotherIndValue[baseBar] + sigma ? 1 : 0; indCompShort.Value[bar] = adIndValue[currentBar] > adAnotherIndValue[currentBar] + sigma && adIndValue[baseBar] < adAnotherIndValue[baseBar] - sigma ? 1 : 0; } return; }
/// <summary> /// Returns a copy /// </summary> public IndicatorComp Clone() { IndicatorComp component = new IndicatorComp(); component.compName = compName; component.dataType = dataType; component.chartType = chartType; component.chartColor = chartColor; component.firstBar = firstBar; component.previous = previous; component.isDynInfo = isDynInfo; component.posPriceDependence = posPriceDependence; if (values != null) { component.values = new double[values.Length]; values.CopyTo(component.values, 0); } return(component); }
/// <summary> /// Returns a copy. /// </summary> 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); }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int period = (int)IndParam.NumParam[0].Value; int multipl = (int)IndParam.NumParam[1].Value; int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + 2; double[] 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); double[] ATRStop = new double[Bars]; double minStop = 5 * Point; 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(); Component[0].CompName = "ATR Stop margin"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].FirstBar = firstBar; Component[0].ShowInDynInfo = false; Component[0].Value = ATRStop; Component[1] = new IndicatorComp(); Component[1].CompName = "ATR Stop for the transferred position"; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[1].FirstBar = firstBar; Component[1].Value = new double[Bars]; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters double dShift = IndParam.NumParam[0].Value * Point; int iDigids = (int)IndParam.NumParam[1].Value; // Calculation double[] adUpperRN = new double[Bars]; double[] adLowerRN = new double[Bars]; int iFirstBar = 1; for (int iBar = 1; iBar < Bars; iBar++) { double dNearestRound; int iCutDigids = Digits - iDigids; if (iCutDigids >= 0) dNearestRound = Math.Round(Open[iBar], iCutDigids); else dNearestRound = Math.Round(Open[iBar] * Math.Pow(10, iCutDigids)) / Math.Pow(10, iCutDigids); if (dNearestRound < Open[iBar]) { adUpperRN[iBar] = dNearestRound + (Point * Math.Pow(10, iDigids)); adLowerRN[iBar] = dNearestRound; } else { adUpperRN[iBar] = dNearestRound; adLowerRN[iBar] = dNearestRound - (Point * Math.Pow(10, iDigids)); } } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Higher round number"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.SpringGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adUpperRN; Component[1] = new IndicatorComp(); Component[1].CompName = "Lower round number"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adLowerRN; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; 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.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; } switch (IndParam.ListParam[0].Text) { case "Enter long at the higher round number": case "Exit long at the higher round number": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[2].Value[iBar] = adUpperRN[iBar] + dShift; Component[3].Value[iBar] = adLowerRN[iBar] - dShift; } break; case "Enter long at the lower round number": case "Exit long at the lower round number": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[2].Value[iBar] = adLowerRN[iBar] - dShift; Component[3].Value[iBar] = adUpperRN[iBar] + dShift; } break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int nPeriod = (int)IndParam.NumParam[0].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = 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); double[] adTrix = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adTrix[iBar] = 100 * (ma3[iBar] - ma3[iBar - 1]) / ma3[iBar - 1]; } double[] adSignal = MovingAverage(nPeriod, 0, maMethod, adTrix); // adHistogram reprezents the Trix Index oscillator double[] adHistogram = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adHistogram[iBar] = adTrix[iBar] - adSignal[iBar]; } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "Histogram"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adHistogram; Component[1] = new IndicatorComp(); Component[1].CompName = "Signal"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Gold; Component[1].FirstBar = iFirstBar; Component[1].Value = adSignal; Component[2] = new IndicatorComp(); Component[2].CompName = "Trix Line"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adTrix; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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 Trix Index line rises": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_rises); break; case "The Trix Index line falls": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_falls); break; case "The Trix Index line is higher than zero": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "The Trix Index line is lower than zero": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; case "The Trix Index line crosses the zero line upward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "The Trix Index line crosses the zero line downward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "The Trix Index line changes its direction upward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_upward); break; case "The Trix Index line changes its direction downward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_downward); break; case "The Trix Index line crosses the Signal line upward": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "The Trix Index line crosses the Signal line downward": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "The Trix Index line is higher than the Signal line": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "The Trix Index line is lower than the Signal line": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iSense = (int)IndParam.NumParam[0].Value; int iFirstBar = iSense; double[] adFibo0; double[] adFibo382; double[] adFibo50; double[] adFibo618; double[] adFibo100; bool bReverseLogic = (IndParam.ListParam[1].Text == "Retracement"); int iDeviation = 5; int iBackStep = 3; double[] adHighPoint = new double[Bars]; double[] adLowPoint = new double[Bars]; adFibo0 = new double[Bars]; adFibo382 = new double[Bars]; adFibo50 = new double[Bars]; adFibo618 = new double[Bars]; adFibo100 = new double[Bars]; double dLastHigh = 0; double dLastLow = 0; for (int iBar = iSense; iBar < Bars; iBar++) { // The highest High in the period [iBar-iSence, iBar] double dHigh = 0; for (int iShift = 0; iShift < iSense; iShift++) if (dHigh < High[iBar - iShift]) dHigh = High[iBar - iShift]; if (dHigh == dLastHigh) dHigh = 0; else { dLastHigh = dHigh; if (dHigh - High[iBar] > iDeviation * Point) dHigh = 0; else for (int iBack = 1; iBack <= iBackStep; iBack++) if (adHighPoint[iBar - iBack] > 0 && adHighPoint[iBar - iBack] < dHigh) adHighPoint[iBar - iBack] = 0; } adHighPoint[iBar] = dHigh; // The lowest Low in the period [iBar-iSence, iBar] double dLow = 10000; for (int iShift = 0; iShift < iSense; iShift++) if (Low[iBar - iShift] < dLow) dLow = Low[iBar - iShift]; if (dLow == dLastLow) dLow = 0; else { dLastLow = dLow; if (Low[iBar] - dLow > iDeviation * Point) dLow = 0; else for (int iBack = 1; iBack <= iBackStep; iBack++) if (adLowPoint[iBar - iBack] > 0 && adLowPoint[iBar - iBack] > dLow) adLowPoint[iBar - iBack] = 0; } adLowPoint[iBar] = dLow; } int iLastHighBar = -1; int iLastLowBar = -1; double dCurHigh; double dCurLow; dLastHigh = -1; dLastLow = -1; for (int iBar = iSense; iBar < Bars; iBar++) { dCurHigh = adHighPoint[iBar]; dCurLow = adLowPoint[iBar]; if (dCurLow == 0 && dCurHigh == 0) continue; if (dCurHigh != 0) { if (dLastHigh > 0) { if (dLastHigh < dCurHigh) adHighPoint[iLastHighBar] = 0; else adHighPoint[iBar] = 0; } if (dLastHigh < dCurHigh || dLastHigh < 0) { dLastHigh = dCurHigh; iLastHighBar = iBar; } dLastLow = -1; } if (dCurLow != 0) { if (dLastLow > 0) { if (dLastLow > dCurLow) adLowPoint[iLastLowBar] = 0; else adLowPoint[iBar] = 0; } if (dCurLow < dLastLow || dLastLow < 0) { dLastLow = dCurLow; iLastLowBar = iBar; } dLastHigh = -1; } } dLastHigh = 0; dLastLow = 0; int iFirstLowBar = 0; int iFirstHighBar = 0; for (int iBar = 0; iBar < Bars; iBar++) { if (adHighPoint[iBar] > 0) { dLastHigh = adHighPoint[iBar]; iFirstHighBar = iBar; } if (adLowPoint[iBar] > 0) { dLastLow = adLowPoint[iBar]; iFirstLowBar = iBar; } if (iFirstHighBar > 0 && iFirstLowBar > 0) break; } for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++) { if (adHighPoint[iBar - 1] > 0) { dLastHigh = adHighPoint[iBar - 1]; adFibo0 [iBar] = dLastHigh; adFibo382[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.382; adFibo50 [iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.500; adFibo618[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.618; adFibo100[iBar] = dLastLow; } else if (adLowPoint[iBar - 1] > 0) { dLastLow = adLowPoint[iBar - 1]; adFibo0 [iBar] = dLastLow; adFibo382[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.382; adFibo50 [iBar] = dLastLow + (dLastHigh - dLastLow) * 0.500; adFibo618[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.618; adFibo100[iBar] = dLastHigh; } else { adFibo0 [iBar] = adFibo0 [iBar - 1]; adFibo382[iBar] = adFibo382[iBar - 1]; adFibo50 [iBar] = adFibo50 [iBar - 1]; adFibo618[iBar] = adFibo618[iBar - 1]; adFibo100[iBar] = adFibo100[iBar - 1]; } } // Saving the components Component = new IndicatorComp[8]; Component[0] = new IndicatorComp(); Component[0].CompName = "Position entry price"; Component[0].DataType = IndComponentType.OpenPrice; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = new double[Bars]; Component[1] = new IndicatorComp(); Component[1].CompName = "Fibonacci retracement 0%"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.Green; Component[1].FirstBar = iFirstBar; Component[1].Value = adFibo0; Component[2] = new IndicatorComp(); Component[2].CompName = "Fibonacci retracement 38.2%"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Level; Component[2].ChartColor = Color.Gold; Component[2].FirstBar = iFirstBar; Component[2].Value = adFibo382; Component[3] = new IndicatorComp(); Component[3].CompName = "Fibonacci retracement 50%"; Component[3].DataType = IndComponentType.IndicatorValue; Component[3].ChartType = IndChartType.Level; Component[3].ChartColor = Color.Orchid; Component[3].FirstBar = iFirstBar; Component[3].Value = adFibo50; Component[4] = new IndicatorComp(); Component[4].CompName = "Fibonacci retracement 61.8%"; Component[4].DataType = IndComponentType.IndicatorValue; Component[4].ChartType = IndChartType.Level; Component[4].ChartColor = Color.Purple; Component[4].FirstBar = iFirstBar; Component[4].Value = adFibo618; Component[5] = new IndicatorComp(); Component[5].CompName = "Fibonacci retracement 100%"; Component[5].DataType = IndComponentType.IndicatorValue; Component[5].ChartType = IndChartType.Level; Component[5].ChartColor = Color.Red; Component[5].FirstBar = iFirstBar; Component[5].Value = adFibo100; Component[6] = new IndicatorComp(); Component[6].CompName = "Is long entry allowed"; Component[6].DataType = IndComponentType.AllowOpenLong; Component[6].ChartType = IndChartType.NoChart; Component[6].FirstBar = iFirstBar; Component[6].Value = new double[Bars]; Component[7] = new IndicatorComp(); Component[7].CompName = "Is short entry allowed"; Component[7].DataType = IndComponentType.AllowOpenShort; Component[7].ChartType = IndChartType.NoChart; Component[7].FirstBar = iFirstBar; Component[7].Value = new double[Bars]; int iBarFibo382Reached = 0; int iBarFibo500Reached = 0; int iBarFibo618Reached = 0; int iBarFibo100Reached = 0; for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++) { Component[0].Value[iBar] = 0; // Reset if (adHighPoint[iBar - 1] > 0 || adLowPoint[iBar - 1] > 0) { iBarFibo382Reached = 0; iBarFibo500Reached = 0; iBarFibo618Reached = 0; iBarFibo100Reached = 0; } // Up trend if (adFibo0[iBar] < adFibo100[iBar]) { if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; Component[0].Value[iBar] = adFibo382[iBar]; iBarFibo382Reached = iBar; } if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo382Reached != iBar) Component[0].Value[iBar] = adFibo50[iBar]; iBarFibo500Reached = iBar; } if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo500Reached != iBar) Component[0].Value[iBar] = adFibo618[iBar]; iBarFibo618Reached = iBar; } if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo618Reached != iBar) Component[0].Value[iBar] = adFibo100[iBar]; iBarFibo100Reached = iBar; } } // Down trend if (adFibo0[iBar] > adFibo100[iBar]) { if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; Component[0].Value[iBar] = adFibo382[iBar]; iBarFibo382Reached = iBar; } if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo382Reached != iBar) Component[0].Value[iBar] = adFibo50[iBar]; iBarFibo500Reached = iBar; } if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo500Reached != iBar) Component[0].Value[iBar] = adFibo618[iBar]; iBarFibo618Reached = iBar; } if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo618Reached != iBar) Component[0].Value[iBar] = adFibo100[iBar]; iBarFibo100Reached = iBar; } } } return; }
/// <summary> /// Returns a copy /// </summary> public IndicatorComp Clone() { IndicatorComp component = new IndicatorComp(); component.compName = compName; component.dataType = dataType; component.chartType = chartType; component.chartColor = chartColor; component.firstBar = firstBar; component.previous = previous; component.isDynInfo = isDynInfo; component.posPriceDependence = posPriceDependence; if (values != null) { component.values = new double[values.Length]; values.CopyTo(component.values, 0); } return component; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice price = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int iShift = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // TimeExecution if (price == BasePrice.Open && iPeriod == 1 && iShift == 0) IndParam.ExecutionTime = ExecutionTime.AtBarOpening; // Calculation double[] adMA = MovingAverage(iPeriod, iShift, maMethod, Price(price)); int iFirstBar = iPeriod + iShift + 1 + iPrvs; // Saving the components if (slotType == SlotTypes.Open || slotType == SlotTypes.Close) { Component = new IndicatorComp[2]; Component[1] = new IndicatorComp(); Component[1].Value = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { // Covers the cases when the price can pass through the MA without a signal double dValue = adMA[iBar - iPrvs]; // Current value double dValue1 = adMA[iBar - iPrvs - 1]; // Previous value double dTempVal = dValue; if ((dValue1 > High[iBar - 1] && dValue < Open[iBar]) || // The Open price jumps above the indicator (dValue1 < Low[iBar - 1] && dValue > Open[iBar]) || // The Open price jumps below the indicator (Close[iBar - 1] < dValue && dValue < Open[iBar]) || // The Open price is in a positive gap (Close[iBar - 1] > dValue && dValue > Open[iBar])) // The Open price is in a negative gap dTempVal = Open[iBar]; Component[1].Value[iBar] = dTempVal; // Entry or exit value } } else { Component = new IndicatorComp[3]; 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]; } Component[0] = new IndicatorComp(); Component[0].CompName = "MA Value"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Red; Component[0].FirstBar = iFirstBar; Component[0].Value = adMA; if (slotType == SlotTypes.Open) { Component[1].CompName = "Position opening price"; Component[1].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[1].CompName = "Position closing price"; Component[1].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 Moving Average rises": IndicatorRisesLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The Moving Average falls": IndicatorFallsLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens above the Moving Average": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens below the Moving Average": BarOpensBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens above the Moving Average after opening below it": BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens below the Moving Average after opening above it": BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The position opens above the Moving Average": Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower; Component[0].UsePreviousBar = iPrvs; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].DataType = IndComponentType.Other; Component[2].ShowInDynInfo = false; break; case "The position opens below the Moving Average": Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher; Component[0].UsePreviousBar = iPrvs; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].DataType = IndComponentType.Other; Component[2].ShowInDynInfo = false; break; case "The bar closes below the Moving Average": BarClosesBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar closes above the Moving Average": BarClosesAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; default: break; } } return; }
/// <summary> /// Calculates the indicator's components. /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice price = (BasePrice)IndParam.ListParam[2].Index; int nMA = (int)IndParam.NumParam[0].Value; double dMpl = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adPrice = Price(price); double[] adMA = MovingAverage(nMA, 0, maMethod, adPrice); double[] adUpBand = new double[Bars]; double[] adDnBand = new double[Bars]; int iFirstBar = nMA + iPrvs + 2; double dSum; double dStdDev; double dDelta; for (int iBar = nMA; iBar < Bars; iBar++) { dSum = 0; for (int i = 0; i < nMA; i++) { dDelta = (adPrice[iBar - i] - adMA[iBar]); dSum += dDelta * dDelta; } dStdDev = Math.Sqrt(dSum / nMA); adUpBand[iBar] = adMA[iBar] + dMpl * dStdDev; adDnBand[iBar] = adMA[iBar] - dMpl * dStdDev; } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "Upper Band"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adUpBand; Component[1] = new IndicatorComp(); Component[1].CompName = "Moving Average"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Gold; Component[1].FirstBar = iFirstBar; Component[1].Value = adMA; Component[2] = new IndicatorComp(); Component[2].CompName = "Lower Band"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adDnBand; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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 the Upper Band" || IndParam.ListParam[0].Text == "Exit long at the 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 the Upper Band" || IndParam.ListParam[0].Text == "Exit long at the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; default: break; } } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int 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; double[] 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(); Component[0].CompName = "Momentum"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adMomentum; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Momentum rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The Momentum falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The Momentum is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Momentum is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Momentum crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Momentum crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Momentum changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The Momentum changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adMomentum, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iNJaws = (int)IndParam.NumParam[0].Value; int iSJaws = (int)IndParam.NumParam[1].Value; int iNTeeth = (int)IndParam.NumParam[2].Value; int iSTeeth = (int)IndParam.NumParam[3].Value; int iNLips = (int)IndParam.NumParam[4].Value; int 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(); Component[0].CompName = "Jaws"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adJaws; Component[1] = new IndicatorComp(); Component[1].CompName = "Teeth"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Red; Component[1].FirstBar = iFirstBar; Component[1].Value = adTeeth; Component[2] = new IndicatorComp(); Component[2].CompName = "Lips"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Lime; Component[2].FirstBar = iFirstBar; Component[2].Value = adLips; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters BasePrice basePrice = (BasePrice)IndParam.ListParam[1].Index; int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adBasePrice = Price(basePrice); double[] adUp = new double[Bars]; double[] adDown = new double[Bars]; double[] adAroon = new double[Bars]; for (int iBar = iPeriod; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iPeriod; i++) { int iBaseBar = iBar - iPeriod + 1 + i; if (adBasePrice[iBaseBar] > dHighestHigh) { dHighestHigh = adBasePrice[iBaseBar]; adUp[iBar] = 100.0 * i / (iPeriod - 1); } if (adBasePrice[iBaseBar] < dLowestLow) { dLowestLow = adBasePrice[iBaseBar]; adDown[iBar] = 100.0 * i / (iPeriod - 1); } } } for (int iBar = iFirstBar; iBar < Bars; iBar++) { adAroon[iBar] = adUp[iBar] - adDown[iBar]; } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "Aroon Histogram"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adAroon; Component[1] = new IndicatorComp(); Component[1].CompName = "Aroon Up"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Green; Component[1].FirstBar = iFirstBar; Component[1].Value = adUp; Component[2] = new IndicatorComp(); Component[2].CompName = "Aroon Down"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Red; Component[2].FirstBar = iFirstBar; Component[2].Value = adDown; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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"; } // Calculation of the logic IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Aroon Histogram rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The Aroon Histogram falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The Aroon Histogram is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Aroon Histogram is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Aroon Histogram crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Aroon Histogram crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The Aroon Histogram changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The Aroon Histogram changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adAroon, dLevel, -dLevel, ref Component[3], ref Component[4], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice price = BasePrice.Close; int nMA = (int)IndParam.NumParam[0].Value; int iATRPeriod = (int)IndParam.NumParam[1].Value; int iATRMultiplier = (int)IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adMA = MovingAverage(nMA, 0, maMethod, Price(price)); double[] adATR = new double[Bars]; double[] adUpBand = new double[Bars]; double[] adDnBand = new double[Bars]; int iFirstBar = (int)Math.Max(nMA, iATRPeriod) + iPrvs + 2; for (int iBar = 1; iBar < Bars; iBar++) { adATR[iBar] = Math.Max(Math.Abs(High[iBar] - Close[iBar - 1]), Math.Abs(Close[iBar - 1] - Low[iBar])); adATR[iBar] = Math.Max(Math.Abs(High[iBar] - Low[iBar]), adATR[iBar]); } adATR = MovingAverage(iATRPeriod, 0, maMethod, adATR); for (int iBar = nMA; iBar < Bars; iBar++) { adUpBand[iBar] = adMA[iBar] + adATR[iBar] * iATRMultiplier; adDnBand[iBar] = adMA[iBar] - adATR[iBar] * iATRMultiplier; } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "Upper Band"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adUpBand; Component[1] = new IndicatorComp(); Component[1].CompName = "Moving Average"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Gold; Component[1].FirstBar = iFirstBar; Component[1].Value = adMA; Component[2] = new IndicatorComp(); Component[2].CompName = "Lower Band"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adDnBand; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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 the Upper Band" || IndParam.ListParam[0].Text == "Exit long at the 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 the Upper Band" || IndParam.ListParam[0].Text == "Exit long at the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the Lower Band": BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; default: break; } } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = iPeriod + iPrvs; // Calculating Money Flow double[] adMF = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { double dAVG = (High[iBar] + Low[iBar] + Close[iBar]) / 3; double dAVG1 = (High[iBar - 1] + Low[iBar - 1] + Close[iBar - 1]) / 3; if (dAVG > dAVG1) { adMF[iBar] = adMF[iBar - 1] + dAVG * Volume[iBar]; } else if (dAVG < dAVG1) { adMF[iBar] = adMF[iBar - 1] - dAVG * Volume[iBar]; } else { adMF[iBar] = adMF[iBar - 1]; } } // Calculating Money Flow Index double[] adMFI = new double[Bars]; for (int iBar = iPeriod + 1; iBar < Bars; iBar++) { double dPMF = 0; double dNMF = 0; for (int index = 0; index < iPeriod; index++) { if (adMF[iBar - index] > adMF[iBar - index - 1]) { dPMF += adMF[iBar - index] - adMF[iBar - index - 1]; } if (adMF[iBar - index] < adMF[iBar - index - 1]) { dNMF += adMF[iBar - index - 1] - adMF[iBar - index]; } } if (dNMF == 0) { adMFI[iBar] = 100.0; } else { adMFI[iBar] = 100.0 - (100.0 / (1.0 + (dPMF / dNMF))); } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Money Flow Index"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adMFI; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The MFI rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 50 }; break; case "The MFI falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 50 }; break; case "The MFI is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 50 }; break; case "The MFI changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 50 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adMFI, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iPeriod = (int)IndParam.NumParam[0].Value; int dLevel = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adOBOS = new double[Bars]; double dMin = double.MaxValue; double dMax = double.MinValue; for (int iBar = iPeriod; iBar < Bars; iBar++) { dMin = double.MaxValue; dMax = double.MinValue; for (int index = 0; index < iPeriod; index++) { if (High[iBar - index] > dMax) { dMax = High[iBar - index]; } if (Low[iBar - index] < dMin) { dMin = Low[iBar - index]; } } adOBOS[iBar] = 100 * (Close[iBar] - dMin) / (dMax - dMin); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "OBOS"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Brown; Component[0].FirstBar = iFirstBar; Component[0].Value = adOBOS; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Overbought Oversold Index rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 50 }; break; case "The Overbought Oversold Index falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 50 }; break; case "The Overbought Oversold Index is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The Overbought Oversold Index is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The Overbought Oversold Index crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The Overbought Oversold Index crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The Overbought Oversold Index changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 50 }; break; case "The Overbought Oversold Index changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 50 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adOBOS, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adHAOpen = new double[Bars]; double[] adHAHigh = new double[Bars]; double[] adHALow = new double[Bars]; double[] adHAClose = new double[Bars]; adHAOpen[0] = Open[0]; adHAHigh[0] = High[0]; adHALow[0] = Low[0]; adHAClose[0] = Close[0]; int iFirstBar = 1 + iPrvs; for (int iBar = 1; iBar < Bars; iBar++) { adHAClose[iBar] = (Open[iBar] + High[iBar] + Low[iBar] + Close[iBar]) / 4; adHAOpen[iBar] = (adHAOpen[iBar - 1] + adHAClose[iBar - 1]) / 2; adHAHigh[iBar] = High[iBar] > adHAOpen[iBar] ? High[iBar] : adHAOpen[iBar]; adHAHigh[iBar] = adHAClose[iBar] > adHAHigh[iBar] ? adHAClose[iBar] : adHAHigh[iBar]; adHALow[iBar] = Low[iBar] < adHAOpen[iBar] ? Low[iBar] : adHAOpen[iBar]; adHALow[iBar] = adHAClose[iBar] < adHALow[iBar] ? adHAClose[iBar] : adHALow[iBar]; } // Saving the components Component = new IndicatorComp[6]; Component[0] = new IndicatorComp(); Component[0].CompName = "H.A. Open"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Dot; Component[0].ChartColor = Color.Green; Component[0].FirstBar = iFirstBar; Component[0].Value = adHAOpen; Component[1] = new IndicatorComp(); Component[1].CompName = "H.A. High"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Dot; Component[1].ChartColor = Color.Blue; Component[1].FirstBar = iFirstBar; Component[1].Value = adHAHigh; Component[2] = new IndicatorComp(); Component[2].CompName = "H.A. Low"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Dot; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adHALow; Component[3] = new IndicatorComp(); Component[3].CompName = "H.A. Close"; Component[3].DataType = IndComponentType.IndicatorValue; Component[3].ChartType = IndChartType.Dot; Component[3].ChartColor = Color.Red; Component[3].FirstBar = iFirstBar; Component[3].Value = adHAClose; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].Value = new double[Bars]; Component[5] = new IndicatorComp(); Component[5].ChartType = IndChartType.NoChart; Component[5].FirstBar = iFirstBar; Component[5].Value = new double[Bars]; // Sets the Component's type if (slotType == SlotTypes.Open) { Component[4].DataType = IndComponentType.OpenLongPrice; Component[4].CompName = "Long position entry price"; Component[5].DataType = IndComponentType.OpenShortPrice; Component[5].CompName = "Short position entry price"; } else if (slotType == SlotTypes.OpenFilter) { Component[4].DataType = IndComponentType.AllowOpenLong; Component[4].CompName = "Is long entry allowed"; Component[5].DataType = IndComponentType.AllowOpenShort; Component[5].CompName = "Is short entry allowed"; } else if (slotType == SlotTypes.Close) { Component[4].DataType = IndComponentType.CloseLongPrice; Component[4].CompName = "Long position closing price"; Component[5].DataType = IndComponentType.CloseShortPrice; Component[5].CompName = "Short position closing price"; } else if (slotType == SlotTypes.CloseFilter) { Component[4].DataType = IndComponentType.ForceCloseLong; Component[4].CompName = "Close out long position"; Component[5].DataType = IndComponentType.ForceCloseShort; Component[5].CompName = "Close out short position"; } if (slotType == SlotTypes.Open || slotType == SlotTypes.Close) { for (int iBar = 2; iBar < Bars; iBar++) { if (IndParam.ListParam[0].Text == "Enter long at the H.A. High" || IndParam.ListParam[0].Text == "Exit long at the H.A. High") { Component[4].Value[iBar] = adHAHigh[iBar - iPrvs]; Component[5].Value[iBar] = adHALow[iBar - iPrvs]; } else { Component[4].Value[iBar] = adHALow[iBar - iPrvs]; Component[5].Value[iBar] = adHAHigh[iBar - iPrvs]; } } } else { switch (IndParam.ListParam[0].Text) { case "White H.A. bar without lower shadow": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[4].Value[iBar] = adHAClose[iBar - iPrvs] > adHAOpen[iBar - iPrvs] && adHALow[iBar - iPrvs] == adHAOpen[iBar - iPrvs] ? 1 : 0; Component[5].Value[iBar] = adHAClose[iBar - iPrvs] < adHAOpen[iBar - iPrvs] && adHAHigh[iBar - iPrvs] == adHAOpen[iBar - iPrvs] ? 1 : 0; } break; case "White H.A. bar": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[4].Value[iBar] = adHAClose[iBar - iPrvs] > adHAOpen[iBar - iPrvs] ? 1 : 0; Component[5].Value[iBar] = adHAClose[iBar - iPrvs] < adHAOpen[iBar - iPrvs] ? 1 : 0; } break; case "Black H.A. bar": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[4].Value[iBar] = adHAClose[iBar - iPrvs] < adHAOpen[iBar - iPrvs] ? 1 : 0; Component[5].Value[iBar] = adHAClose[iBar - iPrvs] > adHAOpen[iBar - iPrvs] ? 1 : 0; } break; case "Black H.A. bar without upper shadow": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[4].Value[iBar] = adHAClose[iBar - iPrvs] < adHAOpen[iBar - iPrvs] && adHAHigh[iBar - iPrvs] == adHAOpen[iBar - iPrvs] ? 1 : 0; Component[5].Value[iBar] = adHAClose[iBar - iPrvs] > adHAOpen[iBar - iPrvs] && adHALow[iBar - iPrvs] == adHAOpen[iBar - iPrvs] ? 1 : 0; } break; default: break; } } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int iK = (int)IndParam.NumParam[0].Value; int iDFast = (int)IndParam.NumParam[1].Value; int iDSlow = (int)IndParam.NumParam[2].Value; int iLevel = (int)IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iK + iDFast + iDSlow + 3; double[] adHighs = new double[Bars]; double[] adLows = new double[Bars]; for (int iBar = 0; iBar < iK; iBar++) { double dMin = double.MaxValue; double dMax = double.MinValue; for (int i = 0; i < iBar; i++) { if (High[iBar - i] > dMax) dMax = High[iBar - i]; if (Low[iBar - i] < dMin) dMin = Low[iBar - i]; } adHighs[iBar] = dMax; adLows[iBar] = dMin; } adHighs[0] = High[0]; adLows[0] = Low[0]; for (int iBar = iK; iBar < Bars; iBar++) { double dMin = double.MaxValue; double dMax = double.MinValue; for (int i = 0; i < iK; i++) { if (High[iBar - i] > dMax) dMax = High[iBar - i]; if (Low[iBar - i] < dMin) dMin = Low[iBar - i]; } adHighs[iBar] = dMax; adLows[iBar] = dMin; } double[] adK = new double[Bars]; for (int iBar = iK; iBar < Bars; iBar++) { if (adHighs[iBar] == adLows[iBar]) adK[iBar] = 50; else adK[iBar] = 100 * (Close[iBar] - adLows[iBar]) / (adHighs[iBar] - adLows[iBar]); } double[] adDFast = new double[Bars]; for (int iBar = iDFast; iBar < Bars; iBar++) { double dSumHigh = 0; double dSumLow = 0; for (int i = 0; i < iDFast; i++) { dSumLow += Close[iBar - i] - adLows[iBar - i]; dSumHigh += adHighs[iBar - i] - adLows[iBar - i]; } if (dSumHigh == 0) adDFast[iBar] = 100; else adDFast[iBar] = 100 * dSumLow / dSumHigh; } double[] adDSlow = MovingAverage(iDSlow, 0, maMethod, adDFast); // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "%K"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Brown; Component[0].FirstBar = iFirstBar; Component[0].Value = adK; Component[1] = new IndicatorComp(); Component[1].CompName = "Fast %D"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Gold; Component[1].FirstBar = iFirstBar; Component[1].Value = adDFast; Component[2] = new IndicatorComp(); Component[2].CompName = "Slow %D"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adDSlow; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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"; } // Calculation of the logic IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; if (IndParam.ListParam[0].Text == "The %K crosses the Slow %D upward") { SpecialValues = new double[1] { 50 }; IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs,adK, adDSlow, ref Component[3], ref Component[4]); return; } else if (IndParam.ListParam[0].Text == "The %K crosses the Slow %D downward") { SpecialValues = new double[1] { 50 }; IndicatorCrossesAnotherIndicatorDownwardLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]); return; } else if (IndParam.ListParam[0].Text == "The %K is higher than the Slow %D") { SpecialValues = new double[1] { 50 }; IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]); return; } else if (IndParam.ListParam[0].Text == "The %K is lower than the Slow %D") { SpecialValues = new double[1] { 50 }; IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, iPrvs, adK, adDSlow, ref Component[3], ref Component[4]); return; } else { switch (IndParam.ListParam[0].Text) { case "The Slow %D rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 50 }; break; case "The Slow %D falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 50 }; break; case "The Slow %D is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Slow %D is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Slow %D crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Slow %D crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Slow %D changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 50 }; break; case "The Slow %D changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 50 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adDSlow, iLevel, 100 - iLevel, ref Component[3], ref Component[4], indLogic); } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = 3; double[] AD = new double[Bars]; AD[0] = (Close[0] - Low[0]) - (High[0] - Close[0]); if ((High[0] - Low[0]) > 0) AD[0] = AD[0] / (High[0] - Low[0]) * Volume[0]; else AD[0] = 0; for (int bar = 1; bar < Bars; bar++) { double delta = 0; double range = High[bar] - Low[bar]; if (range > 0) delta = Volume[bar] * (2 * Close[bar] - High[bar] - Low[bar]) / range; AD[bar] = AD[bar - 1] + delta; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Accumulation Distribution"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = firstBar; Component[0].Value = AD; Component[1] = new IndicatorComp(); Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = firstBar; Component[1].Value = new double[Bars]; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = firstBar; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The AD rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The AD falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The AD changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The AD changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(firstBar, prev, AD, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { int iTenkan = (int)IndParam.NumParam[0].Value; int iKijun = (int)IndParam.NumParam[2].Value; int iSenkou = (int)IndParam.NumParam[4].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; double[] adMedianPrice = Price(BasePrice.Median); int iFirstBar = 1 + iKijun + iSenkou; double[] adTenkanSen = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iTenkan; i++) { if (High[iBar - i] > dHighestHigh) dHighestHigh = High[iBar - i]; if (Low[iBar - i] < dLowestLow) dLowestLow = Low[iBar - i]; } adTenkanSen[iBar] = (dHighestHigh + dLowestLow) / 2; } double[] adKijunSen = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iKijun; i++) { if (High[iBar - i] > dHighestHigh) dHighestHigh = High[iBar - i]; if (Low[iBar - i] < dLowestLow) dLowestLow = Low[iBar - i]; } adKijunSen[iBar] = (dHighestHigh + dLowestLow) / 2; } double[] adChikouSpan = new double[Bars]; for (int iBar = 0; iBar < Bars - iKijun; iBar++) { adChikouSpan[iBar] = Close[iBar + iKijun]; } double[] adSenkouSpanA = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++) { adSenkouSpanA[iBar + iKijun] = (adTenkanSen[iBar] + adKijunSen[iBar]) / 2; } double[] adSenkouSpanB = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iSenkou; i++) { if (High[iBar - i] > dHighestHigh) dHighestHigh = High[iBar - i]; if (Low[iBar - i] < dLowestLow) dLowestLow = Low[iBar - i]; } adSenkouSpanB[iBar + iKijun] = (dHighestHigh + dLowestLow) / 2; } // Saving the components if (slotType == SlotTypes.OpenFilter) Component = new IndicatorComp[7]; else Component = new IndicatorComp[6]; Component[0] = new IndicatorComp(); Component[0].CompName = "Tenkan Sen"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Red; Component[0].FirstBar = iFirstBar; Component[0].Value = adTenkanSen; Component[1] = new IndicatorComp(); Component[1].CompName = "Kijun Sen"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Blue; Component[1].FirstBar = iFirstBar; Component[1].Value = adKijunSen; Component[2] = new IndicatorComp(); Component[2].CompName = "Chikou Span"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Green; Component[2].FirstBar = iFirstBar; Component[2].Value = adChikouSpan; Component[3] = new IndicatorComp(); Component[3].CompName = "Senkou Span A"; Component[3].DataType = IndComponentType.IndicatorValue; Component[3].ChartType = IndChartType.CloudUp; Component[3].ChartColor = Color.SandyBrown; Component[3].FirstBar = iFirstBar; Component[3].Value = adSenkouSpanA; Component[4] = new IndicatorComp(); Component[4].CompName = "Senkou Span B"; Component[4].DataType = IndComponentType.IndicatorValue; Component[4].ChartType = IndChartType.CloudDown; Component[4].ChartColor = Color.Thistle; Component[4].FirstBar = iFirstBar; Component[4].Value = adSenkouSpanB; Component[5] = new IndicatorComp(); Component[5].FirstBar = iFirstBar; Component[5].Value = new double[Bars]; Component[5].DataType = IndComponentType.Other; if (slotType == SlotTypes.OpenFilter) { Component[5].CompName = "Is long entry allowed"; Component[5].DataType = IndComponentType.AllowOpenLong; Component[6] = new IndicatorComp(); Component[6].FirstBar = iFirstBar; Component[6].Value = new double[Bars]; Component[6].CompName = "Is short entry allowed"; Component[6].DataType = IndComponentType.AllowOpenShort; } switch (IndParam.ListParam[0].Text) { case "Enter the market at the Tenkan Sen": Component[5].CompName = "Tenkan Sen entry price"; Component[5].DataType = IndComponentType.OpenPrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs]; } break; case "Enter the market at the Kijun Sen": Component[5].CompName = "Kijun Sen entry price"; Component[5].DataType = IndComponentType.OpenPrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs]; } break; case "Exit the market at the Tenkan Sen": Component[5].CompName = "Tenkan Sen exit price"; Component[5].DataType = IndComponentType.ClosePrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs]; } break; case "Exit the market at the Kijun Sen": Component[5].CompName = "Kijun Sen exit price"; Component[5].DataType = IndComponentType.ClosePrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs]; } break; case "The Tenkan Sen rises": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > adTenkanSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < adTenkanSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0; } break; case "The Kijun Sen rises": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > adKijunSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < adKijunSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0; } break; case "The Tenkan Sen is higher than the Kijun Sen": IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]); break; case "The Tenkan Sen crosses the Kijun Sen upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]); break; case "The bar opens above the Tenkan Sen": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, ref Component[5], ref Component[6]); break; case "The bar opens above the Kijun Sen": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adKijunSen, ref Component[5], ref Component[6]); break; case "The Chikou Span is above the closing price": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] > Close[iBar - iKijun - iPrvs] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] < Close[iBar - iKijun - iPrvs] - Sigma() ? 1 : 0; } break; case "The position opens above the Kumo": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[5].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); Component[6].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); } Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[5].DataType = IndComponentType.Other; Component[5].UsePreviousBar = iPrvs; Component[5].ShowInDynInfo = false; Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[6].DataType = IndComponentType.Other; Component[6].UsePreviousBar = iPrvs; Component[6].ShowInDynInfo = false; break; case "The position opens inside or above the Kumo": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[5].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); Component[6].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); } Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[5].DataType = IndComponentType.Other; Component[5].UsePreviousBar = iPrvs; Component[5].ShowInDynInfo = false; Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[6].DataType = IndComponentType.Other; Component[6].UsePreviousBar = iPrvs; Component[6].ShowInDynInfo = false; break; case "The Tenkan Sen is above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Tenkan Sen is inside or above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Kijun Sen is above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Kijun Sen is inside or above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Senkou Span A is higher than the Senkou Span B": IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]); break; case "The Senkou Span A crosses the Senkou Span B upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]); break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iSense = (int)IndParam.NumParam[0].Value; int iFirstBar = iSense; double[] adFibo0; double[] adFibo382; double[] adFibo50; double[] adFibo618; double[] adFibo100; bool bReverseLogic = (IndParam.ListParam[1].Text == "Retracement"); int iDeviation = 5; int iBackStep = 3; double[] adHighPoint = new double[Bars]; double[] adLowPoint = new double[Bars]; adFibo0 = new double[Bars]; adFibo382 = new double[Bars]; adFibo50 = new double[Bars]; adFibo618 = new double[Bars]; adFibo100 = new double[Bars]; double dLastHigh = 0; double dLastLow = 0; for (int iBar = iSense; iBar < Bars; iBar++) { // The highest High in the period [iBar-iSence, iBar] double dHigh = 0; for (int iShift = 0; iShift < iSense; iShift++) { if (dHigh < High[iBar - iShift]) { dHigh = High[iBar - iShift]; } } if (dHigh == dLastHigh) { dHigh = 0; } else { dLastHigh = dHigh; if (dHigh - High[iBar] > iDeviation * Point) { dHigh = 0; } else { for (int iBack = 1; iBack <= iBackStep; iBack++) { if (adHighPoint[iBar - iBack] > 0 && adHighPoint[iBar - iBack] < dHigh) { adHighPoint[iBar - iBack] = 0; } } } } adHighPoint[iBar] = dHigh; // The lowest Low in the period [iBar-iSence, iBar] double dLow = 10000; for (int iShift = 0; iShift < iSense; iShift++) { if (Low[iBar - iShift] < dLow) { dLow = Low[iBar - iShift]; } } if (dLow == dLastLow) { dLow = 0; } else { dLastLow = dLow; if (Low[iBar] - dLow > iDeviation * Point) { dLow = 0; } else { for (int iBack = 1; iBack <= iBackStep; iBack++) { if (adLowPoint[iBar - iBack] > 0 && adLowPoint[iBar - iBack] > dLow) { adLowPoint[iBar - iBack] = 0; } } } } adLowPoint[iBar] = dLow; } int iLastHighBar = -1; int iLastLowBar = -1; double dCurHigh; double dCurLow; dLastHigh = -1; dLastLow = -1; for (int iBar = iSense; iBar < Bars; iBar++) { dCurHigh = adHighPoint[iBar]; dCurLow = adLowPoint[iBar]; if (dCurLow == 0 && dCurHigh == 0) { continue; } if (dCurHigh != 0) { if (dLastHigh > 0) { if (dLastHigh < dCurHigh) { adHighPoint[iLastHighBar] = 0; } else { adHighPoint[iBar] = 0; } } if (dLastHigh < dCurHigh || dLastHigh < 0) { dLastHigh = dCurHigh; iLastHighBar = iBar; } dLastLow = -1; } if (dCurLow != 0) { if (dLastLow > 0) { if (dLastLow > dCurLow) { adLowPoint[iLastLowBar] = 0; } else { adLowPoint[iBar] = 0; } } if (dCurLow < dLastLow || dLastLow < 0) { dLastLow = dCurLow; iLastLowBar = iBar; } dLastHigh = -1; } } dLastHigh = 0; dLastLow = 0; int iFirstLowBar = 0; int iFirstHighBar = 0; for (int iBar = 0; iBar < Bars; iBar++) { if (adHighPoint[iBar] > 0) { dLastHigh = adHighPoint[iBar]; iFirstHighBar = iBar; } if (adLowPoint[iBar] > 0) { dLastLow = adLowPoint[iBar]; iFirstLowBar = iBar; } if (iFirstHighBar > 0 && iFirstLowBar > 0) { break; } } for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++) { if (adHighPoint[iBar - 1] > 0) { dLastHigh = adHighPoint[iBar - 1]; adFibo0 [iBar] = dLastHigh; adFibo382[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.382; adFibo50 [iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.500; adFibo618[iBar] = dLastHigh - (dLastHigh - dLastLow) * 0.618; adFibo100[iBar] = dLastLow; } else if (adLowPoint[iBar - 1] > 0) { dLastLow = adLowPoint[iBar - 1]; adFibo0 [iBar] = dLastLow; adFibo382[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.382; adFibo50 [iBar] = dLastLow + (dLastHigh - dLastLow) * 0.500; adFibo618[iBar] = dLastLow + (dLastHigh - dLastLow) * 0.618; adFibo100[iBar] = dLastHigh; } else { adFibo0 [iBar] = adFibo0 [iBar - 1]; adFibo382[iBar] = adFibo382[iBar - 1]; adFibo50 [iBar] = adFibo50 [iBar - 1]; adFibo618[iBar] = adFibo618[iBar - 1]; adFibo100[iBar] = adFibo100[iBar - 1]; } } // Saving the components Component = new IndicatorComp[8]; Component[0] = new IndicatorComp(); Component[0].CompName = "Position entry price"; Component[0].DataType = IndComponentType.OpenPrice; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = new double[Bars]; Component[1] = new IndicatorComp(); Component[1].CompName = "Fibonacci retracement 0%"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.Green; Component[1].FirstBar = iFirstBar; Component[1].Value = adFibo0; Component[2] = new IndicatorComp(); Component[2].CompName = "Fibonacci retracement 38.2%"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Level; Component[2].ChartColor = Color.Gold; Component[2].FirstBar = iFirstBar; Component[2].Value = adFibo382; Component[3] = new IndicatorComp(); Component[3].CompName = "Fibonacci retracement 50%"; Component[3].DataType = IndComponentType.IndicatorValue; Component[3].ChartType = IndChartType.Level; Component[3].ChartColor = Color.Orchid; Component[3].FirstBar = iFirstBar; Component[3].Value = adFibo50; Component[4] = new IndicatorComp(); Component[4].CompName = "Fibonacci retracement 61.8%"; Component[4].DataType = IndComponentType.IndicatorValue; Component[4].ChartType = IndChartType.Level; Component[4].ChartColor = Color.Purple; Component[4].FirstBar = iFirstBar; Component[4].Value = adFibo618; Component[5] = new IndicatorComp(); Component[5].CompName = "Fibonacci retracement 100%"; Component[5].DataType = IndComponentType.IndicatorValue; Component[5].ChartType = IndChartType.Level; Component[5].ChartColor = Color.Red; Component[5].FirstBar = iFirstBar; Component[5].Value = adFibo100; Component[6] = new IndicatorComp(); Component[6].CompName = "Is long entry allowed"; Component[6].DataType = IndComponentType.AllowOpenLong; Component[6].ChartType = IndChartType.NoChart; Component[6].FirstBar = iFirstBar; Component[6].Value = new double[Bars]; Component[7] = new IndicatorComp(); Component[7].CompName = "Is short entry allowed"; Component[7].DataType = IndComponentType.AllowOpenShort; Component[7].ChartType = IndChartType.NoChart; Component[7].FirstBar = iFirstBar; Component[7].Value = new double[Bars]; int iBarFibo382Reached = 0; int iBarFibo500Reached = 0; int iBarFibo618Reached = 0; int iBarFibo100Reached = 0; for (int iBar = Math.Max(iFirstLowBar, iFirstHighBar); iBar < Bars; iBar++) { Component[0].Value[iBar] = 0; // Reset if (adHighPoint[iBar - 1] > 0 || adLowPoint[iBar - 1] > 0) { iBarFibo382Reached = 0; iBarFibo500Reached = 0; iBarFibo618Reached = 0; iBarFibo100Reached = 0; } // Up trend if (adFibo0[iBar] < adFibo100[iBar]) { if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; Component[0].Value[iBar] = adFibo382[iBar]; iBarFibo382Reached = iBar; } if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo382Reached != iBar) { Component[0].Value[iBar] = adFibo50[iBar]; } iBarFibo500Reached = iBar; } if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo500Reached != iBar) { Component[0].Value[iBar] = adFibo618[iBar]; } iBarFibo618Reached = iBar; } if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 0 : 1; Component[7].Value[iBar] = bReverseLogic ? 1 : 0; if (iBarFibo618Reached != iBar) { Component[0].Value[iBar] = adFibo100[iBar]; } iBarFibo100Reached = iBar; } } // Down trend if (adFibo0[iBar] > adFibo100[iBar]) { if (iBarFibo382Reached == 0 && Low[iBar] <= adFibo382[iBar] && High[iBar] >= adFibo382[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; Component[0].Value[iBar] = adFibo382[iBar]; iBarFibo382Reached = iBar; } if (iBarFibo500Reached == 0 && Low[iBar] <= adFibo50[iBar] && High[iBar] >= adFibo50[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo382Reached != iBar) { Component[0].Value[iBar] = adFibo50[iBar]; } iBarFibo500Reached = iBar; } if (iBarFibo618Reached == 0 && Low[iBar] <= adFibo618[iBar] && High[iBar] >= adFibo618[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo500Reached != iBar) { Component[0].Value[iBar] = adFibo618[iBar]; } iBarFibo618Reached = iBar; } if (iBarFibo100Reached == 0 && Low[iBar] <= adFibo100[iBar] && High[iBar] >= adFibo100[iBar]) { Component[6].Value[iBar] = bReverseLogic ? 1 : 0; Component[7].Value[iBar] = bReverseLogic ? 0 : 1; if (iBarFibo618Reached != iBar) { Component[0].Value[iBar] = adFibo100[iBar]; } iBarFibo100Reached = iBar; } } } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adMA = MovingAverage(iPeriod, 0, maMethod, Price(BasePrice.Close)); double[] adBulls = new double[Bars]; double[] adBears = new double[Bars]; double[] adBBP = new double[Bars]; for (int iBar = iPeriod; iBar < Bars; iBar++) { adBulls[iBar] = High[iBar] - adMA[iBar]; adBears[iBar] = Low[iBar] - adMA[iBar]; adBBP[iBar] = adBulls[iBar] + adBears[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Bulls Bears Power"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.RoyalBlue; Component[0].FirstBar = iFirstBar; Component[0].Value = adBBP; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The BBP rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The BBP falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The BBP is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The BBP is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The BBP crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The BBP crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The BBP changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The BBP changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adBBP, dLevel, -dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iFromHour = (int)IndParam.NumParam[0].Value; int iFromMin = (int)IndParam.NumParam[1].Value; int iUntilHour = (int)IndParam.NumParam[2].Value; int iUntilMin = (int)IndParam.NumParam[3].Value; TimeSpan tsFromTime = new TimeSpan(iFromHour, iFromMin, 0); TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0); // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if(tsFromTime < tsUntilTime) adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime && Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0; else if(tsFromTime > tsUntilTime) adBars[iBar] = Time[iBar].TimeOfDay >= tsFromTime || Time[iBar].TimeOfDay < tsUntilTime ? 1 : 0; else adBars[iBar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Is long entry allowed"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "Is short entry allowed"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; double dMultiplier = IndParam.NumParam[2].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 3; double[] adBasePrice = Price(basePrice); double[] adSMABasePrice = MovingAverage(iPeriod, 0, MAMethod.Simple, adBasePrice); double dSum; double[] adMeanDev = new double[Bars]; for (int iBar = iPeriod; iBar < Bars; iBar++) { dSum = 0; for (int i = 0; i < iPeriod; i++) { dSum += Math.Abs(adBasePrice[iBar - i] - adSMABasePrice[iBar]); } adMeanDev[iBar] = dMultiplier * dSum / iPeriod; } double[] adCCI = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adMeanDev[iBar] != 0) adCCI[iBar] = (adBasePrice[iBar] - adSMABasePrice[iBar]) / adMeanDev[iBar]; else adCCI[iBar] = 0; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "CCI"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.RoyalBlue; Component[0].FirstBar = iFirstBar; Component[0].Value = adCCI; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The CCI rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[3] { -100, 0, 100 }; break; case "The CCI falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[3] { -100, 0, 100 }; break; case "The CCI is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[3] { dLevel, 0, - dLevel }; break; case "The CCI is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[3] { dLevel, 0, -dLevel }; break; case "The CCI crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[3] { dLevel, 0, -dLevel }; break; case "The CCI crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[3] { dLevel, 0, -dLevel }; break; case "The CCI changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[3] { -100, 0, 100 }; break; case "The CCI changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[3] { -100, 0, 100 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adCCI, dLevel, - dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; BasePrice price = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adPrice = Price(price); double[] adMA = MovingAverage(iPeriod, 0, maMethod, adPrice); double[] adSTDV = new double[Bars]; int iFirstBar = iPeriod + 1; for (int iBar = iPeriod; iBar < Bars; iBar++) { double dSum = 0; for (int index = 0; index < iPeriod; index++) { double fDelta = (adPrice[iBar - index] - adMA[iBar]); dSum += fDelta * fDelta; } adSTDV[iBar] = Math.Sqrt(dSum / iPeriod); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Standard Deviation"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adSTDV; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Standard Deviation rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Standard Deviation falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Standard Deviation is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; case "The Standard Deviation is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; case "The Standard Deviation crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[1] { dLevel }; break; case "The Standard Deviation crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[1] { dLevel }; break; case "The Standard Deviation changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Standard Deviation changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } NoDirectionOscillatorLogic(iFirstBar, iPrvs, adSTDV, dLevel, ref Component[1], indLogic); Component[2].Value = Component[1].Value; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int period = (int)IndParam.NumParam[0].Value; int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = period + 2; double[] DIPos = new double[Bars]; double[] DINeg = new double[Bars]; for (int bar = 1; bar < Bars; bar++) { double trueRange = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]); if (trueRange < Point) { trueRange = Point; } double deltaHigh = High[bar] - High[bar - 1]; double deltaLow = Low[bar - 1] - Low[bar]; if (deltaHigh > 0 && deltaHigh > deltaLow) { DIPos[bar] = 100 * deltaHigh / trueRange; } else { DIPos[bar] = 0; } if (deltaLow > 0 && deltaLow > deltaHigh) { DINeg[bar] = 100 * deltaLow / trueRange; } else { DINeg[bar] = 0; } } double[] ADIPos = MovingAverage(period, 0, maMethod, DIPos); double[] ADINeg = MovingAverage(period, 0, maMethod, DINeg); double[] ADIOsc = new double[Bars]; for (int bar = 0; bar < Bars; bar++) { ADIOsc[bar] = ADIPos[bar] - ADINeg[bar]; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "The ADI+"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Green; Component[0].FirstBar = firstBar; Component[0].Value = ADIPos; Component[1] = new IndicatorComp(); Component[1].CompName = "The ADI-"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Red; Component[1].FirstBar = firstBar; Component[1].Value = ADINeg; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = firstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = firstBar; Component[3].Value = new double[Bars]; // Sets the Component's type if (slotType == SlotTypes.OpenFilter) { Component[2].DataType = IndComponentType.AllowOpenLong; Component[2].CompName = "Is long entry allowed"; Component[3].DataType = IndComponentType.AllowOpenShort; Component[3].CompName = "Is short entry allowed"; } else if (slotType == SlotTypes.CloseFilter) { Component[2].DataType = IndComponentType.ForceCloseLong; Component[2].CompName = "Close out long position"; Component[3].DataType = IndComponentType.ForceCloseShort; Component[3].CompName = "Close out short position"; } switch (IndParam.ListParam[0].Text) { case "The ADI+ rises": OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises); break; case "The ADI+ falls": OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls); break; case "The ADI- rises": OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_rises); break; case "The ADI- falls": OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_falls); break; case "The ADI+ is higher than ADI-": OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "The ADI+ is lower than ADI-": OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; case "The ADI+ crosses the ADI- line upward": OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "The ADI+ crosses the ADI- line downward": OscillatorLogic(firstBar, prev, ADIOsc, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "The ADI+ changes its direction upward": OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward); break; case "The ADI+ changes its direction downward": OscillatorLogic(firstBar, prev, ADIPos, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward); break; case "The ADI- changes its direction upward": OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_upward); break; case "The ADI- changes its direction downward": OscillatorLogic(firstBar, prev, ADINeg, 0, 0, ref Component[2], ref Component[3], IndicatorLogic.The_indicator_changes_its_direction_downward); break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters BasePrice basePrice = (BasePrice)IndParam.ListParam[1].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adPrice = Price(basePrice); double[] adValue = new double[Bars]; for (int iBar = 0; iBar < iPeriod; iBar++) { adValue[iBar] = 0; } for (int iBar = iPeriod; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iPeriod; i++) { if (adPrice[iBar - i] > dHighestHigh) { dHighestHigh = adPrice[iBar - i]; } if (adPrice[iBar - i] < dLowestLow) { dLowestLow = adPrice[iBar - i]; } } if (dHighestHigh == dLowestLow) { dHighestHigh = dLowestLow + Point; } if (dHighestHigh - dLowestLow == 0.5) { dHighestHigh += Point; } adValue[iBar] = 0.33 * 2 * ((adPrice[iBar] - dLowestLow) / (dHighestHigh - dLowestLow) - 0.5) + 0.67 * adValue[iBar - 1]; } double[] adFT = new double[Bars]; adFT[0] = 0; for (int iBar = 1; iBar < Bars; iBar++) { adFT[iBar] = 0.5 * (double)Math.Log10((1 + adValue[iBar]) / (1 - adValue[iBar])) + 0.5 * adFT[iBar - 1]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Fisher Transform"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adFT; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Fisher Transform rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Fisher Transform falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Fisher Transform is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Fisher Transform is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "The Fisher Transform crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Fisher Transform crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Fisher Transform changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Fisher Transform changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adFT, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int iPeriod1 = (int)IndParam.NumParam[0].Value; int iPeriod2 = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod1 + iPeriod2 + 2; double[] adIndicator1 = new double[Bars]; double[] adIndicator2 = new double[Bars]; double[] adOscllator = new double[Bars]; // --------------------------------------------------------- Average_True_Range ATR1 = new Average_True_Range(slotType); ATR1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; ATR1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; ATR1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; ATR1.Calculate(slotType); Average_True_Range ATR2 = new Average_True_Range(slotType); ATR2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; ATR2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; ATR2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; ATR2.Calculate(slotType); adIndicator1 = ATR1.Component[0].Value; adIndicator2 = ATR2.Component[0].Value; // ---------------------------------------------------------- for (int iBar = iFirstBar; iBar < Bars; iBar++) { adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Histogram"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adOscllator; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "The Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } NoDirectionOscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, ref Component[1], indLogic); Component[2].Value = Component[1].Value; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Calculation double[] adPrevBarClosing = new double[Bars]; int iFirstBar = 1; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adPrevBarClosing[iBar] = Close[iBar - 1]; } // Saving the components if (slotType == SlotTypes.Open || slotType == SlotTypes.Close) { Component = new IndicatorComp[1]; } else { Component = new IndicatorComp[3]; 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]; } Component[0] = new IndicatorComp(); Component[0].DataType = IndComponentType.IndicatorValue; Component[0].CompName = "Previous Bar Closing"; Component[0].ChartType = IndChartType.NoChart; Component[0].FirstBar = iFirstBar; Component[0].Value = adPrevBarClosing; // 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 Closing": BarOpensBelowIndicatorLogic(iFirstBar, 0, adPrevBarClosing, ref Component[1], ref Component[2]); break; case "The bar opens above the previous Bar Closing": BarOpensAboveIndicatorLogic(iFirstBar, 0, adPrevBarClosing, ref Component[1], ref Component[2]); break; case "The position opens above the previous Bar Closing": 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 Closing": 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 Closing": BarClosesBelowIndicatorLogic(iFirstBar, 0, adPrevBarClosing, ref Component[1], ref Component[2]); break; case "The bar closes above the previous Bar Closing": BarClosesAboveIndicatorLogic(iFirstBar, 0, adPrevBarClosing, ref Component[1], ref Component[2]); break; default: break; } } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { int iTenkan = (int)IndParam.NumParam[0].Value; int iKijun = (int)IndParam.NumParam[2].Value; int iSenkou = (int)IndParam.NumParam[4].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; double[] adMedianPrice = Price(BasePrice.Median); int iFirstBar = 1 + iKijun + iSenkou; double[] adTenkanSen = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iTenkan; i++) { if (High[iBar - i] > dHighestHigh) { dHighestHigh = High[iBar - i]; } if (Low[iBar - i] < dLowestLow) { dLowestLow = Low[iBar - i]; } } adTenkanSen[iBar] = (dHighestHigh + dLowestLow) / 2; } double[] adKijunSen = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iKijun; i++) { if (High[iBar - i] > dHighestHigh) { dHighestHigh = High[iBar - i]; } if (Low[iBar - i] < dLowestLow) { dLowestLow = Low[iBar - i]; } } adKijunSen[iBar] = (dHighestHigh + dLowestLow) / 2; } double[] adChikouSpan = new double[Bars]; for (int iBar = 0; iBar < Bars - iKijun; iBar++) { adChikouSpan[iBar] = Close[iBar + iKijun]; } double[] adSenkouSpanA = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++) { adSenkouSpanA[iBar + iKijun] = (adTenkanSen[iBar] + adKijunSen[iBar]) / 2; } double[] adSenkouSpanB = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++) { double dHighestHigh = double.MinValue; double dLowestLow = double.MaxValue; for (int i = 0; i < iSenkou; i++) { if (High[iBar - i] > dHighestHigh) { dHighestHigh = High[iBar - i]; } if (Low[iBar - i] < dLowestLow) { dLowestLow = Low[iBar - i]; } } adSenkouSpanB[iBar + iKijun] = (dHighestHigh + dLowestLow) / 2; } // Saving the components if (slotType == SlotTypes.OpenFilter) { Component = new IndicatorComp[7]; } else { Component = new IndicatorComp[6]; } Component[0] = new IndicatorComp(); Component[0].CompName = "Tenkan Sen"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Red; Component[0].FirstBar = iFirstBar; Component[0].Value = adTenkanSen; Component[1] = new IndicatorComp(); Component[1].CompName = "Kijun Sen"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Blue; Component[1].FirstBar = iFirstBar; Component[1].Value = adKijunSen; Component[2] = new IndicatorComp(); Component[2].CompName = "Chikou Span"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Green; Component[2].FirstBar = iFirstBar; Component[2].Value = adChikouSpan; Component[3] = new IndicatorComp(); Component[3].CompName = "Senkou Span A"; Component[3].DataType = IndComponentType.IndicatorValue; Component[3].ChartType = IndChartType.CloudUp; Component[3].ChartColor = Color.SandyBrown; Component[3].FirstBar = iFirstBar; Component[3].Value = adSenkouSpanA; Component[4] = new IndicatorComp(); Component[4].CompName = "Senkou Span B"; Component[4].DataType = IndComponentType.IndicatorValue; Component[4].ChartType = IndChartType.CloudDown; Component[4].ChartColor = Color.Thistle; Component[4].FirstBar = iFirstBar; Component[4].Value = adSenkouSpanB; Component[5] = new IndicatorComp(); Component[5].FirstBar = iFirstBar; Component[5].Value = new double[Bars]; Component[5].DataType = IndComponentType.Other; if (slotType == SlotTypes.OpenFilter) { Component[5].CompName = "Is long entry allowed"; Component[5].DataType = IndComponentType.AllowOpenLong; Component[6] = new IndicatorComp(); Component[6].FirstBar = iFirstBar; Component[6].Value = new double[Bars]; Component[6].CompName = "Is short entry allowed"; Component[6].DataType = IndComponentType.AllowOpenShort; } switch (IndParam.ListParam[0].Text) { case "Enter the market at the Tenkan Sen": Component[5].CompName = "Tenkan Sen entry price"; Component[5].DataType = IndComponentType.OpenPrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs]; } break; case "Enter the market at the Kijun Sen": Component[5].CompName = "Kijun Sen entry price"; Component[5].DataType = IndComponentType.OpenPrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs]; } break; case "Exit the market at the Tenkan Sen": Component[5].CompName = "Tenkan Sen exit price"; Component[5].DataType = IndComponentType.ClosePrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs]; } break; case "Exit the market at the Kijun Sen": Component[5].CompName = "Kijun Sen exit price"; Component[5].DataType = IndComponentType.ClosePrice; Component[5].ChartType = IndChartType.NoChart; for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs]; } break; case "The Tenkan Sen rises": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > adTenkanSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < adTenkanSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0; } break; case "The Kijun Sen rises": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > adKijunSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < adKijunSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0; } break; case "The Tenkan Sen is higher than the Kijun Sen": IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]); break; case "The Tenkan Sen crosses the Kijun Sen upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]); break; case "The bar opens above the Tenkan Sen": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, ref Component[5], ref Component[6]); break; case "The bar opens above the Kijun Sen": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adKijunSen, ref Component[5], ref Component[6]); break; case "The Chikou Span is above the closing price": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] > Close[iBar - iKijun - iPrvs] + Sigma() ? 1 : 0; Component[6].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] < Close[iBar - iKijun - iPrvs] - Sigma() ? 1 : 0; } break; case "The position opens above the Kumo": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[5].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); Component[6].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); } Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[5].DataType = IndComponentType.Other; Component[5].UsePreviousBar = iPrvs; Component[5].ShowInDynInfo = false; Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[6].DataType = IndComponentType.Other; Component[6].UsePreviousBar = iPrvs; Component[6].ShowInDynInfo = false; break; case "The position opens inside or above the Kumo": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[5].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); Component[6].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]); } Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[5].DataType = IndComponentType.Other; Component[5].UsePreviousBar = iPrvs; Component[5].ShowInDynInfo = false; Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[6].DataType = IndComponentType.Other; Component[6].UsePreviousBar = iPrvs; Component[6].ShowInDynInfo = false; break; case "The Tenkan Sen is above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Tenkan Sen is inside or above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Kijun Sen is above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Kijun Sen is inside or above the Kumo": for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++) { Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0; Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0; } break; case "The Senkou Span A is higher than the Senkou Span B": IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]); break; case "The Senkou Span A crosses the Senkou Span B upward": IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]); break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iPeriod = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = iPeriod + iPrvs; // Calculating Money Flow double[] adMF = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { double dAVG = (High[iBar] + Low[iBar] + Close[iBar]) / 3; double dAVG1 = (High[iBar - 1] + Low[iBar - 1] + Close[iBar - 1]) / 3; if (dAVG > dAVG1) adMF[iBar] = adMF[iBar - 1] + dAVG * Volume[iBar]; else if (dAVG < dAVG1) adMF[iBar] = adMF[iBar - 1] - dAVG * Volume[iBar]; else adMF[iBar] = adMF[iBar - 1]; } // Calculating Money Flow Index double[] adMFI = new double[Bars]; for (int iBar = iPeriod + 1; iBar < Bars; iBar++) { double dPMF = 0; double dNMF = 0; for (int index = 0; index < iPeriod; index++) { if (adMF[iBar - index] > adMF[iBar - index - 1]) dPMF += adMF[iBar - index] - adMF[iBar - index - 1]; if (adMF[iBar - index] < adMF[iBar - index - 1]) dNMF += adMF[iBar - index - 1] - adMF[iBar - index]; } if (dNMF == 0) adMFI[iBar] = 100.0; else adMFI[iBar] = 100.0 - (100.0 / (1.0 + (dPMF / dNMF))); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Money Flow Index"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adMFI; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The MFI rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 50 }; break; case "The MFI falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 50 }; break; case "The MFI is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, 100 - dLevel }; break; case "The MFI changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 50 }; break; case "The MFI changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 50 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adMFI, dLevel, 100 - dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters bool bIsVisible = IndParam.ListParam[1].Text == "The fractal is visible"; double dShift = (double)IndParam.NumParam[0].Value * Point; int iFirstBar = 8; double[] adFrUp = new double[Bars]; double[] adFrDn = new double[Bars]; for (int iBar = 8; iBar < Bars - 1; iBar++) { if (High[iBar - 1] < High[iBar - 2] && High[iBar] < High[iBar - 2]) { // Fractal type 1 if (High[iBar - 4] < High[iBar - 2] && High[iBar - 3] < High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } // Fractal type 2 if (High[iBar - 5] < High[iBar - 2] && High[iBar - 4] < High[iBar - 2] && High[iBar - 3] == High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } // Fractal type 3, 4 if (High[iBar - 6] < High[iBar - 2] && High[iBar - 5] < High[iBar - 2] && High[iBar - 4] == High[iBar - 2] && High[iBar - 3] <= High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } // Fractal type 5 if (High[iBar - 7] < High[iBar - 2] && High[iBar - 6] < High[iBar - 2] && High[iBar - 5] == High[iBar - 2] && High[iBar - 4] < High[iBar - 2] && High[iBar - 3] == High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } // Fractal type 6 if (High[iBar - 7] < High[iBar - 2] && High[iBar - 6] < High[iBar - 2] && High[iBar - 5] == High[iBar - 2] && High[iBar - 4] == High[iBar - 2] && High[iBar - 3] < High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } // Fractal type 7 if (High[iBar - 8] < High[iBar - 2] && High[iBar - 7] < High[iBar - 2] && High[iBar - 6] == High[iBar - 2] && High[iBar - 5] < High[iBar - 2] && High[iBar - 4] == High[iBar - 2] && High[iBar - 3] < High[iBar - 2]) { adFrUp[iBar + 1] = High[iBar - 2]; } } if (Low[iBar - 1] > Low[iBar - 2] && Low[iBar] > Low[iBar - 2]) { // Fractal type 1 if (Low[iBar - 4] > Low[iBar - 2] && Low[iBar - 3] > Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } // Fractal type 2 if (Low[iBar - 5] > Low[iBar - 2] && Low[iBar - 4] > Low[iBar - 2] && Low[iBar - 3] == Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } // Fractal type 3, 4 if (Low[iBar - 6] > Low[iBar - 2] && Low[iBar - 5] > Low[iBar - 2] && Low[iBar - 4] == Low[iBar - 2] && Low[iBar - 3] >= Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } // Fractal type 5 if (Low[iBar - 7] > Low[iBar - 2] && Low[iBar - 6] > Low[iBar - 2] && Low[iBar - 5] == Low[iBar - 2] && Low[iBar - 4] > Low[iBar - 2] && Low[iBar - 3] == Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } // Fractal type 6 if (Low[iBar - 7] > Low[iBar - 2] && Low[iBar - 6] > Low[iBar - 2] && Low[iBar - 5] == Low[iBar - 2] && Low[iBar - 4] == Low[iBar - 2] && Low[iBar - 3] > Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } // Fractal type 7 if (Low[iBar - 8] > Low[iBar - 2] && Low[iBar - 7] > Low[iBar - 2] && Low[iBar - 6] == Low[iBar - 2] && Low[iBar - 5] > Low[iBar - 2] && Low[iBar - 4] == Low[iBar - 2] && Low[iBar - 3] > Low[iBar - 2]) { adFrDn[iBar + 1] = Low[iBar - 2]; } } } // Is visible if (bIsVisible) { for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adFrUp[iBar - 1] > 0 && adFrUp[iBar] == 0 && High[iBar - 1] < adFrUp[iBar - 1]) { adFrUp[iBar] = adFrUp[iBar - 1]; } if (adFrDn[iBar - 1] > 0 && adFrDn[iBar] == 0 && Low[iBar - 1] > adFrDn[iBar - 1]) { adFrDn[iBar] = adFrDn[iBar - 1]; } } } else { for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adFrUp[iBar] == 0) { adFrUp[iBar] = adFrUp[iBar - 1]; } if (adFrDn[iBar] == 0) { adFrDn[iBar] = adFrDn[iBar - 1]; } } } double[] adFrUpEntry = new double[Bars]; double[] adFrDnEntry = new double[Bars]; // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Up Fractal"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.SpringGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adFrUp; Component[1] = new IndicatorComp(); Component[1].CompName = "Down Fractal"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adFrDn; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; 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.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; } switch (IndParam.ListParam[0].Text) { case "Enter long at an Up Fractal": case "Exit long at an Up Fractal": for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adFrUp[iBar] > Point) { Component[2].Value[iBar] = adFrUp[iBar] + dShift; } if (adFrDn[iBar] > Point) { Component[3].Value[iBar] = adFrDn[iBar] - dShift; } } break; case "Enter long at a Down Fractal": case "Exit long at a Down Fractal": for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adFrDn[iBar] > Point) { Component[2].Value[iBar] = adFrDn[iBar] - dShift; } if (adFrUp[iBar] > Point) { Component[3].Value[iBar] = adFrUp[iBar] + dShift; } } break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int 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; double[] adROC = new double[Bars]; double[] adBasePrice = Price(basePrice); for (int iBar = iPeriod; iBar < Bars; iBar++) adROC[iBar] = adBasePrice[iBar] / adBasePrice[iBar - iPeriod]; if (iSmooth > 0) { adROC = MovingAverage(iSmooth, 0, maMethod, adROC); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "ROC"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Violet; Component[0].FirstBar = iFirstBar; Component[0].Value = adROC; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The ROC rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 1 }; break; case "The ROC falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 1 }; break; case "The ROC is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, 2 - dLevel }; break; case "The ROC is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, 2 - dLevel }; break; case "The ROC crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, 2 - dLevel }; break; case "The ROC crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, 2 - dLevel }; break; case "The ROC changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 1 }; break; case "The ROC changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 1 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adROC, dLevel, 2 - dLevel, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { int iFromHour = (int)IndParam.NumParam[0].Value; int iFromMin = (int)IndParam.NumParam[1].Value; int iUntilHour = (int)IndParam.NumParam[2].Value; int iUntilMin = (int)IndParam.NumParam[3].Value; TimeSpan tsFromTime = new TimeSpan(iFromHour, iFromMin, 0); TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0); double dShift = IndParam.NumParam[4].Value * Point; int iFirstBar = 2; // Calculation double[] adHighPrice = new double[Bars]; double[] 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 = false; 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 double[] adUpperBand = new double[Bars]; double[] adLowerBand = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adUpperBand[iBar] = adHighPrice[iBar] + dShift; adLowerBand[iBar] = adLowPrice[iBar] - dShift; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Hourly High"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.DarkGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adHighPrice; Component[1] = new IndicatorComp(); Component[1].CompName = "Hourly Low"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adLowPrice; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].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(iFirstBar, 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(iFirstBar, 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(iFirstBar, 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(iFirstBar, 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; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adOBV = new double[Bars]; int iFirstBar = 5; adOBV[0] = Volume[0]; for (int iBar = 1; iBar < Bars; iBar++) { if (Close[iBar] > Close[iBar - 1]) { adOBV[iBar] = adOBV[iBar - 1] + Volume[iBar]; } else if (Close[iBar] < Close[iBar - 1]) { adOBV[iBar] = adOBV[iBar - 1] - Volume[iBar]; } else { adOBV[iBar] = adOBV[iBar - 1]; } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "On Balance Volume"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Green; Component[0].FirstBar = iFirstBar; Component[0].Value = adOBV; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The On Balance Volume rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The On Balance Volume falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The On Balance Volume changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The On Balance Volume changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adOBV, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters double dShift = IndParam.NumParam[0].Value * Point; int iDigids = (int)IndParam.NumParam[1].Value; // Calculation double[] adUpperRN = new double[Bars]; double[] adLowerRN = new double[Bars]; int iFirstBar = 1; for (int iBar = 1; iBar < Bars; iBar++) { double dNearestRound; int iCutDigids = Digits - iDigids; if (iCutDigids >= 0) { dNearestRound = Math.Round(Open[iBar], iCutDigids); } else { dNearestRound = Math.Round(Open[iBar] * Math.Pow(10, iCutDigids)) / Math.Pow(10, iCutDigids); } if (dNearestRound < Open[iBar]) { adUpperRN[iBar] = dNearestRound + (Point * Math.Pow(10, iDigids)); adLowerRN[iBar] = dNearestRound; } else { adUpperRN[iBar] = dNearestRound; adLowerRN[iBar] = dNearestRound - (Point * Math.Pow(10, iDigids)); } } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Higher round number"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.SpringGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adUpperRN; Component[1] = new IndicatorComp(); Component[1].CompName = "Lower round number"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adLowerRN; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; 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.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; } switch (IndParam.ListParam[0].Text) { case "Enter long at the higher round number": case "Exit long at the higher round number": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[2].Value[iBar] = adUpperRN[iBar] + dShift; Component[3].Value[iBar] = adLowerRN[iBar] - dShift; } break; case "Enter long at the lower round number": case "Exit long at the lower round number": for (int iBar = iFirstBar; iBar < Bars; iBar++) { Component[2].Value[iBar] = adLowerRN[iBar] - dShift; Component[3].Value[iBar] = adUpperRN[iBar] + dShift; } break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters double dShift = IndParam.NumParam[0].Value * Point; int iFirstBar = 1; // Calculation double[] adTopPrice = new double[Bars]; double[] adBottomPrice = new double[Bars]; adTopPrice[0] = 0; adBottomPrice[0] = 0; double dTop = double.MinValue; double dBottom = double.MaxValue; for (int iBar = 1; iBar < Bars; iBar++) { if (High[iBar - 1] > dTop) dTop = High[iBar - 1]; if (Low[iBar - 1] < dBottom) dBottom = Low[iBar - 1]; if (IsPeriodChanged(iBar)) { adTopPrice[iBar] = dTop; adBottomPrice[iBar] = dBottom; dTop = double.MinValue; dBottom = double.MaxValue; } else { adTopPrice[iBar] = adTopPrice[iBar - 1]; adBottomPrice[iBar] = adBottomPrice[iBar - 1]; } } double[] adUpperBand = new double[Bars]; double[] adLowerBand = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adUpperBand[iBar] = adTopPrice[iBar] + dShift; adLowerBand[iBar] = adBottomPrice[iBar] - dShift; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Top price"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.DarkGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adTopPrice; Component[1] = new IndicatorComp(); Component[1].CompName = "Bottom price"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adBottomPrice; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].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 top price": case "Exit long at the top price": Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "Enter long at the bottom price": case "Exit long at the bottom price": Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The bar opens below the top price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar opens above the top price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band); break; case "The bar opens below the bottom price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band); break; case "The bar opens above the bottom price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band); break; case "The bar closes below the top price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar closes above the top price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below the bottom price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above the bottom price": BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; case "The position opens above the top price": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted top price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted bottom price"; Component[3].DataType = IndComponentType.OpenShortPrice; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens below the top price": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted top price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted bottom price"; Component[3].DataType = IndComponentType.OpenShortPrice; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adUpperBand; Component[3].Value = adLowerBand; break; case "The position opens above the bottom price": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted bottom price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].CompName = "Shifted top price"; Component[3].DataType = IndComponentType.OpenShortPrice; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; case "The position opens below the bottom price": Component[0].DataType = IndComponentType.Other; Component[1].DataType = IndComponentType.Other; Component[2].CompName = "Shifted bottom price"; Component[2].DataType = IndComponentType.OpenLongPrice; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].CompName = "Shifted top price"; Component[3].DataType = IndComponentType.OpenShortPrice; Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].Value = adLowerBand; Component[3].Value = adUpperBand; break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters DayOfWeek dowFromDay = (DayOfWeek)IndParam.ListParam[1].Index; DayOfWeek dowUntilDay = (DayOfWeek)IndParam.ListParam[2].Index; // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (dowFromDay < dowUntilDay) adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay && Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0; else if (dowFromDay > dowUntilDay) adBars[iBar] = Time[iBar].DayOfWeek >= dowFromDay || Time[iBar].DayOfWeek < dowUntilDay ? 1 : 0; else adBars[iBar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "Allow long entry"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "Allow short entry"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters // Calculation int iFirstBar = 0; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { adBars[iBar] = 1; } // Saving the components Component = new IndicatorComp[2]; Component[0] = new IndicatorComp(); Component[0].CompName = "(No) Used bars"; Component[0].DataType = IndComponentType.AllowOpenLong; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; Component[1] = new IndicatorComp(); Component[1].CompName = "(No) Used bars"; Component[1].DataType = IndComponentType.AllowOpenShort; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = iFirstBar; Component[1].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { MACD MACD1 = new MACD(slotType); MACD1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; MACD1.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; MACD1.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; MACD1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; MACD1.IndParam.NumParam[1].Value = IndParam.NumParam[2].Value; MACD1.IndParam.NumParam[2].Value = IndParam.NumParam[4].Value; MACD1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; MACD1.Calculate(slotType); MACD MACD2 = new MACD(slotType); MACD2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; MACD2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; MACD2.IndParam.ListParam[3].Index = IndParam.ListParam[3].Index; MACD2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; MACD2.IndParam.NumParam[1].Value = IndParam.NumParam[3].Value; MACD2.IndParam.NumParam[2].Value = IndParam.NumParam[5].Value; MACD2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; MACD2.Calculate(slotType); // Calculation int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iPeriod1 = (int)IndParam.NumParam[0].Value; int iPeriod2 = (int)IndParam.NumParam[1].Value; int iFirstBar = iPeriod1 + iPeriod2 + 2; double[] adIndicator1 = new double[Bars]; double[] adIndicator2 = new double[Bars]; if (IndParam.ListParam[4].Index == 0) { adIndicator1 = MACD1.Component[0].Value; adIndicator2 = MACD2.Component[0].Value; } else if (IndParam.ListParam[4].Index == 1) { adIndicator1 = MACD1.Component[1].Value; adIndicator2 = MACD2.Component[1].Value; } else { adIndicator1 = MACD1.Component[2].Value; adIndicator2 = MACD2.Component[2].Value; } double[] adOscllator = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Oscillator"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adOscllator; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Oscillator of MACD rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Oscillator of MACD falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Oscillator of MACD is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Oscillator of MACD is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "The Oscillator of MACD crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Oscillator of MACD crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Oscillator of MACD changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Oscillator of MACD changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; MAMethod maSignalMAMethod = (MAMethod )IndParam.ListParam[2].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[3].Index; int iPeriod1 = (int)IndParam.NumParam[0].Value; int iPeriod2 = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod1 + iPeriod2 + 2; double[] adIndicator1 = new double[Bars]; double[] adIndicator2 = new double[Bars]; double[] adOscllator = new double[Bars]; // --------------------------------------------------------- RSI rsi1 = new RSI(slotType); rsi1.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; rsi1.IndParam.ListParam[2].Index = IndParam.ListParam[3].Index; rsi1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; rsi1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; rsi1.Calculate(slotType); adIndicator1 = rsi1.Component[0].Value; adIndicator2 = MovingAverage(iPeriod2, 0, maSignalMAMethod, adIndicator1); // ---------------------------------------------------------- for (int iBar = iFirstBar; iBar < Bars; iBar++) { adOscllator[iBar] = adIndicator1[iBar] - adIndicator2[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Oscillator"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adOscllator; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The RSI MA Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The RSI MA Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The RSI MA Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The RSI MA Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "The RSI MA Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The RSI MA Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The RSI MA Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The RSI MA Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adOscllator, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iStepBack = (IndParam.ListParam[0].Text == "There is a NR4 formation" ? 3 : 6); int iFirstBar = iStepBack + iPrvs; double[] adNR = new double[Bars]; double[] adRange = new double[Bars]; for (int iBar = 0; iBar < Bars; iBar++) { adRange[iBar] = High[iBar] - Low[iBar]; adNR[iBar] = 0; } // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { bool bNarrowRange = true; for (int i = 1; i <= iStepBack; i++) if (adRange[iBar - i - iPrvs] <= adRange[iBar - iPrvs]) { bNarrowRange = false; break; } if (bNarrowRange) adNR[iBar] = 1; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Bar Range"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = new double[Bars]; for (int i = 0; i < Bars; i++) Component[0].Value[i] = (double)Math.Round(adRange[i] / Point); Component[1] = new IndicatorComp(); Component[1].CompName = "Allow long entry"; Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = adNR; Component[2] = new IndicatorComp(); Component[2].CompName = "Allow short entry"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = adNR; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int iEntryHour = (int)IndParam.NumParam[0].Value; int iEntryMinute = (int)IndParam.NumParam[1].Value; TimeSpan tsEntryHour = new TimeSpan(iEntryHour, iEntryMinute, 0); // Calculation int iFirstBar = 1; double[] adBars = new double[Bars]; // Calculation of the logic for (int iBar = iFirstBar; iBar < Bars; iBar++) { adBars[iBar] = Time[iBar].TimeOfDay == tsEntryHour ? Open[iBar] : 0; } // Saving the components Component = new IndicatorComp[1]; Component[0] = new IndicatorComp(); Component[0].CompName = "Entry hour"; Component[0].DataType = IndComponentType.OpenPrice; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = iFirstBar; Component[0].Value = adBars; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iPeriod = (int)IndParam.NumParam[0].Value; int iSmooth = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adBasePrice = Price(basePrice); double[] adCumulSum = new double[Bars]; adCumulSum[iPeriod - 1] = 0; for (int iBar = 0; iBar < iPeriod; iBar++) { adCumulSum[iPeriod - 1] += adBasePrice[iBar]; } for (int iBar = iPeriod; iBar < Bars; iBar++) { adCumulSum[iBar] = adCumulSum[iBar - 1] - adBasePrice[iBar - iPeriod] + adBasePrice[iBar]; } adCumulSum = MovingAverage(iSmooth, 0, maMethod, adCumulSum); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Cumulative Sum"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adCumulSum; 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Cumulative Sum rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Cumulative Sum falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Cumulative Sum changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Cumulative Sum changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adCumulSum, 0, 0, ref Component[1], ref Component[2], indLogic); return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int nPeriod = (int)IndParam.NumParam[0].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = 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); double[] adTrix = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) adTrix[iBar] = 100 * (ma3[iBar] - ma3[iBar - 1]) / ma3[iBar - 1]; double[] adSignal = MovingAverage(nPeriod, 0, maMethod, adTrix); // adHistogram reprezents the Trix Index oscillator double[] adHistogram = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) adHistogram[iBar] = adTrix[iBar] - adSignal[iBar]; // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "Histogram"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adHistogram; Component[1] = new IndicatorComp(); Component[1].CompName = "Signal"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Gold; Component[1].FirstBar = iFirstBar; Component[1].Value = adSignal; Component[2] = new IndicatorComp(); Component[2].CompName = "Trix Line"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Blue; Component[2].FirstBar = iFirstBar; Component[2].Value = adTrix; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = iFirstBar; Component[4].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 Trix Index line rises": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_rises); break; case "The Trix Index line falls": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_falls); break; case "The Trix Index line is higher than zero": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "The Trix Index line is lower than zero": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; case "The Trix Index line crosses the zero line upward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "The Trix Index line crosses the zero line downward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "The Trix Index line changes its direction upward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_upward); break; case "The Trix Index line changes its direction downward": OscillatorLogic(iFirstBar, iPrvs, adTrix, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_changes_its_direction_downward); break; case "The Trix Index line crosses the Signal line upward": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_upward); break; case "The Trix Index line crosses the Signal line downward": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_crosses_the_level_line_downward); break; case "The Trix Index line is higher than the Signal line": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); break; case "The Trix Index line is lower than the Signal line": OscillatorLogic(iFirstBar, iPrvs, adHistogram, 0, 0, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); break; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { double dShift = IndParam.NumParam[0].Value * Point; // Calculation double[] adHighPrice = new double[Bars]; double[] adLowPrice = new double[Bars]; int iFirstBar = 2; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adHighPrice[iBar] = High[iBar - 1]; adLowPrice[iBar] = Low[iBar - 1]; } double[] adUpperBand = new double[Bars]; double[] adLowerBand = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adUpperBand[iBar] = adHighPrice[iBar] + dShift; adLowerBand[iBar] = adLowPrice[iBar] - dShift; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Previous High"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Level; Component[0].ChartColor = Color.DarkGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adHighPrice; Component[1] = new IndicatorComp(); Component[1].CompName = "Previous Low"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Level; Component[1].ChartColor = Color.DarkRed; Component[1].FirstBar = iFirstBar; Component[1].Value = adLowPrice; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = iFirstBar; Component[3].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(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar opens above the previous high": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Upper_Band); break; case "The bar opens below the previous low": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_below_the_Lower_Band); break; case "The bar opens above the previous low": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_opens_above_the_Lower_Band); break; case "The bar closes below the previous high": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band); break; case "The bar closes above the previous high": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below the previous low": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above the previous low": BandIndicatorLogic(iFirstBar, 0, adLowerBand, adUpperBand, 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; default: break; } return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { int fridayClosingHour = (int)IndParam.NumParam[0].Value; int fridayClosingMin = (int)IndParam.NumParam[1].Value; // Calculation DateTime time = ServerTime; DateTime fridayTime = new DateTime(time.Year, time.Month, time.Day, fridayClosingHour, fridayClosingMin, 0); int firstBar = 1; double[] adClosePrice = new double[Bars]; // Calculation of the logic for (int bar = firstBar; bar < Bars - 1; bar++) { if (Time[bar].DayOfWeek > DayOfWeek.Wednesday && Time[bar + 1].DayOfWeek < DayOfWeek.Wednesday) adClosePrice[bar] = Close[bar]; else adClosePrice[bar] = 0; } double[] adAllowOpenLong = new double[Bars]; double[] adAllowOpenShort = new double[Bars]; for (int bar = 1; bar < Bars; bar++) { adAllowOpenLong[bar] = 1; adAllowOpenShort[bar] = 1; } // Check the last bar if (time.DayOfWeek == DayOfWeek.Friday) if (time >= fridayTime) { adClosePrice[Bars - 1] = Close[Bars - 1]; // Prevent entries after closing time adAllowOpenLong[Bars - 1] = 0; adAllowOpenShort[Bars - 1] = 0; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Week Closing"; Component[0].DataType = IndComponentType.ClosePrice; Component[0].ChartType = IndChartType.NoChart; Component[0].ShowInDynInfo = false; Component[0].FirstBar = firstBar; Component[0].Value = adClosePrice; Component[1] = new IndicatorComp(); Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[1].ChartType = IndChartType.NoChart; Component[1].ShowInDynInfo = false; Component[1].FirstBar = 2; Component[1].Value = adAllowOpenLong; Component[2] = new IndicatorComp(); Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; Component[2].ChartType = IndChartType.NoChart; Component[2].ShowInDynInfo = false; Component[2].FirstBar = 2; Component[2].Value = adAllowOpenShort; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; int period = (int)IndParam.NumParam[0].Value; double level = IndParam.NumParam[1].Value; int prev = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int firstBar = 2 * period + 2; double[] DIPos = new double[Bars]; double[] DINeg = new double[Bars]; for (int bar = 1; bar < Bars; bar++) { double trueRange = Math.Max(High[bar], Close[bar - 1]) - Math.Min(Low[bar], Close[bar - 1]); if (trueRange < Point) { trueRange = Point; } double deltaHigh = High[bar] - High[bar - 1]; double deltaLow = Low[bar - 1] - Low[bar]; if (deltaHigh > 0 && deltaHigh > deltaLow) { DIPos[bar] = 100 * deltaHigh / trueRange; } else { DIPos[bar] = 0; } if (deltaLow > 0 && deltaLow > deltaHigh) { DINeg[bar] = 100 * deltaLow / trueRange; } else { DINeg[bar] = 0; } } double[] ADIPos = MovingAverage(period, 0, maMethod, DIPos); double[] ADINeg = MovingAverage(period, 0, maMethod, DINeg); double[] DX = new double[Bars]; for (int bar = 0; bar < Bars; bar++) { if (ADIPos[bar] + ADINeg[bar] == 0) { DX[bar] = 0; } else { DX[bar] = 100 * Math.Abs((ADIPos[bar] - ADINeg[bar]) / (ADIPos[bar] + ADINeg[bar])); } } double[] ADX = MovingAverage(period, 0, maMethod, DX); // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp(); Component[0].CompName = "ADX"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Blue; Component[0].FirstBar = firstBar; Component[0].Value = ADX; Component[1] = new IndicatorComp(); Component[1].CompName = "ADI+"; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].ChartColor = Color.Green; Component[1].FirstBar = firstBar; Component[1].Value = ADIPos; Component[2] = new IndicatorComp(); Component[2].CompName = "ADI-"; Component[2].DataType = IndComponentType.IndicatorValue; Component[2].ChartType = IndChartType.Line; Component[2].ChartColor = Color.Red; Component[2].FirstBar = firstBar; Component[2].Value = ADINeg; Component[3] = new IndicatorComp(); Component[3].ChartType = IndChartType.NoChart; Component[3].FirstBar = firstBar; Component[3].Value = new double[Bars]; Component[4] = new IndicatorComp(); Component[4].ChartType = IndChartType.NoChart; Component[4].FirstBar = firstBar; Component[4].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"; } // Calculation of the logic IndicatorLogic logicRule; switch (IndParam.ListParam[0].Text) { case "The ADX rises": logicRule = IndicatorLogic.The_indicator_rises; break; case "The ADX falls": logicRule = IndicatorLogic.The_indicator_falls; break; case "The ADX is higher than the Level line": logicRule = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[1] { level }; break; case "The ADX is lower than the Level line": logicRule = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[1] { level }; break; case "The ADX crosses the Level line upward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[1] { level }; break; case "The ADX crosses the Level line downward": logicRule = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[1] { level }; break; case "The ADX changes its direction upward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The ADX changes its direction downward": logicRule = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: logicRule = IndicatorLogic.It_does_not_act_as_a_filter; break; } // ADX rises equal signals in both directions! NoDirectionOscillatorLogic(firstBar, prev, ADX, level, ref Component[3], logicRule); Component[4].Value = Component[3].Value; return; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters int nBars = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = nBars + 1; double[] adRange = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { double maxHigh = double.MinValue; double minLow = double.MaxValue; for (int i = 0; i < nBars; i++) { if (High[iBar - i] > maxHigh) maxHigh = High[iBar - i]; if (Low[iBar - i] < minLow) minLow = Low[iBar - i]; } adRange[iBar] = maxHigh - minLow; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Bar Range"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = new double[Bars]; for (int i = 0; i < Bars; i++) Component[0].Value[i] = (double)Math.Round(adRange[i] / Point); 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 IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Bar Range rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Bar Range falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Bar Range is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; case "The Bar Range is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; default: break; } NoDirectionOscillatorLogic(iFirstBar, iPrvs, adRange, dLevel * Point, ref Component[1], indLogic); Component[2].Value = Component[1].Value; return; }