24
Introduction The Formula Wizard assists in the creation of new studies, color indicators of studies, and alerts on studies. A basic understanding of the structure of an EFS formula is helpful in making full use of the Formula Wizard. The first formula that we will write will color the price bars green or red if the close is above or below the 10 period exponential moving average. Launching the Wizard Launch the Formula Wizard by selecting the menu command Tools -> Formula Wizard. Click on ‘New Formula’, and the following dialog should show:

The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Introduction The Formula Wizard assists in the creation of new studies, color indicators of studies, and alerts on studies. A basic understanding of the structure of an EFS formula is helpful in making full use of the Formula Wizard. The first formula that we will write will color the price bars green or red if the close is above or below the 10 period exponential moving average.

Launching the Wizard Launch the Formula Wizard by selecting the menu command Tools -> Formula Wizard. Click on ‘New Formula’, and the following dialog should show:

Page 2: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Formula Configuration Dialog

Study Title The Study Title is used to identify the formula in an Advanced Chart’s cursor window.

Price Study A price study is displayed in the same axis as the prices. Examples of this include Bollinger Bands, Moving Averages and Linear Regression studies.

Non-Price Study You may also select between a Price Study (a study that is plotted in the same axis as the prices – eg: Bollinger Bands), or a Non-Price Study (a study that is plotted in a separate axis – eg: Stochastics).

Data Plots The data plots are the numeric values returned by the formula (these mirror the values in the ‘return …’ statement in EFS). The visual properties of the data plots are defined here, one line for each returned value. For example, a study that plots the moving average of an RSI may choose to return two lines: one for the original RSI, and one for the moving average. In our case, we want to return one data point, the moving average. Click on ‘Add Line’, and give the line a name.

Page 3: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Formula Wizard Clicking on OK will dismiss the Formula Configuration dialog, and bring you to the main Formula Wizard screen:

Page 4: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Formula Configuration

This section outlines briefly the configuration selected in the Formula Configuration dialog. Clicking on ‘Edit’ will allow you to edit the configuration.

Studies Used

The Studies Table lists any built-in studies that are currently being used by the formula. Clicking on ‘Add Study’ will bring up a dialog which allows you insert built-in studies for use by your formula:

Page 5: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

After selecting ‘MAStudy’ for example, the Studies Table will now show:

Variable Name The variable name ‘vEMA10’ is automatically assigned to our moving average study. We can use this variable name to reference this study later on in our formula.

Study The built-in study’s EFS constructor is listed here, with the parameters that configure our moving average to our specifications. In this case, a MAStudy is created with a 10 period, 0 offset, exponential moving average using values calculated from the “Close”.

Expression Sets

