Quick Links


Learn More about our Forex Managed Accounts.
Forex Training Broadcasts
Forex Training Broadcasts
Six Steps to Forex Success
Demo the Forexecutor Trading Software Free!
Get a Forex Education with Currency College

 Syntax Help is designed as a basic guide to assist you with writing IntelliScript syntax in the IntelliScript Editor.
  
Basic Concepts
Syntax Examples

Syntax Examples

Disclaimer: The following examples do not reflect real trade strategies.  They are designed for syntax demonstration purpose only.

Example1:
 
Purpose:
 Generate a buy alert when 5-period EMA crosses from below 10-period EMA to above 10-period EMA.

Expression Syntax: 
 IF CrossUp(EMA(Close, 5), EMA(Close, 10)) THEN
    AddBuyEntry
 ENDIF
 
Points to note: 
 EMA(Close, 5): This statement says that the EMA is calculated using the Close price of each bar and 5 is the EMA period.  A further example MACD(high, 12, 26, 9) says that the MACD is calculated using the High price of each bar and 12, 26, and 9 are the three parameters for this MACD.

 AddBuyEntry: This command* will generate a buy position by painting an arrow pointing upward on the chart.  The corresponding sell position is command AddSellEntry.

*In programming language a Command is an action type of statement. In this case it is a specific order to the Intelliscript software from you, the user.
 
 An IF … THEN … ELSE … ENDIF structure is the basic structure for most alert conditions.  The basic syntax for this statement is:
 
 IF (condition) THEN
  command
 ENDIF
 
 In this structure, condition** is a statement that evaluates if the statement is either true or false at a given time.  When a condition is true, the command is executed.  An extension of this structure is the ELSE statement:

 IF (condition) THEN
  command1
 ELSE
  command2
 ENDIF

 In this extension structure, when a condition is true, command1 is executed; when the condition is false, command2 is executed.

** In programming, the condition is a type of statement that controls the flow of the IF-THEN-ELSE statement, or alert in this case, based on whether certain conditions are met. The statement is normally set up in the form: If (specific condition is met) Then (do this action) Else (do this if the condition is not met).

 CrossUp(EMA(Close, 5), EMA(Close, 10)): This statement uses the special CrossUp function, which is true if its first parameter crosses from below the second parameter to above the second parameter.  The opposite function is CrossDown(EMA(Close, 5), EMA(Close, 10)).


Example 2

Purpose:
 Generate a buy alert when the K-line of Slow Stochastic (with 5, 6, and 10 as the parameters) crosses from below the D-line of Slow Stochastic to above the D-line, and generate a sell alert when the same K-line crosses from above the same D-line to below the D-line.

Expression Syntax:
 IF (SlowK(Low, 5, 6, 10) > SlowD(Low, 5, 6, 10)) THEN
    AddBuyEntry
 ELSE
    AddSellEntry
 ENDIF
 
Points to note: 
 This example demonstrates the ELSE extension structure.  Please refer to Example 1 for more information on the IF … THEN … ELSE … ENDIF structure.

 SlowK(Low, 5, 6, 10): this statement says that the Slow Stochastic’s K-line is calculated using the Low price of each bar and 5, 6, and 10 are the three parameters for the K-line.


Example 3

Purpose:
 Generate a buy entry alert when the upper Bollinger Band crosses with the previous bar’s high price, and close the buy entry alert (a buy exit alert) when the lower Bollinger Band crosses with current bar’s low price.

Expression Syntax:
 IF (BLG_U[0](Close, 20, 2) < High[1]) THEN
  AddBuyEntry
 ENDIF

 IF (BLG_L[0](Close, 20, 2) > Low[0]) THEN
  AddBuyExit
 ENDIF

Points to note: 
 Up until now we have assumed that each condition requires the indicator calculated on the current bar.  If an alert requires the indicator calculated on the previous bar, we then need to use the displacement parameter.

 High[1]: This statement refers to the high price of the previous bar.  [0] indicates the current bar.  Note that [0] can be omitted.  [1] indicates the previous bar.  [2] indicates you want to use the second bar to the left of the current bar.

 BLG_U[0](Close, 20, 2): This statement says that the Bollinger Band’s upper band is calculated using the close price of each bar and 20 and 2 are the two parameters for the Bollinger Band.  In this expression, we once again introduced the displacement parameter [..].  By default, this parameter is omitted in the syntax, which means the indicator is applied to the current bar.  BLG_U[0](Close, 20, 2) is equivalent to BLG_U(Close, 20, 2).

 AddBuyExit: This command will close the previous buy entry position.  The corresponding sell position’s command is AddSellExit.

 

 

Example 4:

 This example is for users with some programming experience, it uses highly advanced syntax language.

