Tutorial: Extending PivotBuilder using API Function
Thu, Oct 04, 2012, 02:26 PM
Post: #1
Index Tutorial: Extending PivotBuilder using API Function

The PivotBuilder Function is an Application Programming Interface (API), developed with suite's extensibility in mind. It allows users to natively and easily integrate PivotBuilder Personal Trading Suite and all of its functions with standard and third-party TradeStation and MultiCharts add-ons. I know a lot of you use custom-developed trading systems and strategies, and wish to extend their functionality by adding PivotBuilder to the mix. This function allows you to do just that - all you need is access to add-on source code and minimal understanding of TradeStation’s EasyLanguage (or in case of MultiCharts - PowerLanguage) programming.


TradeStation 8.7-9.1 (and future versions) or MultiCharts 8 (and higher).


To install the function, download and extract the new PivotBuilder Suite 1.5 package, and open the appropriate platform directory (i.e. TradeStation or MultiCharts). Within it, you will find a function file entitled PivotBuilder API Function. Double-click the file to install it into your platform.


  1. Select the add-on you would like to integrate PivotBuilder into, and open its source code using EasyLanguage (Format>>Analysis Techniques , select indicator, click on Edit EasyLanguage). MultiCharts users: Format>>Study, select add-on, click Open Script.

  2. At this point, you should be familiar with EasyLanguage/PowerLanguage and have a very basic grasp on programming. Once you have the source code displayed, look for a space that is not part of any conditional statement or loop - basically, avoid the space between begin and end statements.

  3. To call the PivotBuilder function (i.e. import the Trigger line and 7 pivots into the custom add-on) copy and paste the following line (do not include the word "Code:" below):
    PB = PivotBuilder(oLine0, oLine1, oLine2, oLine3, oLine4, oLine5, oLine6, oLine7,
    The preceding line may be overwhelming at first, but that’s mostly due to all the parameters. As you already know, PivotBuilder is very feature-rich, and each of those parameters enables you to control specific PivotBuilder variables.

  4. We now need to assign individual PivotBuilder pivot lines to variables so we could directly control them (more on this later). Within your source code editor, go the section that starts with Variables. Under that line, copy and paste the following (again, omitting the word "Code:"):

  5. The next step is creating parameter input fields. Go the section that starts with Inputs. Under that line, copy and paste the following (again, omitting the word "Code:"):
    PBPeriodT( 5 ),
    PBDeviationT( 0 ),
    PBUseVolT( false ),
    PBMAT( 0 ),

    PBPeriod1( 500 ),
    PBDeviation1( 0 ),
    PBUseVol1( true),
    PBMA1( 0 ),

    PBPeriod2( 500 ),
    PBDeviation2( 1 ),
    PBUseVol2( true),
    PBMA2( 0 ),

    PBPeriod3( 500 ),
    PBDeviation3( -1 ),
    PBUseVol3( true),
    PBMA3( 0 ),

    PBPeriod4( 500 ),
    PBDeviation4( 2 ),
    PBUseVol4( true),
    PBMA4( 0 ),

    PBPeriod5( 500 ),
    PBDeviation5(- 2 ),
    PBUseVol5( true),
    PBMA5( 0 ),

    PBPeriod6( 75 ),
    PBDeviation6( 2 ),
    PBUseVol6( true),
    PBMA6( 0 ),

    PBPeriod7( 75 ),
    PBDeviation7( -2 ),
    PBUseVol7( true),
    PBMA7( 0 ),


    As previously mentioned, these are called input variables. They will appear within your platform's Format Indicator dialogue window and each allows you to configure the Period, Deviation Amount, Volatility Switch, and Moving Average type - in that order - for individual Pivot Lines. Variables that end with T control the Trigger line, while 1-7 control the pivots that Trigger interacts with to generate signals.

    Recall from PivotBuilder manual - Period can be any positive value, Deviation can be positive (above price) or negative (below price), UseVol can be TRUE (Volatility applied) or FALSE (Volatility not applied), and MA can be 0-3: 0 (Simple – default), 1 (Exponential), 2 (Weighted), 3 (Triangular).

    Also recall that setting UseVol to TRUE will affect Deviation values. Try to use the Standard Deviation scale (typically -4 to 4) while volatility is applied otherwise the pivots will be too far from price action.

    Don't forget to insert your PivotBuilder Serial number within the PBSerial parameter.

  6. Save the add-on by giving it a new name ( File>>Save As) then press F3 to compile and verify code.

  7. Go to TradeStation/MultiCharts platform, open a chart, and add the new analysis technique you just created.

  8. Congratulations, you just integrated PivotBuilder into an existing add-on, compounding effects of the two.

You may optionally create separate variables for price type and displacement parameters using the methodology above.


In steps 3 and 4 we called the PivotBuilder API function and assigned individual pivot line values to 8 variables called oLine0, oLine1, oLine2, oLine3, oLine4, oLine5, oLine6, oLine7 (the first 8 parameters of the PivotBuilder function). oLine0 fetches the Trigger line data while 1-7 are interfaced with Pivot lines 1-7. Although all pivot line values are assigned, you should only use the ones that your strategy requires - just like you would do with PivotBuilder's Indicator, ShowMe, and Strategy add-ons.

Scenario: you have the RSI Indicator code open, and would like to expand the alert ruleset include the following conditions:
  1. LONG: The RSI line crosses over OverSold limit AND PivotBuilder’s Trigger line is below Pivot line 1.
  2. SHORT: The RSI line crosses under OverBought limit AND PivotBuilder’s Trigger line is above Pivot line 1.

Here’s what’s going to happen (using SHORT condition as example):

Original RSI Alert code before Integrating PivotBuilder:

if MyRSI crosses over OverSold then
    Alert( "Indicator exiting oversold zone" )
else if MyRSI crosses under OverBought then
    Alert( "Indicator exiting overbought zone" ) ;

Recall, MyRSI variable represents the RSI curve, OverSold is the oversold limit, and OverBought is the overbought limit.

RSI Alert code with PivotBuilder integration:

if MyRSI crosses over OverSold and oLine0 < oLine1 then
    Alert( "RSI > OverSold & PB Trigger < Pivot1" )
else if MyRSI crosses under OverBought and oLine0 > oLine1 then
    Alert( "RSI < OverBought & PB Trigger > Pivot1" ) ;

RSI variables remain the same, but now we’re also incorporating PivotBuilder variables that control the Trigger line (variable called oLine0) - red thick line in the screenshot - and Pivot1 (oLine1) - magenta line in the screenshot.

Remember, whenever you modify code, you need to press F3 to verify (i.e. compile) it. Saving the code alone is not sufficient. Compiling the new code above will result in the RSI indicator considering PivotBuilder Trigger/Pivot1 line interaction before issuing alerts, similar to the preceding screenshot.

That’s all you need to get started. I’ll post more advanced examples down the line, and include integrated indicator source code for you to practice on.

If you have no programming experience but would still like to integrate PivotBuilder into an existing system, contact me, and I’ll try to assist as much as I can.

Existing customers are encouraged to download the PivotBuilder API function by visiting the PivotBuilder v1.5 framework page.

If you are interested in purchasing PivotBuilder, please visit the official store.

Marko Nikolic
Chief Developer and President
October 4, 2012, Toronto, Canada

Related articles
Article: Author Last Post
Information PivotBuilder v4.0 released (Tick Delta) Marko Thu, Dec 17, 2015 07:14 PM
Last Post: Marko
  PivotBuilder v3.0 released (major upgrade) Marko Tue, Jun 30, 2015 04:32 PM
Last Post: Marko
  PivotBuilder v2.0 released (major upgrade) Marko Sun, Jan 25, 2015 07:12 PM
Last Post: Marko
  PivotBuilder v1.12 released (feat. Momentum oscillator) Marko Mon, Jul 21, 2014 01:35 PM
Last Post: Marko
  PivotBuilder v1.11 released (feat. Trend-Weighted MA) Marko Wed, Feb 19, 2014 02:58 PM
Last Post: Marko
Information PivotBuilder v1.10 released (feat. Linear Regression) Marko Tue, Oct 15, 2013 09:15 PM
Last Post: Marko
Information PivotBuilder v1.9 released (feat. Trailing Stop orders) Marko Sun, Jun 30, 2013 02:09 AM
Last Post: Marko
  PivotBuilder v1.8 Released (feat. Take Profit + Stop Loss) Marko Wed, Apr 03, 2013 04:14 PM
Last Post: Marko

Category Jump:

New Posts
New Posts
No New Posts
No New Posts
RSS Feeds