public override void Calculate(SlotTypes slotType)
{
int iFromHour = (int)IndParam.NumParam[0].Value;
int iFromMin = (int)IndParam.NumParam[1].Value;
int iUntilHour = (int)IndParam.NumParam[2].Value;
int iUntilMin = (int)IndParam.NumParam[3].Value;
TimeSpan tsFromTime = new TimeSpan(iFromHour, iFromMin, 0);
TimeSpan tsUntilTime = new TimeSpan(iUntilHour, iUntilMin, 0);
double dShift = IndParam.NumParam[4].Value * Point;
int iFirstBar = 2;
// Calculation
double[] adHighPrice = new double[Bars];
double[] adLowPrice = new double[Bars];
double dMinPrice = double.MaxValue;
double dMaxPrice = double.MinValue;
adHighPrice[0] = 0;
adLowPrice[0] = 0;
bool bPrevPeriod = false;
for (int iBar = 1; iBar < Bars; iBar++)
{
bool bPeriod = false;
if (tsFromTime < tsUntilTime)
bPeriod = Time[iBar].TimeOfDay >= tsFromTime && Time[iBar].TimeOfDay < tsUntilTime;
else if (tsFromTime > tsUntilTime)
bPeriod = Time[iBar].TimeOfDay >= tsFromTime || Time[iBar].TimeOfDay < tsUntilTime;
else
bPeriod = true;
if (bPeriod)
{
if (dMaxPrice < High[iBar]) dMaxPrice = High[iBar];
if (dMinPrice > Low[iBar]) dMinPrice = Low[iBar];
}
if (!bPeriod && bPrevPeriod)
{
adHighPrice[iBar] = dMaxPrice;
adLowPrice[iBar] = dMinPrice;
dMaxPrice = double.MinValue;
dMinPrice = double.MaxValue;
}
else
{
adHighPrice[iBar] = adHighPrice[iBar - 1];
adLowPrice[iBar] = adLowPrice[iBar - 1];
}
bPrevPeriod = bPeriod;
}
// Shifting the price
double[] adUpperBand = new double[Bars];
double[] adLowerBand = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
adUpperBand[iBar] = adHighPrice[iBar] + dShift;
adLowerBand[iBar] = adLowPrice[iBar] - dShift;
}
// Saving the components
Component = new IndicatorComp[4];
Component[0] = new IndicatorComp();
Component[0].CompName = "Hourly High";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Level;
Component[0].ChartColor = Color.DarkGreen;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adHighPrice;
Component[1] = new IndicatorComp();
Component[1].CompName = "Hourly Low";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Level;
Component[1].ChartColor = Color.DarkRed;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adLowPrice;
Component[2] = new IndicatorComp();
Component[2].ChartType = IndChartType.NoChart;
Component[2].FirstBar = iFirstBar;
Component[2].Value = new double[Bars];
Component[3] = new IndicatorComp();
Component[3].ChartType = IndChartType.NoChart;
Component[3].FirstBar = iFirstBar;
Component[3].Value = new double[Bars];
// Sets the Component's type
if (slotType == SlotTypes.Open)
{
Component[2].CompName = "Long position entry price";
Component[2].DataType = IndComponentType.OpenLongPrice;
Component[3].CompName = "Short position entry price";
Component[3].DataType = IndComponentType.OpenShortPrice;
}
else if (slotType == SlotTypes.OpenFilter)
{
Component[2].CompName = "Is long entry allowed";
Component[2].DataType = IndComponentType.AllowOpenLong;
Component[3].CompName = "Is short entry allowed";
Component[3].DataType = IndComponentType.AllowOpenShort;
}
else if (slotType == SlotTypes.Close)
{
Component[2].CompName = "Long position closing price";
Component[2].DataType = IndComponentType.CloseLongPrice;
Component[3].CompName = "Short position closing price";
Component[3].DataType = IndComponentType.CloseShortPrice;
}
else if (slotType == SlotTypes.CloseFilter)
{
Component[2].CompName = "Close out long position";
Component[2].DataType = IndComponentType.ForceCloseLong;
Component[3].CompName = "Close out short position";
Component[3].DataType = IndComponentType.ForceCloseShort;
}
switch (IndParam.ListParam[0].Text)
{
case "Enter long at the hourly high":
case "Exit long at the hourly high":
Component[2].Value = adUpperBand;
Component[3].Value = adLowerBand;
break;
case "Enter long at the hourly low":
case "Exit long at the hourly low":
Component[2].Value = adLowerBand;
Component[3].Value = adUpperBand;
break;
case "The bar closes below the hourly high":
BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Upper_Band);
break;
case "The bar closes above the hourly high":
BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Upper_Band);
break;
case "The bar closes below the hourly low":
BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_below_the_Lower_Band);
break;
case "The bar closes above the hourly low":
BandIndicatorLogic(iFirstBar, 0, adUpperBand, adLowerBand, ref Component[2], ref Component[3], BandIndLogic.The_bar_closes_above_the_Lower_Band);
break;
case "The position opens above the hourly high":
Component[0].DataType = IndComponentType.Other;
Component[1].DataType = IndComponentType.Other;
Component[2].CompName = "Shifted hourly high";
Component[2].DataType = IndComponentType.Other;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[3].CompName = "Shifted hourly low";
Component[3].DataType = IndComponentType.Other;
Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[2].Value = adUpperBand;
Component[3].Value = adLowerBand;
break;
case "The position opens below the hourly high":
Component[0].DataType = IndComponentType.Other;
Component[1].DataType = IndComponentType.Other;
Component[2].CompName = "Shifted hourly high";
Component[2].DataType = IndComponentType.Other;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[3].CompName = "Shifted hourly low";
Component[3].DataType = IndComponentType.Other;
Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[2].Value = adUpperBand;
Component[3].Value = adLowerBand;
break;
case "The position opens above the hourly low":
Component[0].DataType = IndComponentType.Other;
Component[1].DataType = IndComponentType.Other;
Component[2].CompName = "Shifted hourly low";
Component[2].DataType = IndComponentType.Other;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[3].CompName = "Shifted hourly high";
Component[3].DataType = IndComponentType.Other;
Component[3].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[2].Value = adLowerBand;
Component[3].Value = adUpperBand;
break;
case "The position opens below the hourly low":
Component[0].DataType = IndComponentType.Other;
Component[1].DataType = IndComponentType.Other;
Component[2].CompName = "Shifted hourly low";
Component[2].DataType = IndComponentType.Other;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[3].CompName = "Shifted hourly high";
Component[3].DataType = IndComponentType.Other;
Component[3].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[2].Value = adLowerBand;
Component[3].Value = adUpperBand;
break;
default:
break;
}
return;
}