/// <summary> /// Calculates the base price. /// </summary> /// <param name="priceType">The base price type.</param> /// <returns>Base price.</returns> protected static double[] Price(BasePrice priceType) { var price = new double[Bars]; switch (priceType) { case BasePrice.Open: price = Open; break; case BasePrice.High: price = High; break; case BasePrice.Low: price = Low; break; case BasePrice.Close: price = Close; break; case BasePrice.Median: for (int bar = 0; bar < Bars; bar++) price[bar] = (Low[bar] + High[bar])/2; break; case BasePrice.Typical: for (int bar = 0; bar < Bars; bar++) price[bar] = (Low[bar] + High[bar] + Close[bar])/3; break; case BasePrice.Weighted: for (int bar = 0; bar < Bars; bar++) price[bar] = (Low[bar] + High[bar] + 2*Close[bar])/4; break; } return price; }
public string DisplayPrice(bool includeAdjustments) { if (OverrideText.Length > 0) { return(OverrideText); } else { if (includeAdjustments) { decimal pricewith = PriceWithAdjustments(); if (pricewith < this.BasePrice) { return("<strike>" + this.BasePrice.ToString("C") + "</strike> " + pricewith.ToString("C")); } else { return(pricewith.ToString("C")); } } else { return(BasePrice.ToString("C")); } } }
/// <summary> /// Returns true if ItemExtraOption instances are equal /// </summary> /// <param name="input">Instance of ItemExtraOption to be compared</param> /// <returns>Boolean</returns> public bool Equals(ItemExtraOption input) { if (input == null) { return(false); } return (( Name == input.Name || Name != null && Name.Equals(input.Name) ) && ( Description == input.Description || Description != null && Description.Equals(input.Description) ) && ( MerchantSuppliedId == input.MerchantSuppliedId || MerchantSuppliedId != null && MerchantSuppliedId.Equals(input.MerchantSuppliedId) ) && ( Active == input.Active || Active != null && Active.Equals(input.Active) ) && ( Price == input.Price || Price != null && Price.Equals(input.Price) ) && ( BasePrice == input.BasePrice || BasePrice != null && BasePrice.Equals(input.BasePrice) ) && ( Default == input.Default || Default != null && Default.Equals(input.Default) ) && ( SortId == input.SortId || SortId != null && SortId.Equals(input.SortId) ) && ( TaxRate == input.TaxRate || TaxRate != null && TaxRate.Equals(input.TaxRate) ) && ( Extras == input.Extras || Extras != null && Extras.SequenceEqual(input.Extras) )); }
public void PrintSummary() { Console.WriteLine("\n The details for this " + Name + " are:\r\n"); Console.WriteLine("\tSIZE: " + Size + "\t\t" + BasePrice.ToString("C") + "\r"); Console.WriteLine("\t\t" + NumberOfSugars + " sugars\t" + (_priceList.SugarPrice * NumberOfSugars).ToString("C") + "\r"); Console.WriteLine("\t\t" + NumberOfCreams + " creams\t" + (_priceList.CreamPrice * NumberOfCreams).ToString("C") + "\r"); Console.WriteLine("\t---------------------------------\r"); Console.WriteLine("\tTOTAL" + "\t\t\t" + TotalPrice.ToString("C") + "\r"); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (Description != null) { hashCode = hashCode * 59 + Description.GetHashCode(); } if (MerchantSuppliedId != null) { hashCode = hashCode * 59 + MerchantSuppliedId.GetHashCode(); } if (Active != null) { hashCode = hashCode * 59 + Active.GetHashCode(); } if (IsAlcohol != null) { hashCode = hashCode * 59 + IsAlcohol.GetHashCode(); } if (IsBikeFriendly != null) { hashCode = hashCode * 59 + IsBikeFriendly.GetHashCode(); } if (SortId != null) { hashCode = hashCode * 59 + SortId.GetHashCode(); } if (Price != null) { hashCode = hashCode * 59 + Price.GetHashCode(); } if (BasePrice != null) { hashCode = hashCode * 59 + BasePrice.GetHashCode(); } if (Extras != null) { hashCode = hashCode * 59 + Extras.GetHashCode(); } if (TaxRate != null) { hashCode = hashCode * 59 + TaxRate.GetHashCode(); } if (OriginalImageUrl != null) { hashCode = hashCode * 59 + OriginalImageUrl.GetHashCode(); } return(hashCode); } }
public void The_Currency_Multiplier_Decorator_Will_Apply_A_Given_Currency_To_A_Price() { IPrice basePrice = new BasePrice { Cost = 100 }; decimal priceAfterDiscountShouldEqual = basePrice.Cost * 0.95m; basePrice = new TradeDiscountPriceDecorator(basePrice); Assert.AreEqual(priceAfterDiscountShouldEqual, basePrice.Cost); }
public void The_Trade_Discount_Decorator_Will_Apply_5_Percent_Discount_To_A_Price() { IPrice basePrice = new BasePrice { Cost = 100 }; decimal priceAfterDiscountShouldEqual = basePrice.Cost * 0.95m; basePrice = new TradeDiscountPriceDecorator(basePrice); Assert.AreEqual(priceAfterDiscountShouldEqual, basePrice.Cost); }
public override int GetHashCode() { unchecked { var hashCode = Id.GetHashCode(); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Description != null ? Description.GetHashCode() : 0); hashCode = (hashCode * 397) ^ BasePrice.GetHashCode(); hashCode = (hashCode * 397) ^ (Toppings != null ? Toppings.GetHashCode() : 0); return(hashCode); } }
public void _setMaterialresource(BasePrice price, double materialRate) { if (materialRate != BASE_MATERIAL_RATE) { _materialRate = materialRate; price.MultiplyBase(1 / _materialRate); } price.ConvertToInt(); UnitBasePrice = price; }
public UnitModel(UnitModel other) { Key = other.Key; Count = other.Count; BasePrice = other.BasePrice.CreateNewFromThis(); UnitStats = other.UnitStats.CreateNewFromThis(); SpriteImages = other.SpriteImages.CreateNewFromThis(); if (other.BattleTechCondidion != null) { BattleTechCondidion = other.BattleTechCondidion.ToDictionary(i => i.Key, i => i.Value); } }
/// <summary> /// Calculates the base price. /// </summary> /// <param name="price">The base price type.</param> /// <returns>Base price.</returns> protected static double[] Price(BasePrice price) { double[] adPrice = new double[Bars]; switch (price) { case BasePrice.Open: adPrice = Open; break; case BasePrice.High: adPrice = High; break; case BasePrice.Low: adPrice = Low; break; case BasePrice.Close: adPrice = Close; break; case BasePrice.Median: for (int bar = 0; bar < Bars; bar++) { adPrice[bar] = (Low[bar] + High[bar]) / 2; } break; case BasePrice.Typical: for (int bar = 0; bar < Bars; bar++) { adPrice[bar] = (Low[bar] + High[bar] + Close[bar]) / 3; } break; case BasePrice.Weighted: for (int bar = 0; bar < Bars; bar++) { adPrice[bar] = (Low[bar] + High[bar] + 2 * Close[bar]) / 4; } break; default: break; } return(adPrice); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (Description != null) { hashCode = hashCode * 59 + Description.GetHashCode(); } if (MerchantSuppliedId != null) { hashCode = hashCode * 59 + MerchantSuppliedId.GetHashCode(); } if (Active != null) { hashCode = hashCode * 59 + Active.GetHashCode(); } if (Price != null) { hashCode = hashCode * 59 + Price.GetHashCode(); } if (BasePrice != null) { hashCode = hashCode * 59 + BasePrice.GetHashCode(); } if (Default != null) { hashCode = hashCode * 59 + Default.GetHashCode(); } if (SortId != null) { hashCode = hashCode * 59 + SortId.GetHashCode(); } if (TaxRate != null) { hashCode = hashCode * 59 + TaxRate.GetHashCode(); } if (Extras != null) { hashCode = hashCode * 59 + Extras.GetHashCode(); } return(hashCode); } }
public bool Equals(Pizza other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Id.Equals(other.Id) && string.Equals(Name, other.Name) && string.Equals(Description, other.Description) && BasePrice.Equals(other.BasePrice) && Toppings.OrderlessSequenceEquals(other.Toppings)); }
public void The_Basket_Item_Should_Caclulate_The_Line_Cost_By_Multipling_The_Product_Price_By_The_Quantity() { decimal productPrice = 100; decimal expectedLineTotal = productPrice * 2; IPrice basePrice = new BasePrice { Cost = productPrice }; Product product = new Product { Price = basePrice }; IBasketItem baseBasketItem = new BasketItem { Product = product, Quantity = 2 }; Assert.AreEqual(expectedLineTotal, baseBasketItem.LineTotal); }
public void If_Basket_Item_Quantity_Is_Zero_The_Line_Total_Should_Be_Zero() { decimal productPrice = 100; decimal expectedLineTotal = 0; IPrice basePrice = new BasePrice { Cost = productPrice }; Product product = new Product { Price = basePrice }; IBasketItem baseBasketItem = new BasketItem { Product = product, Quantity = 0 }; Assert.AreEqual(expectedLineTotal, baseBasketItem.LineTotal); }
public void WriteXml(XmlWriter writer) { // If we reach this point through inventories we definitely have a tile // If we don't have a tile, that means we're writing a character's inventory if (Tile != null) { writer.WriteAttributeString("X", Tile.X.ToString()); writer.WriteAttributeString("Y", Tile.Y.ToString()); writer.WriteAttributeString("Z", Tile.Z.ToString()); } writer.WriteAttributeString("objectType", ObjectType); writer.WriteAttributeString("maxStackSize", MaxStackSize.ToString()); writer.WriteAttributeString("stackSize", StackSize.ToString()); writer.WriteAttributeString("basePrice", BasePrice.ToString()); writer.WriteAttributeString("category", Category); }
/// <summary> /// Calculates the base price. /// </summary> /// <param name="priceType">The base price type.</param> /// <returns>Base price.</returns> protected double[] Price(BasePrice priceType) { var price = new double[Bars]; switch (priceType) { case BasePrice.Open: price = Open; break; case BasePrice.High: price = High; break; case BasePrice.Low: price = Low; break; case BasePrice.Close: price = Close; break; case BasePrice.Median: for (int bar = 0; bar < Bars; bar++) { price[bar] = (Low[bar] + High[bar]) / 2; } break; case BasePrice.Typical: for (int bar = 0; bar < Bars; bar++) { price[bar] = (Low[bar] + High[bar] + Close[bar]) / 3; } break; case BasePrice.Weighted: for (int bar = 0; bar < Bars; bar++) { price[bar] = (Low[bar] + High[bar] + 2 * Close[bar]) / 4; } break; } return(price); }
public void When_Applying_The_BogOffBasktemItemDecorator_If_Basket_Item_Quantity_Is_Zero_The_Line_Total_Should_Be_Zero() { decimal productPrice = 100; decimal expectedLineTotal = 0; IPrice basePrice = new BasePrice { Cost = productPrice }; Product product = new Product { Price = basePrice }; IBasketItem baseBasketItem = new BasketItem { Product = product, Quantity = 0 }; baseBasketItem = new BogOffBasktemItemDecorator(baseBasketItem); Assert.AreEqual(expectedLineTotal, baseBasketItem.LineTotal); }
public void The_BOGOFF_Basket_Item_Decorator_Should_Charge_For_Two_Items_If_There_Are_Three() { decimal productPrice = 100; decimal expectedLineTotal = productPrice * 2; IPrice basePrice = new BasePrice { Cost = productPrice }; Product product = new Product { Price = basePrice }; IBasketItem baseBasketItem = new BasketItem { Product = product, Quantity = 3 }; baseBasketItem = new BogOffBasktemItemDecorator(baseBasketItem); Assert.AreEqual(expectedLineTotal, baseBasketItem.LineTotal); }
public string DisplayPrice(bool includeAdjustments, bool noFormatting) { if (OverrideText.Length > 0) { return(OverrideText); } if (includeAdjustments) { var pricewith = PriceWithAdjustments(); if (pricewith < BasePrice) { return(noFormatting ? pricewith.ToString("F") : string.Format("<strike>{0}</strike> {1}", BasePrice.ToString("C"), pricewith.ToString("C"))); } return(noFormatting ? pricewith.ToString("F") : pricewith.ToString("C")); } return(noFormatting ? BasePrice.ToString("F") : BasePrice.ToString("C")); }
/// end WTF modfication 4 version 4 /// <summary> /// Calculate base price for higher time frame data /// </summary> protected static int HigherBasePrice(BasePrice basePrice, int hBars, double[] hfHigh, double[] hfLow, double[] hfOpen, double[] hfClose, out double[] hfPrice) { hfPrice = new double[Bars]; switch (basePrice) { case BasePrice.Open: hfPrice = hfOpen; break; case BasePrice.Close: hfPrice = hfClose; break; case BasePrice.High: hfPrice = hfHigh; break; case BasePrice.Low: hfPrice = hfLow; break; case BasePrice.Median: for (int iBar = 0; iBar < hBars; iBar++) { hfPrice[iBar] = (hfLow[iBar] + hfHigh[iBar]) / 2; } break; case BasePrice.Typical: for (int iBar = 0; iBar < hBars; iBar++) { hfPrice[iBar] = (hfLow[iBar] + hfHigh[iBar] + hfClose[iBar]) / 3; } break; case BasePrice.Weighted: for (int iBar = 0; iBar < hBars; iBar++) { hfPrice[iBar] = (hfOpen[iBar] + hfLow[iBar] + hfHigh[iBar] + hfClose[iBar]) / 4; } break; default: break; } return(0); }
/// <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; }
public override void Calculate(IDataSet dataSet) { DataSet = dataSet; // Reading the parameters var maMethod = (MAMethod)IndParam.ListParam[1].Index; const BasePrice basePrice = BasePrice.Close; var maPeriod = (int)IndParam.NumParam[0].Value; var atrPeriod = (int)IndParam.NumParam[1].Value; var atrMultiplier = (int)IndParam.NumParam[3].Value; int previous = IndParam.CheckParam[0].Checked ? 1 : 0; // Calculation double[] ma = MovingAverage(maPeriod, 0, maMethod, Price(basePrice)); var atr = new double[Bars]; var upperBand = new double[Bars]; var lowerBand = new double[Bars]; int firstBar = Math.Max(maPeriod, atrPeriod) + previous + 2; for (int bar = 1; bar < Bars; bar++) { atr[bar] = Math.Max(Math.Abs(High[bar] - Close[bar - 1]), Math.Abs(Close[bar - 1] - Low[bar])); atr[bar] = Math.Max(Math.Abs(High[bar] - Low[bar]), atr[bar]); } atr = MovingAverage(atrPeriod, 0, maMethod, atr); for (int bar = maPeriod; bar < Bars; bar++) { upperBand[bar] = ma[bar] + atr[bar] * atrMultiplier; lowerBand[bar] = ma[bar] - atr[bar] * atrMultiplier; } // Saving the components Component = new IndicatorComp[5]; Component[0] = new IndicatorComp { CompName = "Upper Band", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = firstBar, Value = upperBand }; Component[1] = new IndicatorComp { CompName = "Moving Average", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Gold, FirstBar = firstBar, Value = ma }; Component[2] = new IndicatorComp { CompName = "Lower Band", DataType = IndComponentType.IndicatorValue, ChartType = IndChartType.Line, ChartColor = Color.Blue, FirstBar = firstBar, Value = lowerBand }; Component[3] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; Component[4] = new IndicatorComp { ChartType = IndChartType.NoChart, FirstBar = firstBar, Value = new double[Bars] }; // Sets the Component's type if (SlotType == SlotTypes.Open) { Component[3].DataType = IndComponentType.OpenLongPrice; Component[3].CompName = "Long position entry price"; Component[4].DataType = IndComponentType.OpenShortPrice; Component[4].CompName = "Short position entry price"; } else if (SlotType == SlotTypes.OpenFilter) { Component[3].DataType = IndComponentType.AllowOpenLong; Component[3].CompName = "Is long entry allowed"; Component[4].DataType = IndComponentType.AllowOpenShort; Component[4].CompName = "Is short entry allowed"; } else if (SlotType == SlotTypes.Close) { Component[3].DataType = IndComponentType.CloseLongPrice; Component[3].CompName = "Long position closing price"; Component[4].DataType = IndComponentType.CloseShortPrice; Component[4].CompName = "Short position closing price"; } else if (SlotType == SlotTypes.CloseFilter) { Component[3].DataType = IndComponentType.ForceCloseLong; Component[3].CompName = "Close out long position"; Component[4].DataType = IndComponentType.ForceCloseShort; Component[4].CompName = "Close out short position"; } if (SlotType == SlotTypes.Open || SlotType == SlotTypes.Close) { if (maPeriod > 1) { for (int bar = firstBar; bar < Bars; bar++) { // Covers the cases when the price can pass through the band without a signal. double dOpen = Open[bar]; // Current open price // Upper band double valueUp = upperBand[bar - previous]; // Current value double valueUp1 = upperBand[bar - previous - 1]; // Previous value double tempValUp = valueUp; if ((valueUp1 > High[bar - 1] && valueUp < dOpen) || // The Open price jumps above the indicator (valueUp1 <Low[bar - 1] && valueUp> dOpen) || // The Open price jumps below the indicator (Close[bar - 1] < valueUp && valueUp < dOpen) || // The Open price is in a positive gap (Close[bar - 1] > valueUp && valueUp > dOpen)) // The Open price is in a negative gap { tempValUp = dOpen; // The entry/exit level is moved to Open price } // Lower band double valueDown = lowerBand[bar - previous]; // Current value double valueDown1 = lowerBand[bar - previous - 1]; // Previous value double tempValDown = valueDown; if ((valueDown1 > High[bar - 1] && valueDown < dOpen) || // The Open price jumps above the indicator (valueDown1 <Low[bar - 1] && valueDown> dOpen) || // The Open price jumps below the indicator (Close[bar - 1] < valueDown && valueDown < dOpen) || // The Open price is in a positive gap (Close[bar - 1] > valueDown && valueDown > dOpen)) // The Open price is in a negative gap { tempValDown = dOpen; // The entry/exit level is moved to Open price } if (IndParam.ListParam[0].Text == "Enter long at Upper Band" || IndParam.ListParam[0].Text == "Exit long at Upper Band") { Component[3].Value[bar] = tempValUp; Component[4].Value[bar] = tempValDown; } else { Component[3].Value[bar] = tempValDown; Component[4].Value[bar] = tempValUp; } } } else { for (int bar = 2; bar < Bars; bar++) { if (IndParam.ListParam[0].Text == "Enter long at Upper Band" || IndParam.ListParam[0].Text == "Exit long at Upper Band") { Component[3].Value[bar] = upperBand[bar - previous]; Component[4].Value[bar] = lowerBand[bar - previous]; } else { Component[3].Value[bar] = lowerBand[bar - previous]; Component[4].Value[bar] = upperBand[bar - previous]; } } } } else { switch (IndParam.ListParam[0].Text) { case "The bar opens below Upper Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band); break; case "The bar opens above Upper Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band); break; case "The bar opens below Lower Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band); break; case "The bar opens above Lower Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band); break; case "The bar opens below Upper Band after opening above it": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it); break; case "The bar opens above Upper Band after opening below it": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it); break; case "The bar opens below Lower Band after opening above it": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it); break; case "The bar opens above Lower Band after opening below it": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it); break; case "The position opens above Upper Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[2].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens below Upper Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[2].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens above Lower Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The position opens below Lower Band": Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher; Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower; Component[3].DataType = IndComponentType.Other; Component[4].DataType = IndComponentType.Other; Component[3].ShowInDynInfo = false; Component[4].ShowInDynInfo = false; break; case "The bar closes below Upper Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Upper_Band); break; case "The bar closes above Upper Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Upper_Band); break; case "The bar closes below Lower Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Lower_Band); break; case "The bar closes above Lower Band": BandIndicatorLogic(firstBar, previous, upperBand, lowerBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band); break; } } }
/// <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; }
public void RemoveFromBasePrices(BasePrice basePrice) { this.RemoveBasePrice(basePrice); }
public void AddToBasePrice(BasePrice basePrice) { this.AddBasePrice(basePrice); }
/// <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; }
public string GetFormattedBasePrice() => BasePrice.ToString("0.00");
/// <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 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 double[] adBasePrice = Price(basePrice); double[] adMA = new double[Bars]; int iFirstBar = iPeriod + iSmooth + 1 + iPrvs; // Calculating Chande Momentum Oscillator 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]); } } double SC = 2.0 / (iSmooth + 1); for (int iBar = 0; iBar < iPeriod; iBar++) { adMA[iBar] = adBasePrice[iBar]; } for (int iBar = iPeriod; iBar < Bars; iBar++) { double dAbsCMO = Math.Abs(adCMO[iBar]) / 100; adMA[iBar] = SC * dAbsCMO * adBasePrice[iBar] + (1 - SC * dAbsCMO) * adMA[iBar - 1]; } // Saving the components if (slotType == SlotTypes.Open || slotType == SlotTypes.Close) { Component = new IndicatorComp[2]; Component[1] = new IndicatorComp(); Component[1].Value = new double[Bars]; for (int iBar = 2; iBar < Bars; iBar++) { // Covers the cases when the price can pass through the MA without a signal double dValue = adMA[iBar - iPrvs]; // Current value double dValue1 = adMA[iBar - iPrvs - 1]; // Previous value double dTempVal = dValue; if ((dValue1 > High[iBar - 1] && dValue < Open[iBar]) || // It jumps below the current bar (dValue1 <Low[iBar - 1] && dValue> Open[iBar]) || // It jumps above the current bar (Close[iBar - 1] < dValue && dValue < Open[iBar]) || // Positive gap (Close[iBar - 1] > dValue && dValue > Open[iBar])) // Negative gap { dTempVal = Open[iBar]; } Component[1].Value[iBar] = dTempVal; } } else { Component = new IndicatorComp[3]; Component[1] = new IndicatorComp(); Component[1].ChartType = IndChartType.NoChart; Component[1].FirstBar = iFirstBar; Component[1].Value = new double[Bars]; Component[2] = new IndicatorComp(); Component[2].ChartType = IndChartType.NoChart; Component[2].FirstBar = iFirstBar; Component[2].Value = new double[Bars]; } Component[0] = new IndicatorComp(); Component[0].CompName = "MA Value"; Component[0].DataType = IndComponentType.IndicatorValue; Component[0].ChartType = IndChartType.Line; Component[0].ChartColor = Color.Red; Component[0].FirstBar = iFirstBar; Component[0].Value = adMA; if (slotType == SlotTypes.Open) { Component[1].CompName = "Position opening price"; Component[1].DataType = IndComponentType.OpenPrice; } else if (slotType == SlotTypes.OpenFilter) { Component[1].DataType = IndComponentType.AllowOpenLong; Component[1].CompName = "Is long entry allowed"; Component[2].DataType = IndComponentType.AllowOpenShort; Component[2].CompName = "Is short entry allowed"; } else if (slotType == SlotTypes.Close) { Component[1].CompName = "Position closing price"; Component[1].DataType = IndComponentType.ClosePrice; } else if (slotType == SlotTypes.CloseFilter) { Component[1].DataType = IndComponentType.ForceCloseLong; Component[1].CompName = "Close out long position"; Component[2].DataType = IndComponentType.ForceCloseShort; Component[2].CompName = "Close out short position"; } if (slotType == SlotTypes.OpenFilter || slotType == SlotTypes.CloseFilter) { switch (IndParam.ListParam[0].Text) { case "The Vidya Moving Average rises": IndicatorRisesLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The Vidya Moving Average falls": IndicatorFallsLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens above the Vidya Moving Average": BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens below the Vidya Moving Average": BarOpensBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens above the Vidya Moving Average after opening below it": BarOpensAboveIndicatorAfterOpeningBelowLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar opens below the Vidya Moving Average after opening above it": BarOpensBelowIndicatorAfterOpeningAboveLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The position opens above the Vidya Moving Average": Component[0].PosPriceDependence = PositionPriceDependence.BuyHigherSellLower; Component[0].UsePreviousBar = iPrvs; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].DataType = IndComponentType.Other; Component[2].ShowInDynInfo = false; break; case "The position opens below the Vidya Moving Average": Component[0].PosPriceDependence = PositionPriceDependence.BuyLowerSelHigher; Component[0].UsePreviousBar = iPrvs; Component[1].DataType = IndComponentType.Other; Component[1].ShowInDynInfo = false; Component[2].DataType = IndComponentType.Other; Component[2].ShowInDynInfo = false; break; case "The bar closes below the Vidya Moving Average": BarClosesBelowIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; case "The bar closes above the Vidya Moving Average": BarClosesAboveIndicatorLogic(iFirstBar, iPrvs, adMA, ref Component[1], ref Component[2]); break; default: break; } } return; }
public static void RemoveFromBasePrices(this Service @this, BasePrice basePrice) { @this.RemoveBasePrice(basePrice); }
/// <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; }
public static void AddToBasePrice(this Service @this, BasePrice basePrice) { @this.AddBasePrice(basePrice); }