Creating a New System

Top  Previous  Next

In this section we create a new system from scratch. Remember this system uses a crossover of two Exponential Moving Averages (EMA) to create buy and sell signals. MACD represents the difference between the two moving averages, so if MACD is positive it means that the fast MA is above the slow MA, if it is negative it means that the fast MA is below the slow MA.

 

A popular formula for the "standard" MACD is the difference between a security's 26-day and 12-day exponential moving averages. This is the formula that is used in many popular technical analysis programs, and quoted in most technical analysis books on the subject. Of the two moving averages that make up MACD, the 12-day EMA is the faster and the 26-day EMA is the slower. Closing prices are used to form the moving averages.

 

A buy signal will be generated when the MACD is positive, and a sell signal when the MACD is negative.

 

First we select the Edit Blox menu item by clicking on the Blox menu item from the Edit menu:

 

MenuEdit

 

This brings us to the Blox Editor. This screen shows the list of available Trading Blox and Scripts in the upper left, the available Blox Items such as Global's, Parameters and Indicators in the lower left, and the selected script shows on the right pane.

 

editblox

We will create a New Block by pressing the New button just below the list of Trading Blox and Scripts. This will bring up a New Trading Block window. We are going to call this new Block the Tutorial Entry Exit Block, and it will be an Entry and Exit Block type. Once we have named the Block and selected its type by clicking the appropriate radio button, we press OK.

 

newblock

At this point we should see our new Block in the list. Notice that we have many blank script templates within the Entry Exit Block that we can use. Each of these serves a particular purpose. Scripts you put in the Before Trading Day template are called before the trading day starts. Scripts placed in the Exit Order Filled template are called only when an exit order is filled. So putting your scripts in the right place is an important first step to getting your Block to work.

 

bloxandscripts

 

Our first step will be to create some parameters and indicators for this Block. We are writing a simple Moving Average Convergence Divergence system. We will need two parameters, short and long moving averages, and a MACD indicator.

 

To create our first parameter we click on the Parameter list item, and click the New button just below the list:

 

blockitems

This brings up a New Parameter Window.

 

editparameter

 

Name for Code: In this case we will enter shortMovingAverageDays. This is the name we will use when we want to refer to this parameter in a script. We want it to be fairly descriptive, with no spaces or special characters.

 

Name for Humans: This is the name the users of our system will see. This name can have spaces and special characters, as it is for display purposes only. We normally indicate the unit of measure so it is clear to the user what we are looking for. In this case we indicate (days) so they know its not weeks, ATR, or some other measure.

 

Parameter Type: We need to let the system know what type of input we are expecting. In this case the input (days) is an integer value. For other parameters we might want to input floating point, percent, or other types.

 

Default Value: This value is displayed when the user first starts the system. Once data is entered into this parameter, it sticks, so this value is only used on the first startup. 12 is a good number to get the user started.

 

Scope: This defines whether this value will be available to just the block, to the system, or to the whole test.

 

Used for Lookback: Check this box only when you use this parameter to reference historical values of indicators or price series. If this parameter is used for an indicator, then you do not need to check this box.

 

Once you are finished, press OK. Using the same process, create a longMovingAverageDays parameter, using 26 as the default value.

 

We now see our two parameters in our Parameter List:

 

tutorialparameters

Now we need to create the MACD indicator on which our system will be based. Click on Indicator in the list, and then click NEW just below the list. This will bring up the New Indicator dialog box.

 

newindicator

 

Name for Code: Similar to parameters, this is the name you will use to access the value of the indicator from the scripting language. We will call our indicator "macdIndicator".

 

Type: Select "MACD".

 

Value: In this case we use the closing prices to calculate the moving averages. You can select other values to see how it affects the performance of your system.

 

Short MA Bars: Select the parameter we setup to hold the short moving average days, which was shortMovingAverageDays.

 

Long MA Bars: Select the parameter we setup to hold the long moving average days, which was longMovingAverageDays.

 

Plots on Trade Graph: We check this box to have the indicator plotted on the graph. We can select a Display name and color here. We would check the "Offset Plot by One Day" box if our system were trading on stops or limits. But if we are using a buy/sell on open type system, then we leave this unchecked. In this case the MACD indicator is not within the scale of the instrument graph, so we do not plot. More on this later.

 

When you are finished creating our indicator, press OK.

 

Now we see both parameters and the indicator in our list:

 

tutorialindicator

Next we need to use this indicator to start trading. The place where entry signals are generated is the Entry Orders template. So we click on the Entry Orders template within the Tutorial Block, and our blank script shows up on the right.

 

tutorialscripts

To create an entry signal we have two parts. The IF statement that determines whether to place the trade, and the BROKER statement which places the order. We want to say something like, "If the MACD is goes positive then enter long on the open. If the MACD goes negative then enter short on the open." Here is how we could write that in Blox Basic:

 

IF ( macdIndicator > 0 ) THEN

   ' This means the MACD has moved above 0, so enter long.

   BROKER.enterLongOnOpen

ENDIF

 

IF ( macdIndicator < 0 ) THEN

   ' This means the MACD has moved below 0, so enter short.

   BROKER.enterShortOnOpen

ENDIF

 

Note the use of comments to make understanding your code easier when you look at it later. We don't want to continue adding units every day when the MACD is positive, so we put one more piece of logic to say "if the MACD is positive and we are not long already, then buy on the open."

 

IF ( macdIndicator > 0 ) AND ( instrument.position <> LONG ) THEN

   ' Two conditions must be met - MACD above 0 and we are not long.

   ' If both are met, we enter long.

   broker.enterLongOnOpen

ENDIF

 

IF ( macdIndicator < 0 ) AND ( instrument.position <> SHORT ) THEN

   ' If we are not short and the MACD is below 0, enter short.

   broker.enterShortOnOpen

ENDIF

 

That's our entry logic. Let's put this script into our Entry Orders template. We should see this:

 

tutorialentryorder

Now press the OK button and we are back in the main screen.

 

All we need to do now is create a new System, and put our new Block into the System. Here is how we create a new system. Select the Systems menu item from the Edit menu:

 

MenuEdit

 

We are presented with the Edit Systems dialog box:

 

editsystemwindow

 

From here, we press the New System button, and enter our system name:

 

systemname

Now we select our new Tutorial System from the list on the left. To put the Entry Exit Block into the system, we can select the block and use the Add button, or right click on the block. We can create more Blox for this system later. We also need to put the "Basic Money Manager" Block into the Money Manager area by adding it or right clicking on it. This Block simply puts the unitSize at 1.  Click "OK".

 

Now we are ready to run our system. We select our Tutorial system from the list of systems by clicking the checkbox on the bottom left. We will want to uncheck any other systems that might be selected.

 

tutorialcustomizetest

Notice how our default values show up. We can press Run Test to see how our system works! Try stepping through many different values and combination of values to find the optimal robust set for this system.