|Subscribe to BB4X PRO(Level III)|
|Gain unrestricted access to the full features of BBForex, including more than 30 Technical Indicators, interactive TrendLines, Stops & Systems. Build, automate and historically test your own trading strategies with BBScript and its Backtester.|
Subscribe now to BBForex Professional and get a 30 day free trial.
|Register for FREE(Level II)|
|Register for FREE and gain access to popular Bollinger Band indicators(%b and BandWidth), Bollinger methods screening, customizable forex grid and portfolio sections.|
|Already Created an Account?|
|If you already have created an account, Log In here.||
What is BBScript?
Quoting the BBScript official website (www.BBScript.net
"BBScript is a web-based programming language for technical analysis. It was developed as a quick, simple and easy to use scripting language for implementing and plotting technical indicators for equities and forex data in our interactive website charts: BollingerOnBollingerbands.com, EquityTrader.com and BBForex.com. Currently the latter three websites are the only ones to support BBScript.
Using BBScript, simple or complex indicators can be plotted in our highly interactive and customizable advanced charts. These charts employ advanced features such as dragging, zooming in and out, vertical and horizontal trackers, trendlines, continuous data updates, drag and drop re-ordering of charts, etc. A BBScript editor is built-in and can compile and run BBScript code. Indicators are then rendered and displayed using the chart engine."
For full documentation and the latest information on BBScript, please refer to the official website: www.BBScript.net
. For questions and online support, go to the BBScript discussion forum
BBScript Program Sample: (Momentum Indicator with Exponential Moving Average)
The following is an example of a BBScript code sample to plot the 12 period momentum indicator along with a 12 period exponential moving average of that indicator in the same indicator chart.
You need to be subscribed to BBForex Professional in order to run BBScript. If you haven't subscribed yet, get your 30 day FREE trial here
Once you've subscribed, go to the Chart section
and make sure that the "Advanced" tab is selected.
Open the "BBScript" editor by clicking on its tab option in the main chart menu. The editor will open. To enable the script to run, make sure the "Run Script" checkbox is checked. On the left panel text area, insert the script you want to run. Click the "Run" button to run the script and plot its output. The script will run on the currently selected symbol and sample rate. In the case below, it is the ticker EUR/USD pair DAILY chart. If you wish to run the script on another symbol or sample rate, just change those settings from their corresponding input fields and drop down menus.
data("x") //data object
//create momentum indicator and its ema
period1 = 12 //mtm period
period2 = 12 //ema period
momentum = close(x) - close(x)[-period1] //mtm formula
plot1 = plot(momentum,"Momentum","histogram","ff0000") //mtm plot
ema_mtm = ema(momentum,period2) //ema of mtm
plot2 = plot(ema_mtm, "EMA", "line", "0000ff") //plot of ema
chart(plot1,plot2) //display mtm and ema in indicator chart
The BBScript editor is displayed below. It consists of the following components:
- Run Script Checkbox: (top left side) The script will run when this checkbox is checked.
- New Button: This will create a blank new script and open it in the current workspace. The script name must be provided in the Script name field.
- Browse Button: This button will open the file manager where all the user's scripts are displayed.
- Delete Button: This button will delete the current script from the backend server and remove it from the workspace.
- Script Name: The script name must be unique and can only contain up to 40 alpha-numeric characters, spaces or the underscore character (_). A script can't be saved or run until a valid name is provided.
- Save Button: (top left side) To save your script to our server, click this button. A valid script name must be provided. If it is disabled, then your script is already saved.
- Input Script Panel: (left side) Insert your code in this area. Comments are highlighted in green and errors are underlined in red. As you type your script, autocomplete functions and their description is displayed on the output screen.
- Search Manual Text Field: (top right side) enter a keyword to lookup in the BBScript manual.
- Output Panel: (right side) Displays the system notifications, variable printouts, error messages, manual or API lookups.
- Duration Indicator: (bottom right side) Displays the duration of the script execution.
BBScript is cloud based. It runs in a browser and all scripts are stored safely on our servers. You can access the scripts anytime you are on line and logged onto BBForex. You must have an Adobe Flash Player installed on your computer and be connected to the Internet to create, edit, save and execute your scripts from our web interface.
In the BBScript file manager, scripts can be loaded into the workspace, renamed or deleted by clicking the corresponding buttons ( load, rename or delete) next to a script's name in the same row.
- Loading a Script: To load a script into the editor's workspace so you can edit or run it, click the "Load" button next to its name. Before the action is completed, you will be asked to save the currently displayed unsaved workspace script before it is removed from the workspace.
- Deleting a Script: To delete a script, simply click the "Delete" button. You will be prompted to confirm your delete action before it is executed.
- Renaming a Script: Clicking the "Rename" button will allow you to edit the script's name as shown below. Once you have finished entering the new name (with the name parameters outlined in Script Name above), click the "Apply" button next to it and the changes will be applied. If the name is invalid, an error message will appear.
The resulting indicator is shown below the price chart. Notice the labels for the momentum and its exponential moving average. Also notice that the momentum indicator is plotted in histogram format (positive green vertical lines and red negative vertical lines). The exponential moving average is plotted in blue in a linear format. The created indicator behaves the same way as the built in indicators. If you hover the cursor above it you can determine the value at a specific point. You can zoom in and out as well as drag the chart to the right or left. As data get streamed the script will rerun and the indicator chart is updated automatically.
The BBScript Backtester is a new feature of BBScript. It was purposely designed to be simple and easy to use without sacrificing power. Its goal is to let you quickly try out your trading and analysis ideas and then automate them if needed. We have prewritten all the Bollinger Band indicators and many other technical indicators for you. In addition, we have written many example scripts that you can use as is or employ as templates for your own ideas. There are many system creation, optimization and backtesting platforms; usually they are quite complicated and very expensive. Ours is a free addition to your existing BB subscription and is designed to be easy to use. Like any powerful tool, it'll take a little while to get used to it, but once you are up to speed I think that you'll appreciate just how unique and useful the BBScript Backtester is. Enjoy!
- You can test 6 different types of systems.
- Mode one: Always in the market, no pyramiding
- Wait for first signal and enter the market long or short.
- Ignore subsequent signals of the same type.
- Reverse to opposite state on next signal of opposite type.
- Repeat step b and c.
Example, if buy first, buy 1(long entry), sell 2 (long exit and short entry), buy 2, sell 2...
Example, if sell first, sell 1, buy 2, sell 2, buy 2...
- Mode two: Always in the market, with pyramiding
- Wait for first signal and enter the market long or short.
- On subsequent signals of the same type add a position.
- Reverse to opposite state on next signal of opposite type. If long, sell net position plus one more unit; If short, cover net position plus one more unit
- Repeat step b and c.
Example, if long first, buy 1, sell 2, sell 1(an add-on), buy 3 (2 long exits, one short entry), sell 2...
- Mode three: Discrete Trades without stops, no pyramiding
- For long trades, wait for the first long entry signal, march forward until matching exit is found, record trade and look for next long entry signal.
- For short trades, wait for the first short entry signal, march forward until matching exit is found, record trade and look for next short entry signal.
- Mode four: Discrete Trades without stops, with pyramiding
- For long trades, march forward until matching exit is found, record trade. Return to long entry and look for next long entry signal.
- For short trades, wait for the first short entry signal, march forward until matching exit is found, record trade. Return to short entry and look for next short entry signal.
- Mode five: Discrete Trades with stops, no pyramiding
- For long trades, wait for the first long entry signal, march forward until matching exit or stop is found, record trade and look for next long entry signal.
- For short trades,wait for the first short entry signal, march forward until matching exit or stop is found, record trade and look for next short entry signal.
- Mode six: Discrete Trades with stops and pyramiding
- For long trades, wait for the first long entry signal, march forward until matching exit or stop is found, record trade. Return to long entry and look for next long entry signal.
- For short trades,wait for the first short entry signal, march forward until matching exit or stop is found, record trade. Return to short entry and look for next short entry signal.
- An optional stop type can be specified when testing systems with stops (mode five and mode six).
There are 3 types of stops: Chandelier Stop, Parabolic Stop and Bollinger Stop.
- Your signals will be numbered as pairs and can be plotted on the chart. Click on any entry or exit and its complement will be instantly highlighted.
- Besides normal system statistics, you can see at a glance how your approach is doing over time by using equity curve plot, which can be constructed by adding daily trade gains or compounding daily trade gains.
Please refer to documentation
for more information.
The following is an example of a BBScript code sample to construct a simple Bollinger Band System, discrete trades with stops and no pyramiding backtester and equity curve plot.
// Written by John Bollinger April 2014
// use the data from the chart
// Bollinger Bands using builtÂin functions
middleBB = bbands(x, 20, 2, "middle")
lowerBB = bbands(x, 20, 2, "lower")
// back in the lower BBands = buy
entry = xover(close(x), lowerBB)
// tag the middle BBand = sell
exit = -xover(close(x), middleBB)
// group buy and sell signals in one array
signals = entry + exit
// back test type 4 = discrete trades, use stops, no pyramiding
back_type = 4
// stop type = Chandelier
stop_type = 0
// run the back test
bt = backtest(x, signals, back_type, stop_type)
// prepare price chart with signals
plot1 = plot(close(x), "signals", "line", "00000000", bt)
// show chart with signals
// calculate equity curve without compounding
equity_curve_calc = 0
// get equity-curve array using the back-tester object
eqCurve = equitycurve(bt, equity_curve_calc)
// create equity-curve plot
plot2 = plot(eqCurve, "EQ Curve", "line", "0000ff")
// display equity-curve chart
To use BBScript Backtester, go to Advanced Chart section, click BBScript button in the main chart menu.
Copy the "Simple System and Backtester" example code or write your own BBScript code in Script Input panel and run it. Please make sure the "Run Script" checkbox is check. System notifications will be shown in the Output Panel.
After successful code execution, click the "Backtester Report" button (top ride side of BBScript Editor), a detailed Backtester Report will show up. Click "Pop Up" button to open the report in a separate window.
The Report includes Trade Summary and Trades History. Below are statistical terms used in Backtester report and their definitions.
In Trade Summary section:
- Total Trades: total number of closed trades
- Total Wins: total number of winning closed trades
- Total Losses: total number of losing closed trades
- Winning %: percentage of winning closed trades in the total number of closed trades
- Total Average Win %: average percent gain per winning closed trade (short and long)
- Total Average Loss %: average percent loss per losing closed trade (short and long)
- Profit Factor: total absolute points won/total absolute points lost, closed trades only
- Overall Average Gain %: average percent gain per closed trade (longs, shorts, winning and losing trades)
- Overall Cumulative Gain %: total percentage compounded gains, closed trades only
In Trades section - Long:
- Number of Longs: total number of closed long trades
- Wins: number of winning closed long trades
- Losses: number of losing closed long trades
- Average Win %: average percent gain per winning closed long trade
- Average Loss %: average percent loss per losing closed long trade
- Cumulative Gain %: total compounded percentage gains from long trades, closed trades only
In Trades section - Short:
- Number of Shorts: total number of closed short trades
- Wins: number of winning closed short trades
- Losses: number of losing closed short trades
- Average Win %: average percent gain per winning closed short trade
- Average Loss %: average percent loss per losing closed short trade
- Cumulative Gain %: total compounded percentage gains from short trades, closed trades only
The following is an example of Backtester Report.
Total Trades: 15
Total Wins: 10 / Total Losses: 5
Winning %: 66.66
Total Average Win %: 1.31
Total Average Loss %: -1.92
Profit Factor: 1.37
Overall Average Gain %: 0.23
Overall Cumulative Gain %: 3.34
Number of Longs: 15
Average Win %: 1.31
Average Loss %: -1.92
Cumulative Gain %: 3.34
1: Enter: 2012-05-11 23:00 1.2919, Exit: 2012-05-23 23:00 1.2586, - 2.5776 %
2: Enter: 2012-05-17 23:00 1.2682, Exit: 2012-05-30 23:00 1.2367, - 2.4838 %
3: Enter: 2012-07-09 23:00 1.2314, Exit: 2012-07-27 23:00 1.2321, + 0.0568 %
4: Enter: 2012-07-11 23:00 1.2243, Exit: 2012-07-31 23:00 1.2299, + 0.4574 %
5: Enter: 2013-02-22 23:00 1.3191, Exit: 2013-03-06 23:00 1.2966, - 1.7057 %
6: Enter: 2013-02-27 23:00 1.3137, Exit: 2013-03-27 23:00 1.2776, - 2.7480 %
7: Enter: 2013-03-20 23:00 1.2944, Exit: 2013-04-04 23:00 1.2933, - 0.0850 %
8: Enter: 2013-03-26 23:00 1.2856, Exit: 2013-05-03 23:00 1.3116, + 2.0224 %
9: Enter: 2013-03-28 23:00 1.2814, Exit: 2013-05-07 23:00 1.3078, + 2.0602 %
10: Enter: 2013-05-16 23:00 1.2883, Exit: 2013-05-30 23:00 1.3043, + 1.2419 %
11: Enter: 2013-05-20 23:00 1.2884, Exit: 2013-06-25 23:00 1.3081, + 1.5290 %
12: Enter: 2013-09-04 23:00 1.3203, Exit: 2013-09-11 23:00 1.3311, + 0.8180 %
13: Enter: 2013-09-06 23:00 1.3177, Exit: 2013-10-17 23:00 1.3672, + 3.7565 %
14: Enter: 2014-01-06 23:00 1.3627, Exit: 2014-01-14 23:00 1.3679, + 0.3816 %
15: Enter: 2014-02-03 23:00 1.3525, Exit: 2014-02-07 23:00 1.3636, + 0.8207 %
Number of Shorts: 0
Average Win %: 0
Average Loss %: 0
Cumulative Gain %: 0
Signals and equity curve
You can see trade signals on the chart after your BBScript run successfully. Green up arrows are buys (long entries, short exits) and Red down arrows are sells (long exits, short entries). Click on any arrow, its complement will be highlighted. Entry and Exit Date along with trade gain will also show up. Equity curve is shown below the price chart.