public override void Calculate(SlotTypes slotType)
{
int iTenkan = (int)IndParam.NumParam[0].Value;
int iKijun = (int)IndParam.NumParam[2].Value;
int iSenkou = (int)IndParam.NumParam[4].Value;
int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
double[] adMedianPrice = Price(BasePrice.Median);
int iFirstBar = 1 + iKijun + iSenkou;
double[] adTenkanSen = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
double dHighestHigh = double.MinValue;
double dLowestLow = double.MaxValue;
for (int i = 0; i < iTenkan; i++)
{
if (High[iBar - i] > dHighestHigh)
dHighestHigh = High[iBar - i];
if (Low[iBar - i] < dLowestLow)
dLowestLow = Low[iBar - i];
}
adTenkanSen[iBar] = (dHighestHigh + dLowestLow) / 2;
}
double[] adKijunSen = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
double dHighestHigh = double.MinValue;
double dLowestLow = double.MaxValue;
for (int i = 0; i < iKijun; i++)
{
if (High[iBar - i] > dHighestHigh)
dHighestHigh = High[iBar - i];
if (Low[iBar - i] < dLowestLow)
dLowestLow = Low[iBar - i];
}
adKijunSen[iBar] = (dHighestHigh + dLowestLow) / 2;
}
double[] adChikouSpan = new double[Bars];
for (int iBar = 0; iBar < Bars - iKijun; iBar++)
{
adChikouSpan[iBar] = Close[iBar + iKijun];
}
double[] adSenkouSpanA = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++)
{
adSenkouSpanA[iBar + iKijun] = (adTenkanSen[iBar] + adKijunSen[iBar]) / 2;
}
double[] adSenkouSpanB = new double[Bars];
for (int iBar = iFirstBar; iBar < Bars - iKijun; iBar++)
{
double dHighestHigh = double.MinValue;
double dLowestLow = double.MaxValue;
for (int i = 0; i < iSenkou; i++)
{
if (High[iBar - i] > dHighestHigh)
dHighestHigh = High[iBar - i];
if (Low[iBar - i] < dLowestLow)
dLowestLow = Low[iBar - i];
}
adSenkouSpanB[iBar + iKijun] = (dHighestHigh + dLowestLow) / 2;
}
// Saving the components
if (slotType == SlotTypes.OpenFilter)
Component = new IndicatorComp[7];
else
Component = new IndicatorComp[6];
Component[0] = new IndicatorComp();
Component[0].CompName = "Tenkan Sen";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.Red;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adTenkanSen;
Component[1] = new IndicatorComp();
Component[1].CompName = "Kijun Sen";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.Blue;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adKijunSen;
Component[2] = new IndicatorComp();
Component[2].CompName = "Chikou Span";
Component[2].DataType = IndComponentType.IndicatorValue;
Component[2].ChartType = IndChartType.Line;
Component[2].ChartColor = Color.Green;
Component[2].FirstBar = iFirstBar;
Component[2].Value = adChikouSpan;
Component[3] = new IndicatorComp();
Component[3].CompName = "Senkou Span A";
Component[3].DataType = IndComponentType.IndicatorValue;
Component[3].ChartType = IndChartType.CloudUp;
Component[3].ChartColor = Color.SandyBrown;
Component[3].FirstBar = iFirstBar;
Component[3].Value = adSenkouSpanA;
Component[4] = new IndicatorComp();
Component[4].CompName = "Senkou Span B";
Component[4].DataType = IndComponentType.IndicatorValue;
Component[4].ChartType = IndChartType.CloudDown;
Component[4].ChartColor = Color.Thistle;
Component[4].FirstBar = iFirstBar;
Component[4].Value = adSenkouSpanB;
Component[5] = new IndicatorComp();
Component[5].FirstBar = iFirstBar;
Component[5].Value = new double[Bars];
Component[5].DataType = IndComponentType.Other;
if (slotType == SlotTypes.OpenFilter)
{
Component[5].CompName = "Is long entry allowed";
Component[5].DataType = IndComponentType.AllowOpenLong;
Component[6] = new IndicatorComp();
Component[6].FirstBar = iFirstBar;
Component[6].Value = new double[Bars];
Component[6].CompName = "Is short entry allowed";
Component[6].DataType = IndComponentType.AllowOpenShort;
}
switch (IndParam.ListParam[0].Text)
{
case "Enter the market at the Tenkan Sen":
Component[5].CompName = "Tenkan Sen entry price";
Component[5].DataType = IndComponentType.OpenPrice;
Component[5].ChartType = IndChartType.NoChart;
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs];
}
break;
case "Enter the market at the Kijun Sen":
Component[5].CompName = "Kijun Sen entry price";
Component[5].DataType = IndComponentType.OpenPrice;
Component[5].ChartType = IndChartType.NoChart;
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adKijunSen[iBar - iPrvs];
}
break;
case "Exit the market at the Tenkan Sen":
Component[5].CompName = "Tenkan Sen exit price";
Component[5].DataType = IndComponentType.ClosePrice;
Component[5].ChartType = IndChartType.NoChart;
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs];
}
break;
case "Exit the market at the Kijun Sen":
Component[5].CompName = "Kijun Sen exit price";
Component[5].DataType = IndComponentType.ClosePrice;
Component[5].ChartType = IndChartType.NoChart;
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adKijunSen[iBar - iPrvs];
}
break;
case "The Tenkan Sen rises":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > adTenkanSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < adTenkanSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0;
}
break;
case "The Kijun Sen rises":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > adKijunSen[iBar - iPrvs - 1] + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < adKijunSen[iBar - iPrvs - 1] - Sigma() ? 1 : 0;
}
break;
case "The Tenkan Sen is higher than the Kijun Sen":
IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]);
break;
case "The Tenkan Sen crosses the Kijun Sen upward":
IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adTenkanSen, adKijunSen, ref Component[5], ref Component[6]);
break;
case "The bar opens above the Tenkan Sen":
BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adTenkanSen, ref Component[5], ref Component[6]);
break;
case "The bar opens above the Kijun Sen":
BarOpensAboveIndicatorLogic(iFirstBar, iPrvs, adKijunSen, ref Component[5], ref Component[6]);
break;
case "The Chikou Span is above the closing price":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] > Close[iBar - iKijun - iPrvs] + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adChikouSpan[iBar - iKijun - iPrvs] < Close[iBar - iKijun - iPrvs] - Sigma() ? 1 : 0;
}
break;
case "The position opens above the Kumo":
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
Component[6].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
}
Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[5].DataType = IndComponentType.Other;
Component[5].UsePreviousBar = iPrvs;
Component[5].ShowInDynInfo = false;
Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[6].DataType = IndComponentType.Other;
Component[6].UsePreviousBar = iPrvs;
Component[6].ShowInDynInfo = false;
break;
case "The position opens inside or above the Kumo":
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = Math.Min(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
Component[6].Value[iBar] = Math.Max(adSenkouSpanA[iBar], adSenkouSpanB[iBar]);
}
Component[5].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[5].DataType = IndComponentType.Other;
Component[5].UsePreviousBar = iPrvs;
Component[5].ShowInDynInfo = false;
Component[6].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[6].DataType = IndComponentType.Other;
Component[6].UsePreviousBar = iPrvs;
Component[6].ShowInDynInfo = false;
break;
case "The Tenkan Sen is above the Kumo":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
}
break;
case "The Tenkan Sen is inside or above the Kumo":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adTenkanSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adTenkanSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
}
break;
case "The Kijun Sen is above the Kumo":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
}
break;
case "The Kijun Sen is inside or above the Kumo":
for (int iBar = iFirstBar + iPrvs; iBar < Bars; iBar++)
{
Component[5].Value[iBar] = adKijunSen[iBar - iPrvs] > Math.Min(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) + Sigma() ? 1 : 0;
Component[6].Value[iBar] = adKijunSen[iBar - iPrvs] < Math.Max(adSenkouSpanA[iBar - iPrvs], adSenkouSpanB[iBar - iPrvs]) - Sigma() ? 1 : 0;
}
break;
case "The Senkou Span A is higher than the Senkou Span B":
IndicatorIsHigherThanAnotherIndicatorLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]);
break;
case "The Senkou Span A crosses the Senkou Span B upward":
IndicatorCrossesAnotherIndicatorUpwardLogic(iFirstBar, iPrvs, adSenkouSpanA, adSenkouSpanB, ref Component[5], ref Component[6]);
break;
default:
break;
}
return;
}