Source »
Data Bars Filter - source code
// Forex Strategy Builder
// Copyright (c) 2006 - 2008 Miroslav Popov - All rights reserved!
// http://forexsb.com
// info(a)forexsb.com
//
// Last changed on: 2007-01-17
using System;
using System.Drawing;
namespace Forex_Strategy_Builder
{
/// <summary>
/// indicator: Data Bars Filter
/// </summary>
public class Data_Bars_Filter : Indicator
{
/// <summary>
/// The default constructor.
/// </summary>
public Data_Bars_Filter()
{
}
/// <summary>
/// Sets the default parameters for the designated slot type.
/// </summary>
/// <param name="slotType">The slot type.</param>
public Data_Bars_Filter(SlotTypes slotType)
{
sIndicatorName = "Data Bars Filter";
parameters = new IndicatorParam();
component = new IndicatorComp[] { };
bIsCalculated = false;
typeOfIndicator = TypeOfIndicator.DateTime;
// The indicator name.
parameters.IndicatorName = sIndicatorName;
// The slot type.
parameters.SlotType = slotType;
// The ComboBox parameters.
parameters.ListParam[0].Caption = "Logic";
parameters.ListParam[0].ItemList = new string[]
{
"Do not use the newest 'n' bars",
"Do not use the oldest 'm' bars",
"Do not use the newest 'n' bars and oldest 'm' bars",
"Use the newest 'n' bars only",
};
parameters.ListParam[0].Index = 0;
parameters.ListParam[0].Text = parameters.ListParam[0].ItemList[parameters.ListParam[0].Index];
parameters.ListParam[0].Enabled = true;
parameters.ListParam[0].ToolTip = "Specify the entry bars";
// The NumericUpDown parameters.
parameters.NumParam[0].Caption = "Newest 'n' bars";
parameters.NumParam[0].Value = 1000;
parameters.NumParam[0].Min = 0;
parameters.NumParam[0].Max = 100000;
parameters.NumParam[0].Enabled = true;
parameters.NumParam[0].ToolTip = "The number of newest bars";
parameters.NumParam[1].Caption = "Oldest 'm' bars";
parameters.NumParam[1].Value = 0;
parameters.NumParam[1].Min = 0;
parameters.NumParam[1].Max = 100000;
parameters.NumParam[1].Enabled = true;
parameters.NumParam[1].ToolTip = "The number of oldest bars";
}
/// <summary>
/// Calculates the indicator's components.
/// </summary>
/// <param name="slotType">The slot type.</param>
public override void Calculate(SlotTypes slotType)
{
if (parameters.SlotType == SlotTypes.NotDefined) return;
// Reading the parameters
int iNewest = (int)parameters.NumParam[0].Value;
int iOldest = (int)parameters.NumParam[1].Value;
// Calculation
int iFirstBar = 0;
float[] afBars = new float[Bars];
// Calculation of the logic.
switch (parameters.ListParam[0].Text)
{
case "Use the newest 'n' bars only":
iFirstBar = (int)Math.Max(0, Bars - iNewest);
iFirstBar = (int)Math.Min(iFirstBar, Bars - 300);
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
afBars[iBar] = 1;
}
break;
case "Do not use the newest 'n' bars":
for (int iBar = iFirstBar; iBar < Bars - iNewest; iBar++)
{
afBars[iBar] = 1;
}
break;
case "Do not use the oldest 'm' bars":
iFirstBar = (int)Math.Min(iOldest, Bars - 300);
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{
afBars[iBar] = 1;
}
break;
case "Do not use the newest 'n' bars and oldest 'm' bars":
iFirstBar = (int)Math.Min(iOldest, Bars - 300);
int iLastBar = (int)Math.Max(iFirstBar + 300, Bars - iNewest);
for (int iBar = iFirstBar; iBar < iLastBar; iBar++)
{
afBars[iBar] = 1;
}
break;
default:
break;
}
// Saving the components
component = new IndicatorComp[2];
component[0] = new IndicatorComp();
component[0].CompName = "(No) Used bars";
component[0].DataType = IndComponentType.AllowOpenLong;
component[0].ChartType = IndChartType.NoChart;
component[0].ShowInDynInfo = false;
component[0].FirstBar = iFirstBar;
component[0].Value = afBars;
component[1] = new IndicatorComp();
component[1].CompName = "(No) Used bars";
component[1].DataType = IndComponentType.AllowOpenShort;
component[1].ChartType = IndChartType.NoChart;
component[1].ShowInDynInfo = false;
component[1].FirstBar = iFirstBar;
component[1].Value = afBars;
bIsCalculated = true;
}
}
}
Top