Creating BollingerBands_LE Strategy

There is a detailed description of creation of BollingerBands_LE strategy.

At first:

  1. Use the File menu.
  2. Select New.

    image

  3. Select Strategy.

Now you can see Code Editor. It's empty.

image

Click with the right mouse button anywhere in the Code Editor window.

image

In the shortcut menu select Properties and enter strategy name in the field Analysis Technique|Name at the Properties window.

image 

Enter the name: "BollingerBands_LE". "_LE" means that this strategy produces only Long Enter orders, this is a good practice to mark strategies in such way (although it's not required). After filling name field this strategy name will appear at the end of the list of strategies in Browser. We want to write this strategy on C# so keep field Language without changes too.

image 

Click the right mouse button anywhere in the Code Editor window again. Now in the shortcut menu select Parameters. We need to enter input parameters for this strategy:

  1. BollingerPrice parameter (it will tell strategy against what price bollinger band must be calculated).
  2. TestPrice parameter (specifies prices that will be compared to bollinger band to decide whether trade order should be generated).
  3. Length parameter (specifies number of bars back used to calculate bollinger band).
  4. NumDevsDn parameter (number of deviations down - required to calculate bollinger band).

image

To add parameters click right mouse button on the Parameters box and in the shortcut menu select Add Parameter and special form will appear.

image

In this form enter Parameter name, Parameter type, Parameter default value, Parameter description and if necessary mark that parameter is Reference. Than click Save if you want to save this parameter or Discard if you don't.

Creating BollingerPrice parameter: enter Parameter name ("BollingerPrice") and select Parameter type ("DoubleSeries"), set Parameter default value ("C") and than click Save.

 image

Creating TestPrice parameter: again click right mouse button on the Parameters box and in the shortcut menu select Add Parameter. Now enter Parameter name ("TestPrice") and select Parameter type ("DoubleSeries"), set Parameter default value ("C") and click Save.

 image

Creating Length parameter: again click right mouse button on the Parameters box and in the shortcut menu select Add Parameter. Now enter Parameter name ("Length") and select Parameter type ("Integer"), set Parameter default value ("20") and click Save.

image

Creating NumDevsDn parameter: again click right mouse button on the Parameters box and in the shortcut menu select Add Parameter. Now enter Parameter name ("NumDevsDn") and select Parameter type ("Integer"), set Parameter default value ("2") and click Save.

image

So we filled Parameters box:

image

This strategy uses two functions: BollingerBandFunction and CrossesOver. So we must add them as references. To do it select Functions from Browse for list of Browser window:

image

Browser window will show all available Functions:

image 

Find BollingerBandFunction and drag it with lift mouse button and drop over References window. Proceed the same with CrossesOver function.

After that References window will show that strategy references two functions:

image 

To calculate BollingerBands_LE strategy we need to define variable LowerBand in Variable Store. It will holdseries of values that represent Bollinger Band curve. To define it go to the Variable Store window, right-click on it and select Add Variable from context menu:

image 

Variable edit window will appear:

image

Enter Variable name ("LowerBand") and Variable type ("DoubleSeries"). Click Save.

image

Now enter the code of BollingerBands_LE strategy into the Code Editor window.

image

Strategy is executed on every bar of loaded data range.

At first we are checking that we have enough data:

[code:c#]

if (Bars.Count >= Length)
{
    //we have enough data
}

[/code]

The following line calculates LowerBand by calling BollingerBandFunction:

[code:c#]

LowerBand[0] = BollingerBandFunction(BollingerPrice, Length, -NumDevsDn );

[/code]

This line defines buying condition (Buy if this is not a first bar and TestPrice crosses over LowerBand):

[code:c#]

if ( CurrentBar > 1 && CrossesOver(TestPrice, LowerBand) )

[/code]

Generating Buy order:

[code:c#]

BuyNextBarAtStop("BBandLE", LowerBand[0]);

[/code]

where "BBandLE" - order name and LowerBand[0] - stop price.

 

After all listed actions are done click right mouse button anywhere in the Code Editor window and select Build Analysis Technique. If there are no errors in the Strategy it will appear in the list of functions at Browser with the green tick. Otherwise Task List will appear. For example if you forgot semicolon it will display in Task List with indication of concrete line and file name with error.

image

When you will find the error and correct it click the right mouse button anywhere in the Code Editor window and select Build Analysis Technique again. If there are no errors in the Strategy now Task List will be empty and function name will appear in the list of Strategies at Browser with the green tick.

NeedForTrade Trading Platform
Home
Products
Features
Buy
Downloads
Support
Help
Tutorials
Contacts
Login
Login
Login