Purpose:
 Generate a buy entry alert when the upper Bollinger Band crosses with the previous bar’s high price.  Set a stop loss for this buy entry alert if the current price is 75 pips below the buy entry price.

Expression Syntax:
 Global MyBuyStop = -1

 IF (BLG_U[0](Close, 20, 2) < High[1]) THEN
  AddBuyEntry
 ENDIF

 MyBuyStop = LastTradePrice[0] - .0075

 IF (Close < MyBuyStop) THEN
  AddBuyExit AT  MyBuyStop
 ENDIF
 
Points to note:
 This alert introduces to us how to declare variables† and how to set stop losses. 

 Global MyBuyStop = -1: This statement makes the initial declaration for variable MyBuyStop.  Note that the word MyBuyStop is arbitrary.  One can create any single word after the Global keyword as the variable name.  We introduce the word Global as the necessary language to be used in the declaration of the variable. The syntax for Global is:
 
 Global variableName = expression

 The above statement has two effects: 1. Declare variable named variableName; 2. Initialize this variable with the value evaluated by expression, in the example above, expression is -1.

 LastTradePrice: This keyword evaluates to the entry price of the last buy or sell position.  Note that the displacement parameter is applicable to this keyword, LastTradePrice.  Another example is LastTradePrice[1] which evaluates to the entry price of buy or sell position just prior to (one position to the left of) the last generated entry price of buy or sells position.

 AT: By default, commands AddBuyEntry, AddBuyExit, AddSellEntry, AddSellExit , or AlertOnly cause the event to happen at the price when the condition is met. We refer to these 5 commands as the addCommand.  The AT keyword enables the above commands to occur at the price following the AT keyword or expression.  The formal syntax for AT is:

 addCommand AT expression

 The list of available addCommand is:

 AddBuyEntry 
 AddSellEntry 
 AddBuyExit 
 AddSellExit 
 AlertOnly
 
†In programming, a variable is uniquely named by the programmer (you the user) and is a structure that holds data, or your statement in this case. It holds the data assigned to it until a new value is assigned.


Example 5:

Purpose:
 Generate a sell entry alert when the lower Bollinger Band crosses with the previous bar’s low price.  Set a stop loss for this sell entry alert if the price goes 30 pips above the sell entry price.  Exit the sell entry alert if the price goes 75 pips below the sell entry price.

Expression Syntax:
 Global MySellStop = -1
 Global MySellProfit = -1

 IF (BLG_L[0](Close, 20, 2) > Low[1]) THEN
  AddSellEntry
 ENDIF

 MySellStop = ABS(LastTradePrice[0]) + Point(30)

 MySellProfit = ABS(LastTradePrice[0]) - Point(75)

 IF (LastTradePrice[0] < 0 and Close[0] > MySellStop) THEN
  AddSellExit AT  MySellStop
 ENDIF

 IF (LastTradePrice[0] < 0 and Close[0] < MySellProfit) THEN
  AddSellExit AT  MySellProfit
 ENDIF
 
Points to note:
 This example shows us how to set a stop loss for a sell position and how to exit the sell position if the profit target is reached.

 ABS(LastTradePrice[0]): A sell position is the opposite of a buy position.  Therefore, LastTradePrice for a sell position will always evaluate to a negative value.  In order to return its positive value, we can use the ABS(x) function, which returns the absolute value of the input.  For example, ABS(-10) is equal to 10.  ABS(20) is equal to 20.

 Point(75): Here we introduce a special short-cut function so that this same alert can be applied to JPY related currency pairs as well as other pairs.  For JPY related currency pairs, this function 0.75.  For all other currency pairs, this function evaluates to 0.0075.


Example 6:

Purpose:
 Draws a customized indicator which displays as two colors.   If the close price is greater than the open price, the indicator is displayed as a blue line; otherwise, the indicator is displayed as a red line.  The value of the indicator is the percentage difference of each bar’s close price and open price in reference with the close price.

Expression Syntax:
 // Define a customized indicator called MyInd
 Indicator MyInd
 MyInd.Channel = 1
 IF Close > Open THEN
   MyInd.Color = "Blue"
   MyInd.Value = (Close - Open) / Close * 100
 ELSE
   MyInd.Color = "Red"
   MyInd.Value = (Open - Close) / Close * 100
 ENDIF
 
 MyInd.Draw