Expression sets drive the logic behind the formula. Each expression set (displayed above is an empty Expression Set #1) contains a list of conditions. If all of the conditions are true, then the actions specified will be executed. This may include actions such as coloring the bars, playing an alert sound, emailing an alert, or executing a paper trade for back testing purposes. If the conditions in Expression Set #1 are not satisfied, then the conditions in Expression Set #2 are tested, and so on.

Page 6: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Expression Conditions

The expression conditions for an expression set are listed immediately below the set number. Clicking on ‘Add Line’ will allow you to add a condition to your expression:

Clicking on either of the ‘Edit’ buttons in the condition line will bring up the familiar Function Editor:

Using the Function Editor, you may select various functions to use in the expression set. Select the function ‘close’ under Globals and click OK. The condition line should be updated to show this:

Now we need to compare the closing price to the value of our vEMA10 variable, the 10 period exponential moving average. Click on the right-most ‘Edit’ button:

Page 7: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

A list of all built-in study variables are at the top. Select ‘vEMA10’, and click OK. The condition line should now look like this:

The formula now contains one condition line, which tests if the close is less than the value of vEMA10. What we do under that condition is left for the action lines to handle.

Actions

The actions are listed immediately below the condition lines. There are two types of actions: ones that happen every time the conditions are satisfied, and ones that happen only the first time the conditions are satisfied. Since we want to color the price bars every time our close is less than our moving average, click on the appropriate ‘Add Line’ button:

Page 8: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

The Function Editor appears again, this time displaying functions that can be added as action functions. Since we want to color the price bars, select ‘setPriceBarColor’, and choose an appropriate color from the drop down list. The Expression Set should now look like this:

Page 9: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

The formula will now color price bars red if the close is less than the 10 period EMA. The formula still needs to know how to handle cases where the close is greater than the 10 period EMA. This can be defined in Expression Set #2. Create this set by clicking on ‘Set 2’ in the tabs:

Add a condition line to Expression Set #2, and select ‘close’ and ‘vEMA10’ from the Function Editor for either side of the condition:

Be sure to select the greater than (‘>’) sign between the two in order to test for the appropriate direction of price. Add an action line to Expression Set #2, which colors the price bars green. Your Expression Set #2 should now look like this:

The formula will now color the price bars green if the close is greater than the vEMA10, and red if the close is less than the vEMA10. We may however, want to plot the 10 period moving average as well, in order to visualize the market movement.

Page 10: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Returned Data Points

Below the expression sets is the Returned Data Points section. Any lines defined in the Formula Configuration dialog are listed here. You may type in any expression in the adjacent text box to return the value. For example, simply putting ‘50’ here will plot a straight line at $50 on your chart. Typing ‘high() + 5’ instead will plot a line connecting the high’s of each bar, plus $5. In our case, we just want to return the 10 period moving average that we have been using thus far, our variable vEMA10. Click on ‘Edit’, and select ‘vEMA10’ from the list:

The Function Editor again lists the functions that you may insert at this location. The Returned Data Points section should now look like this:

Your first formula is completed. Save the EFS file and load it in an Advanced Chart to see the results of your handiwork.

Page 11: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Example #1: Study on Study (MA of RSI)

Introduction The Formula Wizard allows you to use the values of a built-in study as the input for other built-in studies. In this example, we will build a 5 period moving average of an RSI study, and plot both in the same axis.

Formula Configuration

Page 12: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Study Configuration We will name our study “MA of RSI”, and select non-price study in order to plot our data in a separate axis.

Data Plots Add two data plot lines here, one for the RSI, and one for the moving average of that RSI. Color the MA-RSI differently than the RSI in order to tell them apart on the chart.

Min/Max Plot Values When plotting a non-price study, you have the option of restricting the min and max values of the study. As this is essentially an RSI plot, all values will lie between 0 and 100 on our chart.

Studies Used

Adding the RSI Study This formula requires the insertion of an RSI built-in study. Click on ‘Add Study’ and select the default values for ‘RSIStudy’:

Page 13: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Adding the Moving Average Study Next, we want to insert a moving average study that uses the RSI as the input data for its calculations. Click on ‘Add Study’ again, and select ‘MAStudy’:

Note the drop down arrow to the left of the constructor MAStudy(…). Clicking on this drop down arrow will reveal another constructor MAStudy(length,offset,studyVarName,dataSeriesID, movingAverageType):

Selecting this 2nd constructor will allow us to use our previously inserted RSIStudy as the input data for calculating this moving average:

Page 14: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Note that in the ‘studyVarName’ parameter, the Function Editor has automatically filled in the variable name of our RSIStudy: ‘vRSI14’. The ‘dataSeriesID’ specifies which data series within the ‘studyVarName’ to reference in its calculations. The RSIStudy only has one data series (RSIStudy.RSI), other studies, such as the MACD have more than one (MACDStudy.FAST, MACDStudy.SLOW, MACDStudy.HIST and MACDStudy.SIGNAL). After accepting these values, the Studies Table should now show the following:

Page 15: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Expression Sets Since our study only returns the RSI and MA-RSI calculations, we do not need to add anything in this section.

Returned Data Points We now need to return the values of vRSI14 and vEMA5_of_vRSI14. Click on ‘Edit’ for each of the return lines and select the appropriate variable to return:

Results After saving the formula to an EFS file, it may be applied to a new Advanced Chart. You should see something similar to this:

Page 16: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Example #2: Alerts on MACD Crosses

Introduction In this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification will take the form of a post to the Alert List, and a sound played from a .wav file. We will not be displaying the MACD, but instead display up and down arrows directly on the price chart where the signal crosses above and below the oscillator.

Formula Configuration

Select price study, and click OK. Since we are not plotting the MACD itself, we do not need to return any lines in the Data Plots Table.

Page 17: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Studies Used Click on ‘Add Study’ and add a MACDStudy with the desired parameters:

Expression Sets We will have two expression sets, one to handle the cross up case, and the other to handle the cross down case. Add a condition line to the first expression set:

On the left side, click on ‘Edit’, and select our previously added study variable name: ‘vMACD12_26’:

Under the ‘dataSeriesID’ parameter, be sure to select ‘MACDStudy.SIGNAL’. This will return the value of the MACD’s signal line to the left side of our condition line. Click on OK, then click on the right ‘Edit’ button. Select our study variable name again ‘vMACD12_26’:

Page 18: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

This time, keep the default ‘dataSeriesID’ as ‘MACDStudy.MACD’. You should now have a condition line that looks like this:

This sets up our first case, where the signal has crossed under the MACD oscillator. The first thing we would like to at this point is to add a popup alert to the Alert List. Click on the ‘Add Line’ next to the actions that execute only the first time, and select the ‘addToList’ function:

For our description, type in “MACD Signal Cross Down”, and select an appropriate color to use to represent this event. The action line should now look like this:

Page 19: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Next, we want to play a sound file to provide an audio alert. Click on ‘Add Line’ again, and select ‘playSound’. We can use the default sound file that is already filled in. The action lines should now look like this:

The final action will be to draw a down arrow on the bar where the crossover occurs. Click on ‘Add Line’ again, but this time select the ‘drawShapeRelative’ function:

Select ‘high()’ as the yValue (the price value on the y-axis where the shape will be drawn), ‘Shape.DOWNARROW’ as the shape to draw, an appropriate color, and ‘Shape.BOTTOM’ as the alignment flag, so that our arrow points in the correct location.

Page 20: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Expression Set #1 should now look like the following:

To complete Expression Set #2, click on ‘Set 2’ and follow the same steps, this time taking care to reverse the sign from ‘<’ to >’, and selecting the appropriate description and colors to signal a cross in the opposite direction. Expression Set #2 should look similar to this:

Returned Data Points No data points are returned in this study, as we are not plotting the MACD directly.

Page 21: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Results

The green arrows mark the locations where the MACD signal has crossed above the MACD oscillator. The red arrows mark the locations where the signal has moved below the oscillator. In addition, when this is run in real-time (or in Replay Mode), alerts are generated and posted to the Alert List:

Page 22: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Example #3: Three Bar Breakout Trading System

Introduction The Formula Wizard can also be used to set up more advanced formulas, such as a trading system. In this example, we will write a trading system formula that can be used in the backtester. The system will go long if the price exceeds the high of the three previous bars. The system will go short if the price goes lower than the low of the three previous bars. The stop is set at the low of the current bar, and is updated with each new bar. Successive signals in the same direction are ignored. If a short signal is received while long, but before the stop is triggered, the long will be exited and the trade reversed. The same applies for a long signal while the system is short. The price bar will be colored green while long, red while short and black otherwise.

Formula Configuration As we are only coloring the price bars, and not plotting any values of our own, select a price study, and do not add any lines to the Data Plot table. Type in an appropriate study name and click on OK.

Studies Used There are no studies used in this formula. Expression Sets

Long Conditions The system will go long only if it is not currently long, and if the price exceeds the high of the previous three bars. Add the following conditions to the first expression set:

Page 23: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Note the use of the negative offsets for the high() function. Negative offsets go ‘back’ bars, so the three lines test against the highs of the previous three bars.

Long Actions Once these conditions are satisfied, we want to open a position in the long direction (thus closing out any existing short positions), and color the price bar green:

Note how we want the price bar to be colored every time, but the Strategy.doLong() only the first time. This stops us from adding to the position every time the price continues in our direction. When calling the Strategy.setStop() function, we are also passing in the low() value as our stop point.

Short Conditions The short conditions are the exact opposite of the long conditions. Add these to the 2nd expression set:

Page 24: The Formula Wizard - eSignalkb.esignal.com/al/12/6/1391.pdfIn this example formula, we want to be notified when the MACD signal line crosses the MACD oscillator line. Notification

Short Actions Next, we add actions to color the price bar red, and to open the short position:

This looks similar to the long actions, note that we are using the high of the current bar as our stop loss.

Results The trading system is now complete. You can save the formula and run the resulting EFS in the strategy back tester to evaluate its effectiveness.