public void UpdateIndicatorTest() { var indicator = new Indicator { Name = "Indicator", Area = 1, Red = new BinaryOperator(), Yellow = new BinaryOperator(), Green = new BinaryOperator(), }; var mock = new Mock <IRepository <Indicator> >(MockBehavior.Strict); mock.Setup(m => m.Update(It.IsAny <Indicator>())); mock.Setup(m => m.Has(indicator)).Returns(true); mock.Setup(m => m.Save()); IIndicatorLogic indicatorLogic = new IndicatorLogic(mock.Object); indicator.Name = "Indicator2"; indicatorLogic.UpdateIndicator(indicator); mock.VerifyAll(); Assert.AreEqual(indicator.Name, "Indicator2"); }
public ActionResult Put(int id, [FromBody] List <int> order) { try { var user = userLogic.GetUserByID(id); List <Indicator> indicadores = userLogic.GetAllIndicators(user); List <Indicator> orderSet = new List <Indicator>(); IndicatorLogic il = new IndicatorLogic(null); foreach (int i in order) { foreach (Indicator ind in indicadores) { if (ind.ID == i) { orderSet.Add(ind); } } } List <Indicator> toReturn = userLogic.ReorderUserIndicators(user, orderSet); return(Ok(toReturn)); } catch (NullException) { return(BadRequest("No es posible obtener un usuario nulo")); } catch (NotFoundException) { return(BadRequest("No fue posible obtener ese usuario")); } catch (NullReferenceException) { return(BadRequest("No es posible obtener un usuario nulo")); } catch (NotValidException) { return(BadRequest("No es posible obtener un usuario no válido")); } catch (DataBaseLogicException) { return(BadRequest("Error en la conexión con la base de datos")); } catch (InvalidOperationLogicException) { return(BadRequest("Error en el sistema")); } }
public void UpdateIndicatorStringValeExpresionEqualmockOk() { Guid id = Guid.NewGuid(); string color = "red"; Value izq = new StringValue { Data = "hola" }; Value der = new StringValue { Data = "hola" }; BaseCondition component = new Condition { ValueIzq = izq, ValueDer = der, Operator = "=" }; Indicator indicator = new Indicator { Color = color, Id = id, Condition = component }; var mock = new Mock <IRepository <Indicator> >(MockBehavior.Strict); mock.Setup(m => m.Update(It.IsAny <Indicator>())); mock.Setup(m => m.Save()); IndicatorLogic indicatorLogic = new IndicatorLogic(mock.Object); indicatorLogic.Update(indicator); mock.VerifyAll(); }
public void UdateIndicatorStringValeExpresionEqualNotOk() { Guid id = Guid.NewGuid(); string color = "red"; Value izq = new StringValue { Data = "hola" }; Value der = new StringValue { Data = "hola" }; BaseCondition component = new Condition { ValueIzq = izq, ValueDer = der, Operator = "=" }; Indicator indicator = new Indicator { Color = color, Id = id, Condition = component }; var context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); IRepository <Indicator> indicatorRepo = new IndicatorRepository(context); IndicatorLogic indicatroLogic = new IndicatorLogic(indicatorRepo); indicatroLogic.Update(indicator); }
public void CreateIndicatorStringValeExpresionEqualOk2() { Guid id = Guid.NewGuid(); string color = "red"; Value izq = new StringValue { Data = "hola" }; Value der = new StringValue { Data = "chau" }; BaseCondition component = new Condition { ValueIzq = izq, ValueDer = der, Operator = "=" }; Indicator indicator = new Indicator { Color = color, Id = id, Condition = component }; var context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); IRepository <Indicator> indicatorRepo = new IndicatorRepository(context); IndicatorLogic indicatroLogic = new IndicatorLogic(indicatorRepo); indicatroLogic.Create(indicator); var components = indicatorRepo.GetAll().ToList(); bool res = components[0].Condition.Eval(); Assert.IsTrue(res == false); }
private void Start() { // Indicator script init; \\ indicatorLogic = GetComponentInChildren <IndicatorLogic>(true); // Nearest target (Point), nearests point color \\ /// ummary> /// /// </summary> /// <returns></returns> cHZ = indicatorLogic.GetCurrentHitzone(); eBChS = GetComponent <BonyCharacter>(); }
public void CreateUserIndicator() { UserLogic ul = new UserLogic(null); User u = ul.GetUserByID(1); IndicatorLogic il = new IndicatorLogic(null); Indicator i2 = il.GetById(2); List <Indicator> ia = ul.GetAllIndicators(u); ul.AddIndicator(u, i2); ul.ShowIndicator(u, i2); List <Indicator> reorder = ul.GetAllIndicators(u); //il.DeleteIndicator(i2.ID); Assert.AreEqual(1, reorder.Count()); }
public void CreateExistingIndicatorTest() { var indicator = new Indicator { Area = 1, Red = new BinaryOperator(), Yellow = new BinaryOperator(), Green = new BinaryOperator(), }; var mock = new Mock <IRepository <Indicator> >(MockBehavior.Strict); mock.Setup(m => m.Add(It.IsAny <Indicator>())); mock.Setup(m => m.Has(indicator)).Returns(true); mock.Setup(m => m.Save()); IIndicatorLogic indicatorLogic = new IndicatorLogic(mock.Object); var result = indicatorLogic.AddIndicator(indicator); mock.VerifyAll(); Assert.AreEqual(indicator.Name, result.Name); }
public void DeleteUnexistingIndicatorTest() { var indicator = new Indicator { Area = 1, Red = new BinaryOperator(), Yellow = new BinaryOperator(), Green = new BinaryOperator(), }; var mock = new Mock <IRepository <Indicator> >(MockBehavior.Strict); mock.Setup(m => m.Has(It.IsAny <Indicator>())).Returns(false); mock.Setup(m => m.Delete(It.IsAny <Indicator>())); mock.Setup(m => m.Save()); IIndicatorLogic indicatorLogic = new IndicatorLogic(mock.Object); indicatorLogic.DeleteIndicator(indicator.ID); mock.VerifyAll(); }
public void GetAllIndicatorsTest() { var indicator1 = new Indicator { Name = "Name1", Area = 1, Red = new BinaryOperator(), Yellow = new BinaryOperator(), Green = new BinaryOperator(), }; var indicator2 = new Indicator { Name = "Name2", Area = 1, Red = new BinaryOperator(), Yellow = new BinaryOperator(), Green = new BinaryOperator(), }; List <Indicator> indicators = new List <Indicator>(); indicators.Add(indicator1); indicators.Add(indicator2); var mock = new Mock <IRepository <Indicator> >(MockBehavior.Strict); mock.Setup(m => m.GetAll()).Returns(indicators); IIndicatorLogic indicatorLogic = new IndicatorLogic(mock.Object); IEnumerable <Indicator> retorno = indicatorLogic.GetAllIndicators(); List <Indicator> result = indicatorLogic.GetAllIndicators().ToList(); mock.VerifyAll(); Assert.AreEqual(result.Count, indicators.Count); }
/// <summary> /// Calculates the logic of an Oscillator. /// </summary> /// <param name="firstBar">The first bar number.</param> /// <param name="previous">To use the previous bar or not.</param> /// <param name="adIndValue">The indicator values.</param> /// <param name="levelLong">The Level value for a Long position.</param> /// <param name="levelShort">The Level value for a Short position.</param> /// <param name="indCompLong">Indicator component for Long position.</param> /// <param name="indCompShort">Indicator component for Short position.</param> /// <param name="indLogic">The chosen logic.</param> /// <returns>True if everything is ok.</returns> protected bool OscillatorLogic(int firstBar, int previous, double[] indValue, double levelLong, double levelShort, ref IndicatorComp indCompLong, ref IndicatorComp indCompShort, IndicatorLogic indLogic) { double sigma = Sigma(); switch (indLogic) { case IndicatorLogic.The_indicator_rises: for (int bar = firstBar; bar < Bars; bar++) { int currBar = bar - previous; int baseBar = currBar - 1; bool isHigher = indValue[currBar] > indValue[baseBar]; if (!IsDiscreteValues) // Aroon oscillator uses isDescreteValues = true { bool isNoChange = true; while (Math.Abs(indValue[currBar] - indValue[baseBar]) < sigma && isNoChange && baseBar > firstBar) { isNoChange = (isHigher == (indValue[baseBar + 1] > indValue[baseBar])); baseBar--; } } indCompLong.Value[bar] = indValue[baseBar] < indValue[currBar] - sigma ? 1 : 0; indCompShort.Value[bar] = indValue[baseBar] > indValue[currBar] + sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_falls: for (int bar = firstBar; bar < Bars; bar++) { int currBar = bar - previous; int baseBar = currBar - 1; bool isHigher = indValue[currBar] > indValue[baseBar]; if (!IsDiscreteValues) { bool isNoChange = true; while (Math.Abs(indValue[currBar] - indValue[baseBar]) < sigma && isNoChange && baseBar > firstBar) { isNoChange = (isHigher == (indValue[baseBar + 1] > indValue[baseBar])); baseBar--; } } indCompLong.Value[bar] = indValue[baseBar] > indValue[currBar] + sigma ? 1 : 0; indCompShort.Value[bar] = indValue[baseBar] < indValue[currBar] - sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_is_higher_than_the_level_line: for (int bar = firstBar; bar < Bars; bar++) { indCompLong.Value[bar] = indValue[bar - previous] > levelLong + sigma ? 1 : 0; indCompShort.Value[bar] = indValue[bar - previous] < levelShort - sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_is_lower_than_the_level_line: for (int bar = firstBar; bar < Bars; bar++) { indCompLong.Value[bar] = indValue[bar - previous] < levelLong - sigma ? 1 : 0; indCompShort.Value[bar] = indValue[bar - previous] > levelShort + sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_crosses_the_level_line_upward: for (int bar = firstBar; bar < Bars; bar++) { int baseBar = bar - previous - 1; while (Math.Abs(indValue[baseBar] - levelLong) < sigma && baseBar > firstBar) { baseBar--; } indCompLong.Value[bar] = (indValue[baseBar] < levelLong - sigma && indValue[bar - previous] > levelLong + sigma) ? 1 : 0; indCompShort.Value[bar] = (indValue[baseBar] > levelShort + sigma && indValue[bar - previous] < levelShort - sigma) ? 1 : 0; } break; case IndicatorLogic.The_indicator_crosses_the_level_line_downward: for (int bar = firstBar; bar < Bars; bar++) { int baseBar = bar - previous - 1; while (Math.Abs(indValue[baseBar] - levelLong) < sigma && baseBar > firstBar) { baseBar--; } indCompLong.Value[bar] = (indValue[baseBar] > levelLong + sigma && indValue[bar - previous] < levelLong - sigma) ? 1 : 0; indCompShort.Value[bar] = (indValue[baseBar] < levelShort - sigma && indValue[bar - previous] > levelShort + sigma) ? 1 : 0; } break; case IndicatorLogic.The_indicator_changes_its_direction_upward: for (int bar = firstBar; bar < Bars; bar++) { int bar0 = bar - previous; int bar1 = bar0 - 1; while (Math.Abs(indValue[bar0] - indValue[bar1]) < sigma && bar1 > firstBar) { bar1--; } int bar2 = bar1 - 1 > firstBar ? bar1 - 1 : firstBar; while (Math.Abs(indValue[bar1] - indValue[bar2]) < sigma && bar2 > firstBar) { bar2--; } indCompLong.Value[bar] = (indValue[bar2] > indValue[bar1] && indValue[bar1] < indValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; indCompShort.Value[bar] = (indValue[bar2] < indValue[bar1] && indValue[bar1] > indValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; } break; case IndicatorLogic.The_indicator_changes_its_direction_downward: for (int bar = firstBar; bar < Bars; bar++) { int bar0 = bar - previous; int bar1 = bar0 - 1; while (Math.Abs(indValue[bar0] - indValue[bar1]) < sigma && bar1 > firstBar) { bar1--; } int bar2 = bar1 - 1 > firstBar ? bar1 - 1 : firstBar; while (Math.Abs(indValue[bar1] - indValue[bar2]) < sigma && bar2 > firstBar) { bar2--; } indCompLong.Value[bar] = (indValue[bar2] < indValue[bar1] && indValue[bar1] > indValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; indCompShort.Value[bar] = (indValue[bar2] > indValue[bar1] && indValue[bar1] < indValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; } break; default: return false; } return true; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters MAMethod maMethod1 = (MAMethod)IndParam.ListParam[1].Index; MAMethod maMethod2 = (MAMethod)IndParam.ListParam[2].Index; BasePrice price = (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 + 1; double[] adPrice = Price(price); double[] adMA = MovingAverage(iPeriod1, 0, maMethod1, adPrice); double[] adMAPr = new double[Bars]; for (int iBar = 0; iBar < Bars; iBar++) { adMAPr[iBar] = adPrice[iBar] - adMA[iBar]; } double[] adDO = MovingAverage(iPeriod2, 0, maMethod2, adMAPr); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Detrended Oscillator"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.LightSeaGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adDO; 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 Detrended Oscillator rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Detrended Oscillator falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Detrended Oscillator is higher than the zero line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Detrended Oscillator is lower than the zero line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "The Detrended Oscillator crosses the zero line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Detrended Oscillator crosses the zero line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Detrended Oscillator changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Detrended Oscillator changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adDO, 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 BasePrice basePrice = (BasePrice)IndParam.ListParam[1].Index; MAMethod fastMAMethod = (MAMethod )IndParam.ListParam[3].Index; MAMethod slowMAMethod = (MAMethod )IndParam.ListParam[4].Index; int iNFastMA = (int)IndParam.NumParam[0].Value; int iNSlowMA = (int)IndParam.NumParam[1].Value; int iSFastMA = (int)IndParam.NumParam[2].Value; int iSSlowMA = (int)IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; string[] saColors = new string[] { "Blue", "Black", "Red", "Green", "Yellow", "Orange" }; string sFastColor = saColors[(int)IndParam.NumParam[4].Value]; string sSlowColor = saColors[(int)IndParam.NumParam[5].Value]; // Convert to Higher Time Frame --------------------------------------------- DataPeriods htfPeriod = DataPeriods.week; double[] hfOpen = new double[Bars]; double[] hfClose = new double[Bars]; double[] hfHigh = new double[Bars]; double[] hfLow = new double[Bars]; double[] hfVolume = new double[Bars]; double[] hfPrice = new double[Bars]; int[] hIndex = new int[Bars]; int iFrame; int hBars; switch (IndParam.ListParam[2].Index) { case 1: htfPeriod = DataPeriods.min5; break; case 2: htfPeriod = DataPeriods.min15; break; case 3: htfPeriod = DataPeriods.min30; break; case 4: htfPeriod = DataPeriods.hour1; break; case 5: htfPeriod = DataPeriods.hour4; break; case 6: htfPeriod = DataPeriods.day; break; case 7: htfPeriod = DataPeriods.week; break; } int err1 = HigherTimeFrame(Period, htfPeriod, out hIndex, out hBars, out iFrame, out hfHigh, out hfLow, out hfOpen, out hfClose, out hfVolume); int err2 = HigherBasePrice(basePrice, hBars, hfHigh, hfLow, hfOpen, hfClose, out hfPrice); if (err1 == 1) { return; } //----------------------------------------------------------------------- // Calculation int iFirstBar = (int)Math.Max(iNFastMA + iSFastMA, iNSlowMA + iSSlowMA) + 2; double[] adMAFast = MovingAverage(iNFastMA, iSFastMA, fastMAMethod, hfPrice); double[] adMASlow = MovingAverage(iNSlowMA, iSSlowMA, slowMAMethod, hfPrice); double[] adMAOscillator = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adMAOscillator[iBar] = adMAFast[iBar] - adMASlow[iBar]; } // Convert to Current Time Frame ---------------------------------------------- /// start WTF modfication 2 version 4 // do in 3 blocks for adMAFast, adMASlow, to draw on chart, and adMAOscillator for signals // copy of wider time frame array of values double[] hadMAFast = new double[Bars]; adMAFast.CopyTo(hadMAFast, 0); int err3 = CurrentTimeFrame(hIndex, hBars, ref adMAFast); // if any error, return out of calculation and indicator fails silently if (err3 == 1) { return; } // copy of wider time frame array of values double[] hadMASlow = new double[Bars]; adMASlow.CopyTo(hadMASlow, 0); err3 = CurrentTimeFrame(hIndex, hBars, ref adMASlow); // if any error, return out of calculation and indicator fails silently if (err3 == 1) { return; } // copy of wider time frame array of values double[] hadMAOscillator = new double[Bars]; adMAOscillator.CopyTo(hadMAOscillator, 0); err3 = CurrentTimeFrame(hIndex, hBars, ref adMAOscillator); // if any error, return out of calculation and indicator fails silently if (err3 == 1) { return; } /// end WTF modfication 2 version 4 //----------------------------------------------------------------------------- // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Fast Moving Average"; Component[0].ChartColor = Color.FromName(sFastColor); Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].FirstBar = iFirstBar; Component[0].Value = adMAFast; Component[1] = new IndicatorComp(); Component[1].CompName = "Slow Moving Average"; Component[1].ChartColor = Color.FromName(sSlowColor); Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].FirstBar = iFirstBar; Component[1].Value = adMASlow; 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.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"; } // Calculation of the logic IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Fast MA crosses the Slow MA upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Fast MA crosses the Slow MA downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Fast MA is higher than the Slow MA": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Fast MA is lower than the Slow MA": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; case "Draw only, no entry or exit signals": Component[2].CompName = "Visual Only"; Component[2].DataType = IndComponentType.NotDefined; Component[3].CompName = "Visual Only"; Component[3].DataType = IndComponentType.NotDefined; break; default: break; } /// start WTF modfication 3 version 4 // back up Bars value, reset to hBars, for performance improvement in indicator logic function int mtfBars = Data.Bars; Data.Bars = hBars; // replace very small values with 0 for performance improvement; don't know why but works for (int ctr = 0; ctr < hadMAOscillator.Length; ctr++) { hadMAOscillator[ctr] = (hadMAOscillator[ctr] < .000000001 && hadMAOscillator[ctr] > -.000000001) ? 0 : hadMAOscillator[ctr]; } OscillatorLogic(iFirstBar, iPrvs, hadMAOscillator, 0, 0, ref Component[2], ref Component[3], indLogic); // resest Bars to real value Data.Bars = mtfBars; // expand component array from wtf to current time frame double[] wtfCompValue = Component[2].Value; int err4 = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue); if (err4 == 1) { return; } Component[2].Value = wtfCompValue; wtfCompValue = Component[3].Value; int err5 = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue); if (err5 == 1) { return; } Component[3].Value = wtfCompValue; /// end WTF modfication 3 version 4 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 nSlow = (int)IndParam.NumParam[0].Value; int nFast = (int)IndParam.NumParam[1].Value; double dLevel = IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = nSlow + 2; double[] adMASlow = MovingAverage(nSlow, 0, maMethod, Price(basePrice)); double[] adMAFast = MovingAverage(nFast, 0, maMethod, Price(basePrice)); double[] adAO = new double[Bars]; for (int iBar = nSlow - 1; iBar < Bars; iBar++) { adAO[iBar] = adMAFast[iBar] - adMASlow[iBar]; } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "AO"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adAO; 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 indicatorLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The AO rises": indicatorLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The AO falls": indicatorLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The AO is higher than the Level line": indicatorLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The AO is lower than the Level line": indicatorLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The AO crosses the Level line upward": indicatorLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The AO crosses the Level line downward": indicatorLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The AO changes its direction upward": indicatorLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The AO changes its direction downward": indicatorLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adAO, dLevel, -dLevel, ref Component[1], ref Component[2], indicatorLogic); 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[] adDeMax = new double[Bars]; double[] adDeMin = new double[Bars]; double[] adDeMarker = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { adDeMax[iBar] = High[iBar] > High[iBar - 1] ? High[iBar] - High[iBar - 1] : 0; adDeMin[iBar] = Low[iBar] < Low[iBar - 1] ? Low[iBar - 1] - Low[iBar] : 0; } double[] adDeMaxMA = MovingAverage(iPeriod, 0, maMethod, adDeMax); double[] adDeMinMA = MovingAverage(iPeriod, 0, maMethod, adDeMin); for (int iBar = iFirstBar; iBar < Bars; iBar++) { if (adDeMaxMA[iBar] + adDeMinMA[iBar] == 0) { adDeMarker[iBar] = 0; } else { adDeMarker[iBar] = adDeMaxMA[iBar] / (adDeMaxMA[iBar] + adDeMinMA[iBar]); } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "DeMarker"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.RoyalBlue; Component[0].FirstBar = iFirstBar; Component[0].Value = adDeMarker; 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 DeMarker rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0.5 }; break; case "The DeMarker falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0.5 }; break; case "The DeMarker is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[2] { dLevel, 1 - dLevel }; break; case "The DeMarker is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[2] { dLevel, 1 - dLevel }; break; case "The DeMarker crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, 1 - dLevel }; break; case "The DeMarker crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, 1 - dLevel }; break; case "The DeMarker changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0.5 }; break; case "The DeMarker changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0.5 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adDeMarker, dLevel, 1 - dLevel, ref Component[1], ref Component[2], indLogic); return; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters MAMethod maMethod = (MAMethod)IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int period = (int)IndParam.NumParam[0].Value; int smooth = (int)IndParam.NumParam[1].Value; double level = IndParam.NumParam[2].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; int firstBar = previous + period + smooth + 2; double[] adMomentum = new double[Bars]; double[] adBasePrice = Price(basePrice); for (int bar = period; bar < Bars; bar++) { adMomentum[bar] = 100 * adBasePrice[bar] / adBasePrice[bar - period]; } if (smooth > 0) { adMomentum = MovingAverage(smooth, 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 = firstBar; Component[0].Value = adMomentum; 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 switch (SlotType) { case 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"; break; case 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"; break; default: break; } // Calculation of the logic IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "Momentum rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[] { 100 }; break; case "Momentum falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[] { 100 }; break; case "Momentum is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[] { level, 2 * 100 - level }; break; case "Momentum is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[] { level, 2 * 100 - level }; break; case "Momentum crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[] { level, 2 * 100 - level }; break; case "Momentum crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[] { level, 2 * 100 - level }; break; case "Momentum changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[] { 100 }; break; case "Momentum changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[] { 100 }; break; default: break; } OscillatorLogic(firstBar, previous, adMomentum, level, 2 * 100 - level, ref Component[1], ref Component[2], indLogic); }
public void CreateIndicator() { IAreaLogic areaLogic = new AreaLogic(null); var area = areaLogic.GetAreaByID(1); var Left1 = new Operator { Type = 5, Text = "22/5/2018", Area = area.ID, }; var Right1 = new Operator { Type = 5, Text = "22/3/2018", Area = area.ID, }; var binaryRed = new BinaryOperator { Type = 4, Left = Left1, Right = Right1, Sign = "<=", Area = area.ID, }; var Left2 = new Operator { Type = 2, Text = "2", Area = area.ID, }; var Right2 = new Operator { Type = 2, Text = "3", Area = area.ID, }; var binaryGreenRight = new BinaryOperator { Type = 4, Left = Left2, Right = Right2, Sign = ">", Area = area.ID, }; var binaryGreen = new BinaryOperator { Type = 4, Left = binaryRed, Right = binaryGreenRight, Sign = "OR", Area = area.ID, }; var indicator = new Indicator { Area = area.ID, Name = "Prueba1", Green = binaryGreen, Red = binaryRed, Yellow = binaryRed, }; IIndicatorLogic indicatorLogic = new IndicatorLogic(null); var result = indicatorLogic.AddIndicator(indicator); Assert.AreEqual(indicator.Name, result.Name); }
/// <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 = 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[] adDFast = MovingAverage(iDFast, 0, maMethod, adK); 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.Yellow; 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 if (IndParam.ListParam[0].Text == "The Fast %D is higher than the Slow %D") { SpecialValues = new double[1] { 50 }; IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adDFast, adDSlow, ref Component[3], ref Component[4]); return; } else if (IndParam.ListParam[0].Text == "The Fast %D is lower than the Slow %D") { SpecialValues = new double[1] { 50 }; IndicatorIsLowerThanAnotherIndicatorLogic(iFirstBar, iPrvs, adDFast, adDSlow, ref Component[3], ref Component[4]); return; } else if (IndParam.ListParam[0].Text == "The %K is higher than the Level line") { SpecialValues = new double[2] { iLevel, 100 - iLevel }; OscillatorLogic(iFirstBar, iPrvs, adK, iLevel, 100 - iLevel, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_higher_than_the_level_line); return; } else if (IndParam.ListParam[0].Text == "The %K is lower than the Level line") { SpecialValues = new double[2] { iLevel, 100 - iLevel }; OscillatorLogic(iFirstBar, iPrvs, adK, iLevel, 100 - iLevel, ref Component[3], ref Component[4], IndicatorLogic.The_indicator_is_lower_than_the_level_line); 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 MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int iMAPeriod = (int)IndParam.NumParam[0].Value; int iLRLength = (int)IndParam.NumParam[1].Value; double dLevel = IndParam.NumParam[2].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; double[] dX = new double[Bars]; double[] dY = new double[Bars]; double dSigX; double dSigY; double dSigXY; double dSigXX; double[] adLRSlope = new double[Bars]; int iFirstBar = iMAPeriod + iLRLength + 2; double[] adMAPrice = MovingAverage(iMAPeriod, 0, maMethod, Price(basePrice)); for (int iBar = iFirstBar; iBar < Bars; iBar++) { dSigX = 0; dSigY = 0; dSigXX = 0; dSigXY = 0; for (int index = 0; index < iLRLength; index++) { dSigX = dSigX + index; dSigY = dSigY + adMAPrice[iBar - index]; dSigXY = dSigXY + index * adMAPrice[iBar - index]; dSigXX = dSigXX + index * index; } adLRSlope[iBar] = -(iLRLength * dSigXY - dSigX * dSigY) / (iLRLength * dSigXX - dSigX * dSigX); } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "LR Slope"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adLRSlope; 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 LR Slope rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The LR Slope falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The LR Slope 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 LR Slope 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 LR Slope crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The LR Slope crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The LR Slope changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The LR Slope changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adLRSlope, 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 BasePrice basePrice = (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 int iFirstBar = iPeriod + 2; double[] adBasePrice = Price(basePrice); double[] adCMO1 = new double[Bars]; double[] adCMO2 = new double[Bars]; double[] adCMO1Sum = new double[Bars]; double[] adCMO2Sum = new double[Bars]; double[] adCMO = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { adCMO1[iBar] = 0; adCMO2[iBar] = 0; if (adBasePrice[iBar] > adBasePrice[iBar - 1]) { adCMO1[iBar] = adBasePrice[iBar] - adBasePrice[iBar - 1]; } if (adBasePrice[iBar] < adBasePrice[iBar - 1]) { adCMO2[iBar] = adBasePrice[iBar - 1] - adBasePrice[iBar]; } } for (int iBar = 0; iBar < iPeriod; iBar++) { adCMO1Sum[iPeriod - 1] += adCMO1[iBar]; adCMO2Sum[iPeriod - 1] += adCMO2[iBar]; } for (int iBar = iPeriod; iBar < Bars; iBar++) { adCMO1Sum[iBar] = adCMO1Sum[iBar - 1] + adCMO1[iBar] - adCMO1[iBar - iPeriod]; adCMO2Sum[iBar] = adCMO2Sum[iBar - 1] + adCMO2[iBar] - adCMO2[iBar - iPeriod]; if (adCMO1Sum[iBar] + adCMO2Sum[iBar] == 0) { adCMO[iBar] = 100; } else { adCMO[iBar] = 100 * (adCMO1Sum[iBar] - adCMO2Sum[iBar]) / (adCMO1Sum[iBar] + adCMO2Sum[iBar]); } } // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "CMO"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.RoyalBlue; Component[0].FirstBar = iFirstBar; Component[0].Value = adCMO; 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 CMO rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 0 }; break; case "The CMO falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 0 }; break; case "The CMO 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 CMO 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 CMO crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The CMO crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -dLevel }; break; case "The CMO changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 0 }; break; case "The CMO changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 0 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adCMO, 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 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; 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 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 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 logic of a No Direction Oscillator. /// </summary> /// <param name="firstBar">The first bar number.</param> /// <param name="previous">To use the previous bar or not.</param> /// <param name="adIndValue">The indicator values.</param> /// <param name="level">The Level value.</param> /// <param name="indComp">Indicator component where to save the results.</param> /// <param name="indLogic">The chosen logic.</param> /// <returns>True if everything is ok.</returns> protected bool NoDirectionOscillatorLogic(int firstBar, int previous, double[] adIndValue, double level, ref IndicatorComp indComp, IndicatorLogic indLogic) { double sigma = Sigma(); switch (indLogic) { case IndicatorLogic.The_indicator_rises: for (int bar = firstBar; bar < Bars; bar++) { int currentBar = bar - previous; int baseBar = currentBar - 1; bool isHigher = adIndValue[currentBar] > adIndValue[baseBar]; bool isNoChange = true; while (Math.Abs(adIndValue[currentBar] - adIndValue[baseBar]) < sigma && isNoChange && baseBar > firstBar) { isNoChange = (isHigher == (adIndValue[baseBar + 1] > adIndValue[baseBar])); baseBar--; } indComp.Value[bar] = adIndValue[baseBar] < adIndValue[currentBar] - sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_falls: for (int bar = firstBar; bar < Bars; bar++) { int currentBar = bar - previous; int baseBar = currentBar - 1; bool isHigher = adIndValue[currentBar] > adIndValue[baseBar]; bool isNoChange = true; while (Math.Abs(adIndValue[currentBar] - adIndValue[baseBar]) < sigma && isNoChange && baseBar > firstBar) { isNoChange = (isHigher == (adIndValue[baseBar + 1] > adIndValue[baseBar])); baseBar--; } indComp.Value[bar] = adIndValue[baseBar] > adIndValue[currentBar] + sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_is_higher_than_the_level_line: for (int bar = firstBar; bar < Bars; bar++) { indComp.Value[bar] = adIndValue[bar - previous] > level + sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_is_lower_than_the_level_line: for (int bar = firstBar; bar < Bars; bar++) { indComp.Value[bar] = adIndValue[bar - previous] < level - sigma ? 1 : 0; } break; case IndicatorLogic.The_indicator_crosses_the_level_line_upward: for (int bar = firstBar; bar < Bars; bar++) { int baseBar = bar - previous - 1; while (Math.Abs(adIndValue[baseBar] - level) < sigma && baseBar > firstBar) { baseBar--; } indComp.Value[bar] = (adIndValue[baseBar] < level - sigma && adIndValue[bar - previous] > level + sigma) ? 1 : 0; } break; case IndicatorLogic.The_indicator_crosses_the_level_line_downward: for (int bar = firstBar; bar < Bars; bar++) { int baseBar = bar - previous - 1; while (Math.Abs(adIndValue[baseBar] - level) < sigma && baseBar > firstBar) { baseBar--; } indComp.Value[bar] = (adIndValue[baseBar] > level + sigma && adIndValue[bar - previous] < level - sigma) ? 1 : 0; } break; case IndicatorLogic.The_indicator_changes_its_direction_upward: for (int bar = firstBar; bar < Bars; bar++) { int bar0 = bar - previous; int bar1 = bar0 - 1; while (Math.Abs(adIndValue[bar0] - adIndValue[bar1]) < sigma && bar1 > firstBar) { bar1--; } int bar2 = bar1 - 1 > firstBar ? bar1 - 1 : firstBar; while (Math.Abs(adIndValue[bar1] - adIndValue[bar2]) < sigma && bar2 > firstBar) { bar2--; } indComp.Value[bar] = (adIndValue[bar2] > adIndValue[bar1] && adIndValue[bar1] < adIndValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; } break; case IndicatorLogic.The_indicator_changes_its_direction_downward: for (int bar = firstBar; bar < Bars; bar++) { int bar0 = bar - previous; int bar1 = bar0 - 1; while (Math.Abs(adIndValue[bar0] - adIndValue[bar1]) < sigma && bar1 > firstBar) { bar1--; } int bar2 = bar1 - 1 > firstBar ? bar1 - 1 : firstBar; while (Math.Abs(adIndValue[bar1] - adIndValue[bar2]) < sigma && bar2 > firstBar) { bar2--; } indComp.Value[bar] = (adIndValue[bar2] < adIndValue[bar1] && adIndValue[bar1] > adIndValue[bar0] && bar1 == bar0 - 1) ? 1 : 0; } break; default: return false; } return true; }
/// <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; int iDivisor = (int)IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + 2; double[] adAEOM = new double[Bars]; for (int iBar = 1; iBar < Bars; iBar++) { adAEOM[iBar] = iDivisor * (High[iBar] - Low[iBar]) * ((High[iBar] + Low[iBar]) / 2 - (High[iBar - 1] - Low[iBar - 1]) / 2) / Math.Max(Volume[iBar], 1); } adAEOM = MovingAverage(iPeriod, 0, maMethod, adAEOM); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Ease of Movement"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.LightSeaGreen; Component[0].FirstBar = iFirstBar; Component[0].Value = adAEOM; 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 Ease of Movement rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The Ease of Movement falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The Ease of Movement changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The Ease of Movement changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adAEOM, 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 int iPeriod = (int)IndParam.NumParam[0].Value; int iLevel = (int)IndParam.NumParam[1].Value; int iSmooth = (int)IndParam.NumParam[2].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] adOscar = new double[Bars]; double[] adOscarSmoothed = new double[Bars]; int iFirstBar = iPeriod + 1; double dY = 0; for (int iBar = iPeriod; iBar < Bars; iBar++) { double dX = dY; double dHighest = 0; double dLowest = 999999; for (int iIndex = 0; iIndex < iPeriod; iIndex++) { dHighest = Math.Max(High[iBar - iIndex], dHighest); dLowest = Math.Min(Low[iBar - iIndex], dLowest); } double dClose = Close[iBar]; double dRough = (dClose - dLowest) / (dHighest - dLowest) * 100; dY = (((dX / 3) * 2) + (dRough / 3)); adOscar[iBar] = dY; } adOscarSmoothed = MovingAverage(iSmooth, 0, MAMethod.Simple, adOscar); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "Oscar"; Component[0].DataType = IndComponentType.IndicatorValue; if (IndParam.ListParam[1].Text == "Line") { Component[0].ChartType = IndChartType.Line; } else if (IndParam.ListParam[1].Text == "Histogram") { Component[0].ChartType = IndChartType.Histogram; } Component[0].ChartColor = Color.Blue; Component[0].FirstBar = iFirstBar; Component[0].Value = adOscarSmoothed; 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 Oscar rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { 50 }; break; case "The Oscar falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { 50 }; break; case "The Oscar 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 Oscar 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 Oscar crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Oscar crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; case "The Oscar changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { 50 }; break; case "The Oscar changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { 50 }; break; case "Draw Only, no Entry or Exit": indLogic = IndicatorLogic.It_does_not_act_as_a_filter; Component[1].DataType = IndComponentType.Other; Component[1].CompName = "Visual Only"; Component[2].DataType = IndComponentType.Other; Component[2].CompName = "Visual Only"; SpecialValues = new double[2] { iLevel, 100 - iLevel }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adOscarSmoothed, iLevel, 100 - iLevel, 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 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; }
/// <summary> /// Calculates the indicator's components /// </summary> public override void Calculate(SlotTypes slotType) { // Reading the parameters BasePrice basePrice = (BasePrice)IndParam.ListParam[2].Index; int n = (int)IndParam.NumParam[0].Value; double dLevel = IndParam.NumParam[1].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Convert to Higher Time Frame --------------------------------------------- DataPeriods htfPeriod = DataPeriods.week; double[] hfOpen = new double[Bars]; double[] hfClose = new double[Bars]; double[] hfHigh = new double[Bars]; double[] hfLow = new double[Bars]; double[] hfVolume = new double[Bars]; double[] hfPrice = new double[Bars]; int[] hIndex = new int[Bars]; int iFrame; int hBars; switch (IndParam.ListParam[4].Index) { case 1: htfPeriod = DataPeriods.min5; break; case 2: htfPeriod = DataPeriods.min15; break; case 3: htfPeriod = DataPeriods.min30; break; case 4: htfPeriod = DataPeriods.hour1; break; case 5: htfPeriod = DataPeriods.hour4; break; case 6: htfPeriod = DataPeriods.day; break; case 7: htfPeriod = DataPeriods.week; break; } int err1 = HigherTimeFrame(Period, htfPeriod, out hIndex, out hBars, out iFrame, out hfHigh, out hfLow, out hfOpen, out hfClose, out hfVolume); int err2 = HigherBasePrice(basePrice, hBars, hfHigh, hfLow, hfOpen, hfClose, out hfPrice); if (err1 == 1) { return; } // Calculation int iFirstBar = n + 1; double[] adRegr = new double[Bars]; double[] adRSquared = new double[Bars]; double rsquared; for (int period = iFirstBar; period < Bars; period++) { double x = 0; double xx = 0; double xy = 0; double y = 0; double b = 0; double a = 0; double sumY2 = 0; for (int i = 0; i < n; i++) { int ii = i + 1; double source = hfPrice[period - (n - i)]; // source = xVal x = x + ii; // x = xSum xx = xx + (ii * ii); // xx = sumX2 xy = xy + (ii * source); // xy = sumXY y = y + source; // y = ySum sumY2 += (source * source); } // adapting eSignal code from Tech S&C article Dec 2007 p. 74 // article gets r-squared, matching lines from FXCM code to article's code // see Regression .lua or .cs for orignal regression code // (nLRlen * sumXY) - (xSum * ySum) b = (n * xy) - (x * y); double line1 = b; // (nLRlen * sumX2 - (xSum*xSum)) double line2 = n * xx - (x * x); if (Math.Abs(line2) < 1e-10) { b = 0; } else { b = b / (line2); a = y - (b * x); a = a / n; } // nLRlen * sumY2 - (ySum * ySum) double line3 = n * sumY2 - (y * y); rsquared = Math.Pow(line1 / Math.Sqrt(line2 * line3), 2); adRSquared[period] = rsquared; } // Convert to Current Time Frame ---------------------------------------------- /// start WTF modfication 2 version 4 // copy of wider time frame array of values double[] hadRSquared = new double[Bars]; adRSquared.CopyTo(hadRSquared, 0); int err3 = CurrentTimeFrame(hIndex, hBars, ref adRSquared); // if any error, return out of calculation and indicator fails silently if (err3 == 1) { return; } /// end WTF modfication 2 version 4 //----------------------------------------------------------------------------- // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "R Squared"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Histogram; Component[0].FirstBar = iFirstBar; Component[0].Value = adRSquared; 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 R Squared Line rises": indLogic = IndicatorLogic.The_indicator_rises; break; case "The R Squared Line falls": indLogic = IndicatorLogic.The_indicator_falls; break; case "The R Squared Line is higher than the Level line": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; case "The R Squared Line is lower than the Level line": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; SpecialValues = new double[1] { dLevel }; break; case "The R Squared Line crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[1] { dLevel }; break; case "The R Squared Line crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[1] { dLevel }; break; case "The R Squared Line changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; break; case "The R Squared Line changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; break; default: break; } /// start WTF modfication 3 version 4 // back up Bars value, reset to hBars, for performance improvement in indicator logic function int mtfBars = Data.Bars; Data.Bars = hBars; // replace very small values with 0 for performance improvement; don't know why but works for (int ctr = 0; ctr < hadRSquared.Length; ctr++) { hadRSquared[ctr] = (hadRSquared[ctr] < .000000001 && hadRSquared[ctr] > -.000000001) ? 0 : hadRSquared[ctr]; } NoDirectionOscillatorLogic(iFirstBar, iPrvs, hadRSquared, dLevel, ref Component[1], indLogic); // resest Bars to real value Data.Bars = mtfBars; // expand component array from wtf to current time frame double[] wtfCompValue = Component[1].Value; int err4 = CurrentTimeFrame(hIndex, hBars, ref wtfCompValue); if (err4 == 1) { return; } Component[1].Value = Component[2].Value = wtfCompValue; /// end WTF modfication 3 version 4 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; int iSmoothing = (int)IndParam.NumParam[1].Value; int dLevel = (int)IndParam.NumParam[2].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation int iFirstBar = iPeriod + iSmoothing + iPrvs + 2; double[] adR = 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]; } } adR[iBar] = -100 * (dMax - Close[iBar]) / (dMax - dMin); } double[] adRSmoothed = MovingAverage(iSmoothing, 0, maMethod, adR); // Saving the components Component = new IndicatorComp[3]; Component[0] = new IndicatorComp(); Component[0].CompName = "%R"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Teal; Component[0].FirstBar = iFirstBar; Component[0].Value = adRSmoothed; 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 %R rises": indLogic = IndicatorLogic.The_indicator_rises; SpecialValues = new double[1] { -50 }; break; case "The %R falls": indLogic = IndicatorLogic.The_indicator_falls; SpecialValues = new double[1] { -50 }; break; case "The %R 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 %R 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 %R crosses the Level line upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; SpecialValues = new double[2] { dLevel, -100 - dLevel }; break; case "The %R crosses the Level line downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; SpecialValues = new double[2] { dLevel, -100 - dLevel }; break; case "The %R changes its direction upward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_upward; SpecialValues = new double[1] { -50 }; break; case "The %R changes its direction downward": indLogic = IndicatorLogic.The_indicator_changes_its_direction_downward; SpecialValues = new double[1] { -50 }; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adRSmoothed, 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 MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index; BasePrice basePrice = (BasePrice)IndParam.ListParam[2].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[2].Index; rsi1.IndParam.NumParam[0].Value = IndParam.NumParam[0].Value; rsi1.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; rsi1.Calculate(slotType); RSI rsi2 = new RSI(slotType); rsi2.IndParam.ListParam[1].Index = IndParam.ListParam[1].Index; rsi2.IndParam.ListParam[2].Index = IndParam.ListParam[2].Index; rsi2.IndParam.NumParam[0].Value = IndParam.NumParam[1].Value; rsi2.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked; rsi2.Calculate(slotType); adIndicator1 = rsi1.Component[0].Value; adIndicator2 = rsi2.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 = "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 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; } 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 BasePrice basePrice = (BasePrice)IndParam.ListParam[1].Index; MAMethod fastMAMethod = (MAMethod )IndParam.ListParam[3].Index; MAMethod slowMAMethod = (MAMethod )IndParam.ListParam[4].Index; int iNFastMA = (int)IndParam.NumParam[0].Value; int iNSlowMA = (int)IndParam.NumParam[1].Value; int iSFastMA = (int)IndParam.NumParam[2].Value; int iSSlowMA = (int)IndParam.NumParam[3].Value; int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0; int iFirstBar = (int)Math.Max(iNFastMA + iSFastMA, iNSlowMA + iSSlowMA) + 2; double[] adMAFast = MovingAverage(iNFastMA, iSFastMA, fastMAMethod, Price(basePrice)); double[] adMASlow = MovingAverage(iNSlowMA, iSSlowMA, slowMAMethod, Price(basePrice)); double[] adMAOscillator = new double[Bars]; for (int iBar = iFirstBar; iBar < Bars; iBar++) { adMAOscillator[iBar] = adMAFast[iBar] - adMASlow[iBar]; } // Saving the components Component = new IndicatorComp[4]; Component[0] = new IndicatorComp(); Component[0].CompName = "Fast Moving Average"; Component[0].ChartColor = Color.Goldenrod; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].FirstBar = iFirstBar; Component[0].Value = adMAFast; Component[1] = new IndicatorComp(); Component[1].CompName = "Slow Moving Average"; Component[1].ChartColor = Color.IndianRed; Component[1].DataType = IndComponentType.IndicatorValue; Component[1].ChartType = IndChartType.Line; Component[1].FirstBar = iFirstBar; Component[1].Value = adMASlow; 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.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"; } // Calculation of the logic IndicatorLogic indLogic = IndicatorLogic.It_does_not_act_as_a_filter; switch (IndParam.ListParam[0].Text) { case "The Fast MA crosses the Slow MA upward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_upward; break; case "The Fast MA crosses the Slow MA downward": indLogic = IndicatorLogic.The_indicator_crosses_the_level_line_downward; break; case "The Fast MA is higher than the Slow MA": indLogic = IndicatorLogic.The_indicator_is_higher_than_the_level_line; break; case "The Fast MA is lower than the Slow MA": indLogic = IndicatorLogic.The_indicator_is_lower_than_the_level_line; break; default: break; } OscillatorLogic(iFirstBar, iPrvs, adMAOscillator, 0, 0, ref Component[2], ref Component[3], indLogic); return; }