Points to note:
 // When a line of script is started with these two forward slashes, it means this line is ignored by the IntelliScript engine.  This is called commenting.  It is a convenient way to add your note in your script.
 
 Indicator MyInd: This is how you define the name of your customized indicator.  The name of the indicator can be any word you create.  The declaration’s formal syntax is:

 Indicator indicatorName

 MyInd.Channel = 1: This syntax tells the chart in which channel to draw this indicator.  When the channel is equal to 0, the indicator is drawn in the same channel as the price bars (the Price Channel).  When the channel is equal to 1, the indicator is drawn in the first lower channel below the Price Channel.

 MyInd.Value = (Close - Open) / Close * 100: To assign the calculations to the customized indicator, you use the .Value property.

 MyInd.Color = "Blue": This syntax assigns a blue color to the customized indicator.  The available colors are "Yellow", "Green", "Black", "Purple", "Blue", and "Red"

 MyInd.Draw: Only if you write this syntax in the end, this customized indicator will be drawn on the chart.


Example 7:

Purpose:
 Send an email when an alert is generated.

Expression Syntax:
 IF CrossUP(EMA(Close,5) , EMA(Close,10)) THEN
  AddBuyEntry "EMA Cross Up"
    SendMail "EMA Cross UP"
 ENDIF
 
 
Points to note:
 AddBuyEntry "EMA Cross Up": This syntax shows you that you can add your own popup messages when a buy entry position is added to the chart.  You can substitute any text you want inside the two double quotes.
 
 SendMail "EMA Cross Up": This syntax shows you that you can send an email when an alert is generated.  The double quotes contain the subject for the email.  You have to configure a list of email addresses under the Organizer tab in the Default Email List section before using this command.


Example 8:

Purpose:
 Generate a buy alert when 5-period EMA crosses from below 10-period EMA to above 10-period EMA and the EUR/USD 1-Hour chart is currently in a buy position at the same moment. Generate a sell alert when 5-period EMA crosses from above 10-period EMA to below 10-period EMA and the EUR/USD 1-Hour chart is currently in a sell position at the same moment. Please read "Points to Note" below to learn more details.

Expression Syntax:
 Local OneHourEURTradePos
 OneHourEURTradePos = getValue("EUR/USD,1 Hour", getTradePrice(0))
 
 IF CrossUP(EMA(Close,5) , EMA(Close,10)) AND (OneHourEURTradePos > 0) THEN
  AddBuyEntry
 ENDIF
 
 IF CrossDown(EMA(Close,5) , EMA(Close,10)) AND
     (OneHourEURTradePos < 0) THEN
  AddSellEntry
 ENDIF

Points to note:
 This example assumes that the syntax above is attached to a data series that is not a EUR/USD 1-hour data series. The purpose is that suppose you have a different strategy written as a customized alert and attached to the EUR/USD 1-hour data series, now you want to generate an alert in a second strategy only when the first strategy is in the same trade. For example, you have attached the script shown in Example 1 to the EUR/USD 1-hour data series. Now you attach this Example 8 script to the EUR/USD 5-minute data series. As a result, this Example 8 script will generate a buy entry position when the 5-period EMA crosses with the 10-period EMA in both the EUR/USD 1-hour data series and the EUR/USD 5-minute data series.


Example 9:

Purpose:
 Generate a log file at the close of each bar for the data series in which the script is attached.

Expression Syntax:
 IF BarClosed() THEN
  LogData "C:\EURUSD.TXT"  ENDIF

Points to note:
 Unlike previous examples, this example does not generate any signals.  We use this example to demonstrate how to generate a data file automatically when a bar closes.  Suppose this script is attached to a EUR/USD 1-minute chart, then you will be able to log a 1-minute historical data continuously when the chart is open.

 BarClosed(): This function returns true when the current bar becomes closed.

 LogData: This function takes one parameter: the location of the log file you wish to be saved.  In this example, the log file is named EURUSD.TXT and is saved in your local C: drive.

 

Example 10:

Purpose:
 Draw customized Pivot Points (horizontal support and resistance lines) on the chart.

Expression Syntax:
 Local MyPivot, R1, R2, R3, S1, S2, S3
 
 MyPivot = (High[1] + Low[1] + Close[1]) / 3
 
 S1 = MyPivot - (High[1] - MyPivot)   //S1 Line
 S2 = MyPivot - (High[1] - Low[1])     //S2 Line
 S3 = Low[1] - (High[1] - Low[1])       //S3 Line
 
 R1 = MyPivot + (MyPivot - Low[1])   //R1 Line
 R2 = MyPivot + (High[1] - Low[1])    //R2 Line
 R3 = High[1] + (High[1] - Low[1])     //R3 Line
 
 HLine MyS1 = S1
 HLine MyS2 = S2
 HLine MyS3 = S3
 HLine MyR1 = R1
 HLine MyR2 = R2
 HLine MyR3 = R3

Points to note:
 HLine MyS1 = S1: This syntax creates a horizontal line called MyS1 on the chart.  The value of MyS1 is S1.