Topic: customize Indicators
Hello,
unfortunately I cant find the Indicator data files which are preinstalled on FSB to build my own custom Indicators. Is this on purpose, or am I too dumb to find the files?
Create and Test Forex Strategies
You are not logged in. Please login or register.
Forex Software → Technical Indicators → customize Indicators
Hello,
unfortunately I cant find the Indicator data files which are preinstalled on FSB to build my own custom Indicators. Is this on purpose, or am I too dumb to find the files?
Look there ->http://forexsb.com/forum/topic/2189/for … urce-code/
could you post the link were I can find the sourcecode for the indies for FSB3.0 which are regularely preinstalled, please.
thank you
Sticky topic in this section! Right under your nose
I tried to translate an Indicator
FSB says :
Custom Indicators
File name: steady bands neu.cs
ERROR: Obsolete format of source code in file [steady bands neu.cs].
Get a newer version from Code Repository.
Were is the mistake?
// Steady Bands Indicator neu
// Last changed on 2009-12-15
// Part of Forex Strategy Builder & Forex Strategy Trader
// Website http://forexsb.com/
// Copyright (c) 2006 - 2009 Miroslav Popov - All rights reserved.
// This code or any part of it cannot be used in other applications without a permission.
using System;
using System.Drawing;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
/// <summary>
/// Steady Bands neu Indicator
/// </summary>
public class Steady_Bands_neu : Indicator
{
/// <summary>
/// Sets the default indicator parameters for the designated slot type
/// </summary>
public Steady_Bands_neu()
{
// General properties
IndicatorName = "Steady Bands neu";
PossibleSlots = SlotTypes.Open | SlotTypes.OpenFilter | SlotTypes.Close | SlotTypes.CloseFilter;
CustomIndicator = true;
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
if (slotType == SlotTypes.Open)
IndParam.ListParam[0].ItemList = new string[]
{
"Enter long at the Upper Band",
"Enter long at the Lower Band"
};
else if (slotType == SlotTypes.OpenFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar opens below the Upper Band",
"The bar opens above the Upper Band",
"The bar opens below the Lower Band",
"The bar opens above the Lower Band",
"The position opens below the Upper Band",
"The position opens above the Upper Band",
"The position opens below the Lower Band",
"The position opens above the Lower Band",
"The bar opens below the Upper Band after opening above it",
"The bar opens above the Upper Band after opening below it",
"The bar opens below the Lower Band after opening above it",
"The bar opens above the Lower Band after opening below it",
};
else if (slotType == SlotTypes.Close)
IndParam.ListParam[0].ItemList = new string[]
{
"Exit long at the Upper Band",
"Exit long at the Lower Band"
};
else if (slotType == SlotTypes.CloseFilter)
IndParam.ListParam[0].ItemList = new string[]
{
"The bar closes below the Upper Band",
"The bar closes above the Upper Band",
"The bar closes below the Lower Band",
"The bar closes above the Lower Band"
};
else
IndParam.ListParam[0].ItemList = new string[]
{
"Not Defined"
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
IndParam.ListParam[1].Caption = "Smoothing method";
IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(MAMethod));
IndParam.ListParam[1].Index = 0;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The method of smoothing of central Moving Average.";
IndParam.ListParam[2].Caption = "Base price";
IndParam.ListParam[2].ItemList = Enum.GetNames(typeof(BasePrice));
IndParam.ListParam[2].Index = 3;
IndParam.ListParam[2].Text = IndParam.ListParam[2].ItemList[IndParam.ListParam[2].Index];
IndParam.ListParam[2].Enabled = true;
IndParam.ListParam[2].ToolTip = "The price the central Moving Average is based on.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "MA period";
IndParam.NumParam[0].Value = 20;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 12000;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The central Moving Average period.";
IndParam.NumParam[1].Caption = "Margin in pips";
IndParam.NumParam[1].Value = 40;
IndParam.NumParam[1].Min = 1;
IndParam.NumParam[1].Max = 2000;
IndParam.NumParam[1].Point = 0;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "Determines the distance between the ME and the Upper (Lower) Band.";
// The CheckBox parameters
IndParam.CheckParam[0].Caption = "Use previous bar value";
IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
IndParam.CheckParam[0].Enabled = true;
IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
return;
}
/// <summary>
/// Calculates the indicator's components
/// </summary>
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
MAMethod maMethod = (MAMethod )IndParam.ListParam[1].Index;
BasePrice price = (BasePrice)IndParam.ListParam[2].Index;
int nMA = (int)IndParam.NumParam[0].Value;
double dMargin = IndParam.NumParam[1].Value * Point;
int iPrvs = IndParam.CheckParam[0].Checked ? 1 : 0;
// Calculation
double[] adMA = MovingAverage(nMA, 0, maMethod, Price(price));
double[] adUpBand = new double[Bars];
double[] adDnBand = new double[Bars];
int iFirstBar = nMA + iPrvs + 2;
for (int iBar = nMA; iBar < Bars; iBar++)
{
adUpBand[iBar] = adMA[iBar] + dMargin;
adDnBand[iBar] = adMA[iBar] - dMargin;
}
// Saving the components
Component = new IndicatorComp[5];
Component[0] = new IndicatorComp();
Component[0].CompName = "Upper Band";
Component[0].DataType = IndComponentType.IndicatorValue;
Component[0].ChartType = IndChartType.Line;
Component[0].ChartColor = Color.Blue;
Component[0].FirstBar = iFirstBar;
Component[0].Value = adUpBand;
Component[1] = new IndicatorComp();
Component[1].CompName = "Moving Average";
Component[1].DataType = IndComponentType.IndicatorValue;
Component[1].ChartType = IndChartType.Line;
Component[1].ChartColor = Color.Gold;
Component[1].FirstBar = iFirstBar;
Component[1].Value = adMA;
Component[2] = new IndicatorComp();
Component[2].CompName = "Lower Band";
Component[2].DataType = IndComponentType.IndicatorValue;
Component[2].ChartType = IndChartType.Line;
Component[2].ChartColor = Color.Blue;
Component[2].FirstBar = iFirstBar;
Component[2].Value = adDnBand;
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.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 (nMA > 1)
{
for (int iBar = iFirstBar; iBar < Bars; iBar++)
{ // Covers the cases when the price can pass through the band without a signal.
double dOpen = Open[iBar]; // Current open price
// Upper band
double dValueUp = adUpBand[iBar - iPrvs]; // Current value
double dValueUp1 = adUpBand[iBar - iPrvs - 1]; // Previous value
double dTempValUp = dValueUp;
if ((dValueUp1 > High[iBar - 1] && dValueUp < dOpen) || // The Open price jumps above the indicator
(dValueUp1 < Low[iBar - 1] && dValueUp > dOpen) || // The Open price jumps below the indicator
(Close[iBar - 1] < dValueUp && dValueUp < dOpen) || // The Open price is in a positive gap
(Close[iBar - 1] > dValueUp && dValueUp > dOpen)) // The Open price is in a negative gap
dTempValUp = dOpen; // The entry/exit level is moved to Open price
// Lower band
double dValueDown = adDnBand[iBar - iPrvs]; // Current value
double dValueDown1 = adDnBand[iBar - iPrvs - 1]; // Previous value
double dTempValDown = dValueDown;
if ((dValueDown1 > High[iBar - 1] && dValueDown < dOpen) || // The Open price jumps above the indicator
(dValueDown1 < Low[iBar - 1] && dValueDown > dOpen) || // The Open price jumps below the indicator
(Close[iBar - 1] < dValueDown && dValueDown < dOpen) || // The Open price is in a positive gap
(Close[iBar - 1] > dValueDown && dValueDown > dOpen)) // The Open price is in a negative gap
dTempValDown = dOpen; // The entry/exit level is moved to Open price
if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
IndParam.ListParam[0].Text == "Exit long at the Upper Band")
{
Component[3].Value[iBar] = dTempValUp;
Component[4].Value[iBar] = dTempValDown;
}
else
{
Component[3].Value[iBar] = dTempValDown;
Component[4].Value[iBar] = dTempValUp;
}
}
}
else
{
for (int iBar = 2; iBar < Bars; iBar++)
{
if (IndParam.ListParam[0].Text == "Enter long at the Upper Band" ||
IndParam.ListParam[0].Text == "Exit long at the Upper Band")
{
Component[3].Value[iBar] = adUpBand[iBar - iPrvs];
Component[4].Value[iBar] = adDnBand[iBar - iPrvs];
}
else
{
Component[3].Value[iBar] = adDnBand[iBar - iPrvs];
Component[4].Value[iBar] = adUpBand[iBar - iPrvs];
}
}
}
}
else
{
switch (IndParam.ListParam[0].Text)
{
case "The bar opens below the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band);
break;
case "The bar opens above the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band);
break;
case "The bar opens below the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band);
break;
case "The bar opens above the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band);
break;
case "The bar opens below the Upper Band after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Upper_Band_after_opening_above_it);
break;
case "The bar opens above the Upper Band after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Upper_Band_after_opening_below_it);
break;
case "The bar opens below the Lower Band after opening above it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_below_the_Lower_Band_after_opening_above_it);
break;
case "The bar opens above the Lower Band after opening below it":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_opens_above_the_Lower_Band_after_opening_below_it);
break;
case "The position opens above the Upper Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[2].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[3].DataType = IndComponentType.Other;
Component[4].DataType = IndComponentType.Other;
Component[3].ShowInDynInfo = false;
Component[4].ShowInDynInfo = false;
break;
case "The position opens below the Upper Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[2].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[3].DataType = IndComponentType.Other;
Component[4].DataType = IndComponentType.Other;
Component[3].ShowInDynInfo = false;
Component[4].ShowInDynInfo = false;
break;
case "The position opens above the Lower Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellLower;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyHigher;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[3].DataType = IndComponentType.Other;
Component[4].DataType = IndComponentType.Other;
Component[3].ShowInDynInfo = false;
Component[4].ShowInDynInfo = false;
break;
case "The position opens below the Lower Band":
Component[0].PosPriceDependence = PositionPriceDependence.PriceSellHigher;
Component[2].PosPriceDependence = PositionPriceDependence.PriceBuyLower;
Component[0].UsePreviousBar = iPrvs;
Component[2].UsePreviousBar = iPrvs;
Component[3].DataType = IndComponentType.Other;
Component[4].DataType = IndComponentType.Other;
Component[3].ShowInDynInfo = false;
Component[4].ShowInDynInfo = false;
break;
case "The bar closes below the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Upper_Band);
break;
case "The bar closes above the Upper Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Upper_Band);
break;
case "The bar closes below the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_below_the_Lower_Band);
break;
case "The bar closes above the Lower Band":
BandIndicatorLogic(iFirstBar, iPrvs, adUpBand, adDnBand, ref Component[3], ref Component[4], BandIndLogic.The_bar_closes_above_the_Lower_Band);
break;
default:
break;
}
}
return;
}
/// <summary>
/// Sets the indicator logic description
/// </summary>
public override void SetDescription()
{
switch (IndParam.ListParam[0].Text)
{
case "Enter long at the Upper Band":
EntryPointLongDescription = "at the Upper Band of " + ToString();
EntryPointShortDescription = "at the Lower Band of " + ToString();
break;
case "Enter long at the Lower Band":
EntryPointLongDescription = "at the Lower Band of " + ToString();
EntryPointShortDescription = "at the Upper Band of " + ToString();
break;
case "Exit long at the Upper Band":
ExitPointLongDescription = "at the Upper Band of " + ToString();
ExitPointShortDescription = "at the Lower Band of " + ToString();
break;
case "Exit long at the Lower Band":
ExitPointLongDescription = "at the Lower Band of " + ToString();
ExitPointShortDescription = "at the Upper Band of " + ToString();
break;
case "The bar opens below the Upper Band":
EntryFilterLongDescription = "the bar opens below the Upper Band of " + ToString();
EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString();
break;
case "The bar opens above the Upper Band":
EntryFilterLongDescription = "the bar opens above the Upper Band of " + ToString();
EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString();
break;
case "The bar opens below the Lower Band":
EntryFilterLongDescription = "the bar opens below the Lower Band of " + ToString();
EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString();
break;
case "The bar opens above the Lower Band":
EntryFilterLongDescription = "the bar opens above the Lower Band of " + ToString();
EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString();
break;
case "The position opens above the Upper Band":
EntryFilterLongDescription = "the position opening price is higher than the Upper Band of " + ToString();
EntryFilterShortDescription = "the position opening price is lower than the Lower Band of " + ToString();
break;
case "The position opens below the Upper Band":
EntryFilterLongDescription = "the position opening price is lower than the Upper Band of " + ToString();
EntryFilterShortDescription = "the position opening price is higher than the Lower Band of " + ToString();
break;
case "The position opens above the Lower Band":
EntryFilterLongDescription = "the position opening price is higher than the Lower Band of " + ToString();
EntryFilterShortDescription = "the position opening price is lower than the Upper Band of " + ToString();
break;
case "The position opens below the Lower Band":
EntryFilterLongDescription = "the position opening price is lower than the Lower Band of " + ToString();
EntryFilterShortDescription = "the position opening price is higher than the Upper Band of " + ToString();
break;
case "The bar opens below the Upper Band after opening above it":
EntryFilterLongDescription = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Upper Band after opening below it":
EntryFilterLongDescription = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar opens below the Lower Band after opening above it":
EntryFilterLongDescription = "the bar opens below the Lower Band of " + ToString() + " after the previous bar has opened above it";
EntryFilterShortDescription = "the bar opens above the Upper Band of " + ToString() + " after the previous bar has opened below it";
break;
case "The bar opens above the Lower Band after opening below it":
EntryFilterLongDescription = "the bar opens above the Lower Band of " + ToString() + " after the previous bar has opened below it";
EntryFilterShortDescription = "the bar opens below the Upper Band of " + ToString() + " after the previous bar has opened above it";
break;
case "The bar closes below the Upper Band":
ExitFilterLongDescription = "the bar closes below the Upper Band of " + ToString();
ExitFilterShortDescription = "the bar closes above the Lower Band of " + ToString();
break;
case "The bar closes above the Upper Band":
ExitFilterLongDescription = "the bar closes above the Upper Band of " + ToString();
ExitFilterShortDescription = "the bar closes below the Lower Band of " + ToString();
break;
case "The bar closes below the Lower Band":
ExitFilterLongDescription = "the bar closes below the Lower Band of " + ToString();
ExitFilterShortDescription = "the bar closes above the Upper Band of " + ToString();
break;
case "The bar closes above the Lower Band":
ExitFilterLongDescription = "the bar closes above the Lower Band of " + ToString();
ExitFilterShortDescription = "the bar closes below the Upper Band of " + ToString();
break;
default:
break;
}
return;
}
/// <summary>
/// Indicator to string
/// </summary>
public override string ToString()
{
string sString = IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.ListParam[1].Text + ", " + // Method
IndParam.ListParam[2].Text + ", " + // Price
IndParam.NumParam[0].ValueToString + ", " + // MA period
IndParam.NumParam[1].ValueToString + ")"; // Margin in Pips
return sString;
}
}
}
Errors:
Line 121 Column 46: The name 'PrepareUsePrevBarValueCheckBox' does not exist in the current context.
Line 193 Column 17: The name 'slotType' does not exist in the current context.
Line 200 Column 22: The name 'slotType' does not exist in the current context.
Line 207 Column 22: The name 'slotType' does not exist in the current context.
Line 214 Column 22: The name 'slotType' does not exist in the current context.
Line 222 Column 17: The name 'slotType' does not exist in the current context.
Line 222 Column 47: The name 'slotType' does not exist in the current context.
Remove:
IndParam.CheckParam[0].Checked = PrepareUsePrevBarValueCheckBox(slotType);
Line and rename slotType to SlotType on the shown places.
BTW when i install FSB pro are the indicators in new format already
or do I need to download them from repo and overwrite?
FSB Pro uses the same indicators as FSB v3.0 and FST v 3.0. There are problems with Spread Level indicator. Current WTF indicators do not work with FSB Pro. They can be fixed, but it's pointless since FSB Pro includes same functionality, but much better implemented. FSB Pro doesn't try to compose WTF. It loads actual data from desired period.
thank you Mr. Popov
that worked out well.
I tried it with a 2nd Indicator, but I made a mistake again. Could you take a quick look were the mistake is, please.
Thank you
// Moving Averages Crossover Indicator
// Last changed on 2009-05-05
// Part of Forex Strategy Builder & Forex Strategy Trader
// Website http://forexsb.com/
// Copyright (c) 2006 - 2011 Miroslav Popov - All rights reserved.
// This code or any part of it cannot be used in other applications without a permission.
using System;
using System.Drawing;
namespace Forex_Strategy_Builder
{
/// <summary>
/// Moving Averages Crossover Indicator
/// </summary>
public class Moving_Averages_Crossover_neu : Indicator
{
/// <summary>
/// Sets the default indicator parameters for the designated slot type
/// </summary>
public Moving_Averages_Crossover_neu(SlotTypes slotType)
{
// General properties
IndicatorName = "Moving Averages Crossover neu";
PossibleSlots = SlotTypes.OpenFilter | SlotTypes.CloseFilter;
CustomIndicator = true;
// Setting up the indicator parameters
IndParam = new IndicatorParam();
IndParam.IndicatorName = IndicatorName;
IndParam.SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new string[]
{
"The Fast MA crosses the Slow MA upward",
"The Fast MA crosses the Slow MA downward",
"The Fast MA is higher than the Slow MA",
"The Fast MA is lower than the Slow MA",
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
IndParam.ListParam[1].Caption = "Base price";
IndParam.ListParam[1].ItemList = Enum.GetNames(typeof(BasePrice));
IndParam.ListParam[1].Index = (int)BasePrice.Close;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The price both Moving Averages are based on.";
IndParam.ListParam[3].Caption = "Fast MA method";
IndParam.ListParam[3].ItemList = Enum.GetNames(typeof(MAMethod));
IndParam.ListParam[3].Index = (int)MAMethod.Simple;
IndParam.ListParam[3].Text = IndParam.ListParam[3].ItemList[IndParam.ListParam[3].Index];
IndParam.ListParam[3].Enabled = true;
IndParam.ListParam[3].ToolTip = "The method used for smoothing the Fast Moving Averages.";
IndParam.ListParam[4].Caption = "Slow MA method";
IndParam.ListParam[4].ItemList = Enum.GetNames(typeof(MAMethod));
IndParam.ListParam[4].Index = (int)MAMethod.Simple;
IndParam.ListParam[4].Text = IndParam.ListParam[4].ItemList[IndParam.ListParam[4].Index];
IndParam.ListParam[4].Enabled = true;
IndParam.ListParam[4].ToolTip = "The method used for smoothing the slow Moving Averages.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "Fast MA period";
IndParam.NumParam[0].Value = 13;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 6500;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The period of Fast MA.";
IndParam.NumParam[1].Caption = "Slow MA period";
IndParam.NumParam[1].Value = 21;
IndParam.NumParam[1].Min = 1;
IndParam.NumParam[1].Max = 6500;
IndParam.NumParam[1].Enabled = true;
IndParam.NumParam[1].ToolTip = "The period of Slow MA.";
IndParam.NumParam[2].Caption = "Fast MA shift";
IndParam.NumParam[2].Value = 0;
IndParam.NumParam[2].Min = 0;
IndParam.NumParam[2].Max = 100;
IndParam.NumParam[2].Point = 0;
IndParam.NumParam[2].Enabled = true;
IndParam.NumParam[2].ToolTip = "The shifting value of Fast MA.";
IndParam.NumParam[3].Caption = "Slow MA shift";
IndParam.NumParam[3].Value = 0;
IndParam.NumParam[3].Min = 0;
IndParam.NumParam[3].Max = 100;
IndParam.NumParam[3].Point = 0;
IndParam.NumParam[3].Enabled = true;
IndParam.NumParam[3].ToolTip = "The shifting value of Slow MA.";
// The CheckBox parameters
IndParam.CheckParam[0].Caption = "Use previous bar value";
IndParam.CheckParam[0].Enabled = true;
IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
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;
}
/// <summary>
/// Sets the indicator logic description
/// </summary>
public override void SetDescription(SlotTypes slotType)
{
EntryFilterLongDescription = ToString() + "; the Fast MA ";
EntryFilterShortDescription = ToString() + "; the Fast MA ";
ExitFilterLongDescription = ToString() + "; the Fast MA ";
ExitFilterShortDescription = ToString() + "; the Fast MA ";
switch (IndParam.ListParam[0].Text)
{
case "The Fast MA crosses the Slow MA upward":
EntryFilterLongDescription += "crosses the Slow MA upward";
EntryFilterShortDescription += "crosses the Slow MA downward";
ExitFilterLongDescription += "crosses the Slow MA upward";
ExitFilterShortDescription += "crosses the Slow MA downward";
break;
case "The Fast MA crosses the Slow MA downward":
EntryFilterLongDescription += "crosses the Slow MA downward";
EntryFilterShortDescription += "crosses the Slow MA upward";
ExitFilterLongDescription += "crosses the Slow MA downward";
ExitFilterShortDescription += "crosses the Slow MA upward";
break;
case "The Fast MA is higher than the Slow MA":
EntryFilterLongDescription += "is higher than the Slow MA";
EntryFilterShortDescription += "is lower than the Slow MA";
ExitFilterLongDescription += "is higher than the Slow MA";
ExitFilterShortDescription += "is lower than the Slow MA";
break;
case "The Fast MA is lower than the Slow MA":
EntryFilterLongDescription += "is lower than the Slow MA";
EntryFilterShortDescription += "is higher than the Slow MA";
ExitFilterLongDescription += "is lower than the Slow MA";
ExitFilterShortDescription += "is higher than the Slow MA";
break;
default:
break;
}
return;
}
/// <summary>
/// Indicator to string
/// </summary>
public override string ToString()
{
string sString = IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.ListParam[1].Text + ", " + // Price
IndParam.ListParam[3].Text + ", " + // Fast MA Method
IndParam.ListParam[4].Text + ", " + // Slow MA Method
IndParam.NumParam[0].ValueToString + ", " + // Fast MA period
IndParam.NumParam[1].ValueToString + ", " + // Slow MA period
IndParam.NumParam[2].ValueToString + ", " + // Fast MA shift
IndParam.NumParam[3].ValueToString + ")"; // Slow MA shift
return sString;
}
}
}
You can use this guide: Converting Legacy Indicators in FSB Pro Format
Forex Software → Technical Indicators → customize Indicators
Powered by PunBB, supported by Informer Technologies, Inc.