Tutorial: Creating Custom Indicator with Forex Strategy Builder by Denny Imanuel
[email protected]
1. Preparing the Tools Forex Strategy Builder indicators are developed in C# (CSharp) Language. So the basic C# programming knowledge is necessary if you want to develop a custom indicator on this platform. In this tutorial I assumed that the reader has the basic knowledge of C# programming language. If you need to learn the C# programming language you can find a lot of free resources in internet. In order to develop the indicator firstly you need the C# IDE (Integrated Development Environment) software, such as: 1. Notepad: a basic ASCII editor. 2. Notepad++: free source code editor that support several programming language downloadable from Sourceforge website. 3. Visual C# Express Edition: a free version of Visual Studio downloadable from Microsoft website. Forex Strategy Builder comes in bundle with the debugger, so all you need is just the ASCII editor and may be syntax checker. And for this tutorial purpose we will use Notepad++. How to use these softwares is beyond this tutorial topic. Next you need to download the basic original indicator source code from Forexsb website. These original indicators are your template to create your own custom indicator. So all you need to do is to select one of the original indicators that most suitable to your current indicator. You don’t need to write all the code from scratch. 2. Understanding the Original Indicator Code Structures Let’s open up one of the original indicator source code for an example “Momentum.cs”. You can narrow down the sourcode view by clicking minus sign below the procedure in order to see the overall structures of the code as shown below.
The momentum indicator consists of Momentum main class declaration inside namespace Forex_Strategy_Builder. One indicator must be represented by one class. And inside this Momentum class there are four main procedure: − Momentum(), this is a constructor procedure which contains class initiation. When you set the indicator’s input parameters on FSB (setting the indicator logic, choosing the smoothing method, setting the period value), this procedure is executed. Your custom indicators parameters input should be located here. This procedure is only called once when the indicator is loading. − Calculate(), this is the main procedure for the indicator where the indicator algorithm is performed. Your main custom indicator code should be located here. This procedure is called repeatedly on tick by tick basis when the backtesting is simulated on FSB or trading is performed in FST. − SetDescription(), this is the additional part of the indicator which lest important to take a look currently. It contains the strategy overview and description. This procedure is called when you click the strategy overview on the FSB. − ToString(), this is also the minor part of the indicator which shows the label name for the indicator which displayed on the top left corner of charts data. Constructor() Procedure So let’s focus on the first two procedure and take a look at the breakdown. On the beginning of this procedure the IndicatorName is set to “Momentum” and then the new object IndParam is created.
The IndParam object consists of SlotType parameter which describe which slot the indicator can be applied to. The possible value will be: SlotType.Open, SlotType.Close, SlotType.OpenFilter, SlotType.CloseFilter, as show on the picture below. The IndParam object consist of ListParam which represent the list box control, NumParam which represent the up down numeric control, CheckParam which represent the checkbox control.
SlotType.Open
SlotType.OpenFilter
SlotType.Close
SlotType.CloseFilter
IndParam.IndicatorName
IndParam.ListParam[0] IndParam.ListParam[1]
IndParam.ListParam[2]
IndParam.NumParam[0] IndParam.NumParam[1] IndParam.NumParam[2]
IndParam.CheckParam[2]
Calculate() Procedure Calculate() procedure is the main calculation of the overall indicator. Here you will see four major portion of the this procedure, as shown on the picture below: 1. Initiation Part, in this part, some of the parameters selected on the input controls are transferred to the initial variables, and some of the initial variables are initiated. 2. Calculation Part, this is where the actual indicator calculation is scripted. So, as the programmer you can focus on this part more. Usually the indicator is calculated on an array of bars from the first bar until the last bar. So the loop start from iFirstBar (that you must initiate) and end before the number of bar represented by Bars: for(int iBar = iFirstBar; iBar Current Open then Counter = Counter + 1; - If Current Close < Current Open then Counter = Counter – 1;
However the counter value must reset to zero when the price is reverse it’s direction. - If (Current Close > Current Open) and (Previous Close < Previous Open) then Counter=0; - If (Current Close < Current Open) and (Previous Close > Previous Open) then Counter=0;
And when this code is translated into the C# with loop from first bar to last bar it feels and appears like below: for (int iFirstBar; iBarOpen[iBar] && Close[iBar-1]Open[iBar]) adCounter[iBar] += 1; if (Close[iBar]